From 9fd90e26f7da96ec968ad22dc20fc0041bc02136 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sun, 11 Nov 2012 16:56:22 +0100 Subject: [PATCH] hla: Remove HLADataElement::Path based attribute handling. --- simgear/hla/HLADataElement.cxx | 159 ---------------- simgear/hla/HLADataElement.hxx | 139 -------------- simgear/hla/HLAInteractionClass.cxx | 19 -- simgear/hla/HLAInteractionClass.hxx | 3 - simgear/hla/HLALocation.hxx | 133 ------------- simgear/hla/HLAObjectClass.cxx | 19 -- simgear/hla/HLAObjectClass.hxx | 5 - simgear/hla/HLAObjectInstance.cxx | 286 ---------------------------- simgear/hla/HLAObjectInstance.hxx | 5 - 9 files changed, 768 deletions(-) diff --git a/simgear/hla/HLADataElement.cxx b/simgear/hla/HLADataElement.cxx index 69a32d1e..da0c8e9a 100644 --- a/simgear/hla/HLADataElement.cxx +++ b/simgear/hla/HLADataElement.cxx @@ -29,110 +29,6 @@ namespace simgear { -HLADataElement::PathElement::Data::~Data() -{ -} - -const HLADataElement::PathElement::FieldData* -HLADataElement::PathElement::Data::toFieldData() const -{ - return 0; -} - -const HLADataElement::PathElement::IndexData* -HLADataElement::PathElement::Data::toIndexData() const -{ - return 0; -} - -HLADataElement::PathElement::FieldData::FieldData(const std::string& name) : - _name(name) -{ -} - -HLADataElement::PathElement::FieldData::~FieldData() -{ -} - -const HLADataElement::PathElement::FieldData* -HLADataElement::PathElement::FieldData::toFieldData() const -{ - return this; -} - -bool -HLADataElement::PathElement::FieldData::less(const Data* data) const -{ - const FieldData* fieldData = data->toFieldData(); - // IndexData is allways smaller than FieldData - if (!fieldData) - return false; - return _name < fieldData->_name; -} - -bool -HLADataElement::PathElement::FieldData::equal(const Data* data) const -{ - const FieldData* fieldData = data->toFieldData(); - // IndexData is allways smaller than FieldData - if (!fieldData) - return false; - return _name == fieldData->_name; -} - -void -HLADataElement::PathElement::FieldData::append(std::string& s) const -{ - s.append(1, std::string::value_type('.')); - s.append(_name); -} - -HLADataElement::PathElement::IndexData::IndexData(unsigned index) : - _index(index) -{ -} - -HLADataElement::PathElement::IndexData::~IndexData() -{ -} - -const HLADataElement::PathElement::IndexData* -HLADataElement::PathElement::IndexData::toIndexData() const -{ - return this; -} - -bool -HLADataElement::PathElement::IndexData::less(const Data* data) const -{ - const IndexData* indexData = data->toIndexData(); - // IndexData is allways smaller than FieldData - if (!indexData) - return true; - return _index < indexData->_index; -} - -bool -HLADataElement::PathElement::IndexData::equal(const Data* data) const -{ - const IndexData* indexData = data->toIndexData(); - // IndexData is allways smaller than FieldData - if (!indexData) - return false; - return _index == indexData->_index; -} - -void -HLADataElement::PathElement::IndexData::append(std::string& s) const -{ - s.append(1, std::string::value_type('[')); - unsigned value = _index; - do { - s.append(1, std::string::value_type('0' + value % 10)); - } while (value /= 10); - s.append(1, std::string::value_type(']')); -} - HLADataElement::~HLADataElement() { } @@ -216,61 +112,6 @@ HLADataElement::accept(HLAConstDataElementVisitor& visitor) const visitor.apply(*this); } -std::string -HLADataElement::toString(const Path& path) -{ - std::string s; - for (Path::const_iterator i = path.begin(); i != path.end(); ++i) - i->append(s); - return s; -} - -HLADataElement::StringPathPair -HLADataElement::toStringPathPair(const std::string& s) -{ - Path path; - // Skip the initial attribute/parameter name if given - std::string::size_type i = s.find_first_of("[."); - std::string attribute = s.substr(0, i); - while (i < s.size()) { - if (s[i] == '[') { - ++i; - unsigned index = 0; - while (i < s.size()) { - if (s[i] == ']') - break; - unsigned v = s[i] - '0'; - // Error, no number - if (10 <= v) { - SG_LOG(SG_NETWORK, SG_WARN, "HLADataElement: invalid character in array subscript for \"" - << s << "\" at \"" << attribute << toString(path) << "\"!"); - return StringPathPair(); - } - index *= 10; - index += v; - ++i; - } - path.push_back(index); - ++i; - continue; - } - if (s[i] == '.') { - // Error, . cannot be last - if (s.size() <= ++i) { - SG_LOG(SG_NETWORK, SG_WARN, "HLADataElement: invalid terminating '.' for \"" - << s << "\"!"); - return StringPathPair(); - } - std::string::size_type e = s.find_first_of("[.", i); - path.push_back(s.substr(i, e - i)); - i = e; - continue; - } - } - - return StringPathPair(attribute, path); -} - void HLADataElement::_setStamp(HLADataElement::Stamp* stamp) { diff --git a/simgear/hla/HLADataElement.hxx b/simgear/hla/HLADataElement.hxx index ffbaf5df..7ee817ed 100644 --- a/simgear/hla/HLADataElement.hxx +++ b/simgear/hla/HLADataElement.hxx @@ -83,91 +83,6 @@ public: void attachStamp(HLADataElement& dataElement); void clearStamp(); - /// HLADataElements could be identified by path - /// These paths are composed of structure field names and array indices in the - /// order they appear while walking to the data element. - /// So provide here some tool functions to access these elements - /// Note that these functions are relatively expensive in execution time. - /// So only use them once at object creation time and store direct references to the values - - class PathElement { - public: - PathElement(unsigned index) : _data(new IndexData(index)) {} - PathElement(const std::string& name) : _data(new FieldData(name)) {} - - bool isFieldValue() const - { return _data->toFieldData(); } - bool isIndexValue() const - { return _data->toIndexData(); } - - unsigned getIndexValue() const - { - const IndexData* indexData = _data->toIndexData(); - if (!indexData) - return ~unsigned(0); - return indexData->_index; - } - - std::string getFieldValue() const - { - const FieldData* fieldData = _data->toFieldData(); - if (!fieldData) - return std::string(); - return fieldData->_name; - } - - // Want to be able to use that in std::map and std::set - bool operator<(const PathElement& pathElement) const - { return _data->less(pathElement._data.get()); } - bool operator==(const PathElement& pathElement) const - { return _data->equal(pathElement._data.get()); } - - void append(std::string& s) const - { _data->append(s); } - - private: - struct FieldData; - struct IndexData; - struct Data : public SGReferenced { - virtual ~Data(); - virtual const FieldData* toFieldData() const; - virtual const IndexData* toIndexData() const; - virtual bool less(const Data*) const = 0; - virtual bool equal(const Data*) const = 0; - virtual void append(std::string&) const = 0; - }; - struct FieldData : public Data { - FieldData(const std::string& name); - virtual ~FieldData(); - virtual const FieldData* toFieldData() const; - virtual bool less(const Data* data) const; - virtual bool equal(const Data* data) const; - virtual void append(std::string& s) const; - std::string _name; - }; - struct IndexData : public Data { - IndexData(unsigned index); - virtual ~IndexData(); - virtual const IndexData* toIndexData() const; - virtual bool less(const Data* data) const; - virtual bool equal(const Data* data) const; - virtual void append(std::string& s) const; - unsigned _index; - }; - - SGSharedPtr _data; - }; - typedef std::list Path; - typedef std::pair StringPathPair; - typedef std::pair IndexPathPair; - - static std::string toString(const Path& path); - static std::string toString(const StringPathPair& path) - { return path.first + toString(path.second); } - static StringPathPair toStringPathPair(const std::string& s); - static Path toPath(const std::string& s) - { return toStringPathPair(s).second; } - protected: // Container for the timestamp the originating attribute was last updated for class Stamp : public SGReferenced { @@ -206,60 +121,6 @@ private: SGSharedPtr _stamp; }; -class HLADataElementProvider { -public: - class AbstractProvider : public SGReferenced { - public: - virtual ~AbstractProvider() { } - virtual HLADataElement* getDataElement(const HLADataElement::Path& path) = 0; - // virtual HLADataElement* getDataElement(const HLADataElement::Path& path, const HLADataType* dataType) - // { - // SGSharedPtr dataElement = getDataElement(path); - // if (!dataElement.valid()) - // return 0; - // if (!dataElement->setDataType(dataType)) - // return 0; - // return dataElement.release(); - // } - }; - - HLADataElementProvider() - { } - HLADataElementProvider(HLADataElement* dataElement) : - _provider(new ConcreteProvider(dataElement)) - { } - HLADataElementProvider(const SGSharedPtr& dataElement) : - _provider(new ConcreteProvider(dataElement)) - { } - HLADataElementProvider(AbstractProvider* provider) : - _provider(provider) - { } - - HLADataElement* getDataElement(const HLADataElement::Path& path) const - { - if (!_provider.valid()) - return 0; - return _provider->getDataElement(path); - } - -private: - class ConcreteProvider : public AbstractProvider { - public: - ConcreteProvider(const SGSharedPtr& dataElement) : - _dataElement(dataElement) - { } - virtual HLADataElement* getDataElement(const HLADataElement::Path&) - { return _dataElement.get(); } - private: - SGSharedPtr _dataElement; - }; - - SGSharedPtr _provider; -}; - -typedef std::map HLAPathElementMap; -typedef std::map HLAAttributePathElementMap; - } #endif diff --git a/simgear/hla/HLAInteractionClass.cxx b/simgear/hla/HLAInteractionClass.cxx index a9693d98..c5b1cc5e 100644 --- a/simgear/hla/HLAInteractionClass.cxx +++ b/simgear/hla/HLAInteractionClass.cxx @@ -140,25 +140,6 @@ HLAInteractionClass::setParameterDataType(unsigned index, const SGSharedPtr& dataType); - HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::StringPathPair& stringPathPair) const; - HLADataElement::IndexPathPair getIndexPathPair(const std::string& path) const; - /// Get the attribute data element index for the given path, return true if successful bool getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const; HLADataElementIndex getDataElementIndex(const std::string& path) const; diff --git a/simgear/hla/HLALocation.hxx b/simgear/hla/HLALocation.hxx index 627cc763..474a39c6 100644 --- a/simgear/hla/HLALocation.hxx +++ b/simgear/hla/HLALocation.hxx @@ -166,85 +166,14 @@ private: class HLALocationFactory : public SGReferenced { public: virtual ~HLALocationFactory() {} - virtual HLAAbstractLocation* createLocation(HLAAttributePathElementMap&) const = 0; virtual HLAAbstractLocation* createLocation(HLAObjectInstance&) const = 0; }; class HLACartesianLocationFactory : public HLALocationFactory { public: - virtual HLACartesianLocation* createLocation(HLAAttributePathElementMap& attributePathElementMap) const - { - HLACartesianLocation* location = new HLACartesianLocation; - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _positonIndexPathPair[i]; - attributePathElementMap[indexPathPair.first][indexPathPair.second] = location->getPositionDataElement(i); - } - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _orientationIndexPathPair[i]; - attributePathElementMap[indexPathPair.first][indexPathPair.second] = location->getOrientationDataElement(i); - } - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _angularVelocityIndexPathPair[i]; - attributePathElementMap[indexPathPair.first][indexPathPair.second] = location->getAngularVelocityDataElement(i); - } - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _linearVelocityIndexPathPair[i]; - attributePathElementMap[indexPathPair.first][indexPathPair.second] = location->getLinearVelocityDataElement(i); - } - return location; - } - virtual HLACartesianLocation* createLocation(HLAObjectInstance& objectInstance) const { HLACartesianLocation* location = new HLACartesianLocation; - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _positonIndexPathPair[i]; - if (indexPathPair.first == 0) - continue; - std::string path = objectInstance.getAttributeName(indexPathPair.first); - if (!indexPathPair.second.empty()) - path += HLADataElement::toString(indexPathPair.second); - HLADataElementIndex index; - if (!objectInstance.getDataElementIndex(index, path)) - continue; - objectInstance.setAttributeDataElement(index, location->getPositionDataElement(i)); - } - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _orientationIndexPathPair[i]; - if (indexPathPair.first == 0) - continue; - std::string path = objectInstance.getAttributeName(indexPathPair.first); - if (!indexPathPair.second.empty()) - path += HLADataElement::toString(indexPathPair.second); - HLADataElementIndex index; - if (!objectInstance.getDataElementIndex(index, path)) - continue; - objectInstance.setAttributeDataElement(index, location->getOrientationDataElement(i)); - } - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _angularVelocityIndexPathPair[i]; - if (indexPathPair.first == 0) - continue; - std::string path = objectInstance.getAttributeName(indexPathPair.first); - if (!indexPathPair.second.empty()) - path += HLADataElement::toString(indexPathPair.second); - HLADataElementIndex index; - if (!objectInstance.getDataElementIndex(index, path)) - continue; - objectInstance.setAttributeDataElement(index, location->getAngularVelocityDataElement(i)); - } - for (unsigned i = 0; i < 3; ++i) { - const HLADataElement::IndexPathPair& indexPathPair = _linearVelocityIndexPathPair[i]; - if (indexPathPair.first == 0) - continue; - std::string path = objectInstance.getAttributeName(indexPathPair.first); - if (!indexPathPair.second.empty()) - path += HLADataElement::toString(indexPathPair.second); - HLADataElementIndex index; - if (!objectInstance.getDataElementIndex(index, path)) - continue; - objectInstance.setAttributeDataElement(index, location->getLinearVelocityDataElement(i)); - } for (unsigned i = 0; i < 3; ++i) objectInstance.setAttributeDataElement(_positonIndex[i], location->getPositionDataElement(i)); @@ -258,32 +187,6 @@ public: return location; } - void setPositionIndexPathPair(unsigned index, const HLADataElement::IndexPathPair& indexPathPair) - { - if (3 <= index) - return; - _positonIndexPathPair[index] = indexPathPair; - } - void setOrientationIndexPathPair(unsigned index, const HLADataElement::IndexPathPair& indexPathPair) - { - if (3 <= index) - return; - _orientationIndexPathPair[index] = indexPathPair; - } - - void setAngularVelocityIndexPathPair(unsigned index, const HLADataElement::IndexPathPair& indexPathPair) - { - if (3 <= index) - return; - _angularVelocityIndexPathPair[index] = indexPathPair; - } - void setLinearVelocityIndexPathPair(unsigned index, const HLADataElement::IndexPathPair& indexPathPair) - { - if (3 <= index) - return; - _linearVelocityIndexPathPair[index] = indexPathPair; - } - void setPositionIndex(unsigned index, const HLADataElementIndex& dataElementIndex) { if (3 <= index) @@ -311,12 +214,6 @@ public: } private: - HLADataElement::IndexPathPair _positonIndexPathPair[3]; - HLADataElement::IndexPathPair _orientationIndexPathPair[3]; - - HLADataElement::IndexPathPair _angularVelocityIndexPathPair[3]; - HLADataElement::IndexPathPair _linearVelocityIndexPathPair[3]; - HLADataElementIndex _positonIndex[3]; HLADataElementIndex _orientationIndex[3]; @@ -632,35 +529,10 @@ public: VerticalSpeedMPerSec = HLAGeodeticLocation::VerticalSpeedMPerSec }; - virtual HLAGeodeticLocation* createLocation(HLAAttributePathElementMap& attributePathElementMap) const - { - HLAGeodeticLocation* location = new HLAGeodeticLocation; - - for (IndexPathPairSemanticMap::const_iterator i = _indexPathPairSemanticMap.begin(); - i != _indexPathPairSemanticMap.end(); ++i) { - HLAGeodeticLocation::Semantic semantic = HLAGeodeticLocation::Semantic(i->second); - attributePathElementMap[i->first.first][i->first.second] = location->getDataElement(semantic); - } - - return location; - } - virtual HLAGeodeticLocation* createLocation(HLAObjectInstance& objectInstance) const { HLAGeodeticLocation* location = new HLAGeodeticLocation; - for (IndexPathPairSemanticMap::const_iterator i = _indexPathPairSemanticMap.begin(); - i != _indexPathPairSemanticMap.end(); ++i) { - std::string path = objectInstance.getAttributeName(i->first.first); - if (!i->first.second.empty()) - path += HLADataElement::toString(i->first.second); - HLADataElementIndex index; - if (!objectInstance.getDataElementIndex(index, path)) - continue; - HLAGeodeticLocation::Semantic semantic = HLAGeodeticLocation::Semantic(i->second); - objectInstance.setAttributeDataElement(index, location->getDataElement(semantic)); - } - for (IndexSemanticMap::const_iterator i = _indexSemanticMap.begin(); i != _indexSemanticMap.end(); ++i) { HLAGeodeticLocation::Semantic semantic = HLAGeodeticLocation::Semantic(i->second); @@ -670,15 +542,10 @@ public: return location; } - void setIndexPathPair(Semantic semantic, const HLADataElement::IndexPathPair& indexPathPair) - { _indexPathPairSemanticMap[indexPathPair] = semantic; } void setIndex(Semantic semantic, const HLADataElementIndex& index) { _indexSemanticMap[index] = semantic; } private: - typedef std::map IndexPathPairSemanticMap; - IndexPathPairSemanticMap _indexPathPairSemanticMap; - typedef std::map IndexSemanticMap; IndexSemanticMap _indexSemanticMap; }; diff --git a/simgear/hla/HLAObjectClass.cxx b/simgear/hla/HLAObjectClass.cxx index c9282688..2740eb02 100644 --- a/simgear/hla/HLAObjectClass.cxx +++ b/simgear/hla/HLAObjectClass.cxx @@ -191,25 +191,6 @@ HLAObjectClass::setAttributePublicationType(unsigned index, HLAPublicationType p _attributeVector[index]._publicationType = publicationType; } -HLADataElement::IndexPathPair -HLAObjectClass::getIndexPathPair(const HLADataElement::StringPathPair& stringPathPair) const -{ - unsigned index = getAttributeIndex(stringPathPair.first); - if (getNumAttributes() <= index) { - SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass::getIndexPathPair(\"" - << HLADataElement::toString(stringPathPair) - << "\"): Could not resolve attribute \"" << stringPathPair.first - << "\" for object class \"" << getName() << "\"!"); - } - return HLADataElement::IndexPathPair(index, stringPathPair.second); -} - -HLADataElement::IndexPathPair -HLAObjectClass::getIndexPathPair(const std::string& path) const -{ - return getIndexPathPair(HLADataElement::toStringPathPair(path)); -} - bool HLAObjectClass::getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const { diff --git a/simgear/hla/HLAObjectClass.hxx b/simgear/hla/HLAObjectClass.hxx index 97596d40..f4453c7c 100644 --- a/simgear/hla/HLAObjectClass.hxx +++ b/simgear/hla/HLAObjectClass.hxx @@ -72,11 +72,6 @@ public: /// Sets the publication type of the attribute with the given index to publicationType void setAttributePublicationType(unsigned index, HLAPublicationType publicationType); - /// Return the index, path pair for the given string path pair - HLADataElement::IndexPathPair getIndexPathPair(const HLADataElement::StringPathPair&) const; - /// Return the index, path pair for the given string path - HLADataElement::IndexPathPair getIndexPathPair(const std::string& path) const; - /// Get the attribute data element index for the given path, return true if successful bool getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const; HLADataElementIndex getDataElementIndex(const std::string& path) const; diff --git a/simgear/hla/HLAObjectInstance.cxx b/simgear/hla/HLAObjectInstance.cxx index 39ff74ca..d1f4fac5 100644 --- a/simgear/hla/HLAObjectInstance.cxx +++ b/simgear/hla/HLAObjectInstance.cxx @@ -156,292 +156,6 @@ HLAObjectInstance::setAttributeDataElement(unsigned index, const SGSharedPtrcreateStamp(); } -class HLAObjectInstance::DataElementFactoryVisitor : public HLADataElementFactoryVisitor { -public: - DataElementFactoryVisitor(const HLAPathElementMap& pathElementMap) : - _pathElementMap(pathElementMap) - { } - DataElementFactoryVisitor(const HLADataElement::Path& path, const HLAPathElementMap& pathElementMap) : - _pathElementMap(pathElementMap), - _path(path) - { } - virtual ~DataElementFactoryVisitor() {} - - virtual void apply(const HLADataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - SG_LOG(SG_NETWORK, SG_ALERT, "HLA: Can not find a suitable data element for data type \"" - << dataType.getName() << "\""); - } - - virtual void apply(const HLAInt8DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAUInt8DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAInt16DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAUInt16DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAInt32DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAUInt32DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAInt64DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAUInt64DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAFloat32DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - virtual void apply(const HLAFloat64DataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - - class ArrayDataElementFactory : public HLAArrayDataElement::DataElementFactory { - public: - ArrayDataElementFactory(const HLADataElement::Path& path, const HLAPathElementMap& pathElementMap) : - _path(path) - { - for (HLAPathElementMap::const_iterator i = pathElementMap.lower_bound(path); - i != pathElementMap.end(); ++i) { - if (i->first.begin() != std::search(i->first.begin(), i->first.end(), - path.begin(), path.end())) - break; - _pathElementMap.insert(*i); - } - } - virtual HLADataElement* createElement(const HLAArrayDataElement& element, unsigned index) - { - const HLADataType* dataType = element.getElementDataType(); - if (!dataType) - return 0; - HLADataElement::Path path = _path; - path.push_back(HLADataElement::PathElement(index)); - DataElementFactoryVisitor visitor(path, _pathElementMap); - dataType->accept(visitor); - return visitor._dataElement.release(); - } - private: - HLADataElement::Path _path; - HLAPathElementMap _pathElementMap; - }; - - virtual void apply(const HLAFixedArrayDataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - SGSharedPtr arrayDataElement; - arrayDataElement = new HLAArrayDataElement(&dataType); - arrayDataElement->setDataElementFactory(new ArrayDataElementFactory(_path, _pathElementMap)); - arrayDataElement->setNumElements(dataType.getNumElements()); - - _dataElement = arrayDataElement; - } - - virtual void apply(const HLAVariableArrayDataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - SGSharedPtr arrayDataElement; - arrayDataElement = new HLAArrayDataElement(&dataType); - arrayDataElement->setDataElementFactory(new ArrayDataElementFactory(_path, _pathElementMap)); - - _dataElement = arrayDataElement; - } - - virtual void apply(const HLAEnumeratedDataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - HLADataElementFactoryVisitor::apply(dataType); - } - - virtual void apply(const HLAFixedRecordDataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - SGSharedPtr recordDataElement; - recordDataElement = new HLAFixedRecordDataElement(&dataType); - - unsigned numFields = dataType.getNumFields(); - for (unsigned i = 0; i < numFields; ++i) { - - _path.push_back(HLADataElement::PathElement(dataType.getFieldName(i))); - - dataType.getFieldDataType(i)->accept(*this); - recordDataElement->setField(i, _dataElement.release()); - - _path.pop_back(); - } - _dataElement = recordDataElement; - } - - class VariantRecordDataElementFactory : public HLAVariantRecordDataElement::DataElementFactory { - public: - VariantRecordDataElementFactory(const HLADataElement::Path& path, const HLAPathElementMap& pathElementMap) : - _path(path) - { - for (HLAPathElementMap::const_iterator i = pathElementMap.lower_bound(path); - i != pathElementMap.end(); ++i) { - if (i->first.begin() != std::search(i->first.begin(), i->first.end(), - path.begin(), path.end())) - break; - _pathElementMap.insert(*i); - } - } - virtual HLADataElement* createElement(const HLAVariantRecordDataElement& element, unsigned index) - { - const HLAVariantRecordDataType* dataType = element.getDataType(); - if (!dataType) - return 0; - const HLADataType* alternativeDataType = element.getAlternativeDataType(); - if (!alternativeDataType) - return 0; - HLADataElement::Path path = _path; - path.push_back(HLADataElement::PathElement(dataType->getAlternativeName(index))); - DataElementFactoryVisitor visitor(path, _pathElementMap); - alternativeDataType->accept(visitor); - return visitor._dataElement.release(); - } - private: - HLADataElement::Path _path; - HLAPathElementMap _pathElementMap; - }; - - virtual void apply(const HLAVariantRecordDataType& dataType) - { - _dataElement = createDataElement(_path, dataType); - if (_dataElement.valid()) - return; - - SGSharedPtr variantRecordDataElement; - variantRecordDataElement = new HLAVariantRecordDataElement(&dataType); - variantRecordDataElement->setDataElementFactory(new VariantRecordDataElementFactory(_path, _pathElementMap)); - - _dataElement = variantRecordDataElement; - } - -private: - SGSharedPtr createDataElement(const HLADataElement::Path& path, const HLADataType& dataType) - { - HLAPathElementMap::const_iterator i = _pathElementMap.find(path); - if (i == _pathElementMap.end()) { - SG_LOG(SG_IO, SG_WARN, "No dataElement provided for \"" - << HLADataElement::toString(path) << "\"."); - - return 0; - } - SGSharedPtr dataElement = i->second.getDataElement(path); - if (!dataElement->setDataType(&dataType)) { - SG_LOG(SG_IO, SG_ALERT, "Cannot set data type for data element at \"" - << HLADataElement::toString(path) << "\"!"); - return 0; - } - SG_LOG(SG_IO, SG_DEBUG, "Using provided dataElement for \"" - << HLADataElement::toString(path) << "\"."); - return dataElement; - } - - const HLAPathElementMap& _pathElementMap; - HLADataElement::Path _path; -}; - -void -HLAObjectInstance::setAttribute(unsigned index, const HLAPathElementMap& pathElementMap) -{ - const HLADataType* dataType = getAttributeDataType(index); - if (!dataType) { - SG_LOG(SG_IO, SG_ALERT, "Cannot get attribute data type for setting attribute \"" - << getAttributeName(index) << "\" at index " << index << "!"); - return; - } - - SG_LOG(SG_IO, SG_DEBUG, "Setting DataElement for attribute \"" - << getAttributeName(index) << "\"."); - - DataElementFactoryVisitor visitor(pathElementMap); - dataType->accept(visitor); - setAttributeDataElement(index, visitor.getDataElement()); -} - -void -HLAObjectInstance::setAttributes(const HLAAttributePathElementMap& attributePathElementMap) -{ - for (HLAAttributePathElementMap::const_iterator i = attributePathElementMap.begin(); - i != attributePathElementMap.end(); ++i) { - setAttribute(i->first, i->second); - } -} - bool HLAObjectInstance::getDataElementIndex(HLADataElementIndex& index, const std::string& path) const { diff --git a/simgear/hla/HLAObjectInstance.hxx b/simgear/hla/HLAObjectInstance.hxx index a7c802d4..e5545207 100644 --- a/simgear/hla/HLAObjectInstance.hxx +++ b/simgear/hla/HLAObjectInstance.hxx @@ -73,9 +73,6 @@ public: /// Sets the data element of the attribute with the given index to dataElement void setAttributeDataElement(unsigned index, const SGSharedPtr& dataElement); - /// Sets the data element of the attribute with the given index to the content of pathElementMap - void setAttribute(unsigned index, const HLAPathElementMap& pathElementMap); - void setAttributes(const HLAAttributePathElementMap& attributePathElementMap); /// Retrieve the data element index for the given path. bool getDataElementIndex(HLADataElementIndex& index, const std::string& path) const; @@ -173,8 +170,6 @@ private: void _reflectAttributeValues(const HLAIndexList& indexList, const RTIData& tag); void _reflectAttributeValues(const HLAIndexList& indexList, const SGTimeStamp& timeStamp, const RTIData& tag); - class DataElementFactoryVisitor; - struct Attribute { Attribute() : _enabledUpdate(false), _unconditionalUpdate(false) {} SGSharedPtr _dataElement; -- 2.39.2