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()
{
}
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)
{
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> _data;
- };
- typedef std::list<PathElement> Path;
- typedef std::pair<std::string, Path> StringPathPair;
- typedef std::pair<unsigned, Path> 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 {
SGSharedPtr<Stamp> _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<HLADataElement> 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<HLADataElement>& 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<HLADataElement>& dataElement) :
- _dataElement(dataElement)
- { }
- virtual HLADataElement* getDataElement(const HLADataElement::Path&)
- { return _dataElement.get(); }
- private:
- SGSharedPtr<HLADataElement> _dataElement;
- };
-
- SGSharedPtr<AbstractProvider> _provider;
-};
-
-typedef std::map<HLADataElement::Path, HLADataElementProvider> HLAPathElementMap;
-typedef std::map<unsigned, HLAPathElementMap> HLAAttributePathElementMap;
-
}
#endif
_parameterVector[index]._dataType = dataType;
}
-HLADataElement::IndexPathPair
-HLAInteractionClass::getIndexPathPair(const HLADataElement::StringPathPair& stringPathPair) const
-{
- unsigned index = getParameterIndex(stringPathPair.first);
- if (getNumParameters() <= index) {
- SG_LOG(SG_NETWORK, SG_ALERT, "HLAInteractionClass::getIndexPathPair(\""
- << HLADataElement::toString(stringPathPair)
- << "\"): Could not resolve attribute \"" << stringPathPair.first
- << "\" for interaction class \"" << getName() << "\"!");
- }
- return HLADataElement::IndexPathPair(index, stringPathPair.second);
-}
-
-HLADataElement::IndexPathPair
-HLAInteractionClass::getIndexPathPair(const std::string& path) const
-{
- return getIndexPathPair(HLADataElement::toStringPathPair(path));
-}
-
bool
HLAInteractionClass::getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const
{
const HLADataType* getParameterDataType(unsigned index) const;
void setParameterDataType(unsigned index, const SGSharedPtr<const HLADataType>& 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;
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));
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)
}
private:
- HLADataElement::IndexPathPair _positonIndexPathPair[3];
- HLADataElement::IndexPathPair _orientationIndexPathPair[3];
-
- HLADataElement::IndexPathPair _angularVelocityIndexPathPair[3];
- HLADataElement::IndexPathPair _linearVelocityIndexPathPair[3];
-
HLADataElementIndex _positonIndex[3];
HLADataElementIndex _orientationIndex[3];
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);
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<HLADataElement::IndexPathPair, Semantic> IndexPathPairSemanticMap;
- IndexPathPairSemanticMap _indexPathPairSemanticMap;
-
typedef std::map<HLADataElementIndex, Semantic> IndexSemanticMap;
IndexSemanticMap _indexSemanticMap;
};
_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
{
/// 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;
_attributeVector[index]._dataElement->createStamp();
}
-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<HLAArrayDataElement> 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<HLAArrayDataElement> 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<HLAFixedRecordDataElement> 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<HLAVariantRecordDataElement> variantRecordDataElement;
- variantRecordDataElement = new HLAVariantRecordDataElement(&dataType);
- variantRecordDataElement->setDataElementFactory(new VariantRecordDataElementFactory(_path, _pathElementMap));
-
- _dataElement = variantRecordDataElement;
- }
-
-private:
- SGSharedPtr<HLADataElement> 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<HLADataElement> 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
{
/// Sets the data element of the attribute with the given index to dataElement
void setAttributeDataElement(unsigned index, const SGSharedPtr<HLADataElement>& 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;
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<HLADataElement> _dataElement;