From 40d72b3ba752275feafe298b27f8fbf727b3e036 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Mon, 3 Oct 2011 12:59:51 +0200 Subject: [PATCH] hla: use the property based interface from the property data element. --- src/Network/HLA/hla.cxx | 51 +++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/Network/HLA/hla.cxx b/src/Network/HLA/hla.cxx index 4f5e85ffb..28102336b 100644 --- a/src/Network/HLA/hla.cxx +++ b/src/Network/HLA/hla.cxx @@ -323,6 +323,34 @@ private: ObjectClassConfigList _objectClassConfigList; }; +class PropertyReferenceSet : public SGReferenced { +public: + void insert(const std::string& relativePath, const SGSharedPtr& dataElement) + { + if (_rootNode.valid()) + dataElement->setPropertyNode(_rootNode->getNode(relativePath, true)); + _pathDataElementPairList.push_back(PathDataElementPair(relativePath, dataElement)); + } + + void setRootNode(SGPropertyNode* rootNode) + { + _rootNode = rootNode; + for (PathDataElementPairList::iterator i = _pathDataElementPairList.begin(); + i != _pathDataElementPairList.end(); ++i) { + i->second->setPropertyNode(_rootNode->getNode(i->first, true)); + } + } + SGPropertyNode* getRootNode() + { return _rootNode.get(); } + +private: + SGSharedPtr _rootNode; + + typedef std::pair > PathDataElementPair; + typedef std::list PathDataElementPairList; + PathDataElementPairList _pathDataElementPairList; +}; + class AbstractSimTime : public SGReferenced { public: virtual ~AbstractSimTime() {} @@ -533,7 +561,7 @@ private: // Factory class that is used to create an apternative data element for the multiplayer property attribute class MPPropertyVariantDataElementFactory : public sg::HLAVariantArrayDataElement::AlternativeDataElementFactory { public: - MPPropertyVariantDataElementFactory(sg::HLAPropertyReferenceSet* propertyReferenceSet) : + MPPropertyVariantDataElementFactory(PropertyReferenceSet* propertyReferenceSet) : _propertyReferenceSet(propertyReferenceSet) { } @@ -551,19 +579,19 @@ public: // The relative property path should be in the semantics field name std::string relativePath = dataType->getAlternativeSemantics(index); - sg::HLAPropertyReference* propertyReference = new sg::HLAPropertyReference(relativePath); - _propertyReferenceSet->insert(propertyReference); - return new sg::HLAPropertyDataElement(alternativeDataType, propertyReference); + sg::HLAPropertyDataElement* dataElement = new sg::HLAPropertyDataElement(alternativeDataType, (SGPropertyNode*)0); + _propertyReferenceSet->insert(relativePath, dataElement); + return dataElement; } private: - SGSharedPtr _propertyReferenceSet; + SGSharedPtr _propertyReferenceSet; }; class MPAttributeCallback : public sg::HLAObjectInstance::AttributeCallback { public: MPAttributeCallback() : - _propertyReferenceSet(new sg::HLAPropertyReferenceSet), + _propertyReferenceSet(new PropertyReferenceSet), _mpProperties(new sg::HLAVariantArrayDataElement) { _mpProperties->setAlternativeDataElementFactory(new MPPropertyVariantDataElementFactory(_propertyReferenceSet.get())); @@ -595,7 +623,7 @@ public: sg::HLAVariantArrayDataElement* getMPProperties() const { return _mpProperties.get(); } - SGSharedPtr _propertyReferenceSet; + SGSharedPtr _propertyReferenceSet; protected: SGSharedPtr _location; @@ -792,7 +820,7 @@ private: objectInstance.setAttributes(attributePathElementMap); } - void attachPropertyDataElements(sg::HLAPropertyReferenceSet& propertyReferenceSet, + void attachPropertyDataElements(PropertyReferenceSet& propertyReferenceSet, sg::HLAAttributePathElementMap& attributePathElementMap, const AttributePathPropertyMap& attributePathPropertyMap) { @@ -800,10 +828,9 @@ private: i != attributePathPropertyMap.end(); ++i) { for (PathPropertyMap::const_iterator j = i->second.begin(); j != i->second.end(); ++j) { - SGSharedPtr propertyReference; - propertyReference = new sg::HLAPropertyReference(j->second); - propertyReferenceSet.insert(propertyReference); - attributePathElementMap[i->first][j->first] = new sg::HLAPropertyDataElement(propertyReference); + sg::HLAPropertyDataElement* dataElement = new sg::HLAPropertyDataElement; + propertyReferenceSet.insert(j->second, dataElement); + attributePathElementMap[i->first][j->first] = dataElement; } } } -- 2.39.5