class HLADataType::_DataElementIndexVisitor : public HLADataTypeVisitor {
public:
- _DataElementIndexVisitor(HLADataElementIndex& index, const std::string& path, size_t offset) :
+ _DataElementIndexVisitor(HLADataElementIndex& index, const std::string& path, std::string::size_type offset) :
_index(index),
_path(path),
_offset(offset),
}
virtual void apply(const HLAArrayDataType& dataType)
{
- if (_path.size() <= _offset) {
+ if (_path.size() == _offset) {
+ _success = true;
+ return;
+ }
+ if (_path.size() < _offset) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLADataType: faild to parse data element index \"" << _path << "\":\n"
<< "Expected array subscript at the end of the path!");
return;
virtual void apply(const HLAFixedRecordDataType& dataType)
{
- if (_path.size() <= _offset) {
+ if (_path.size() == _offset) {
+ _success = true;
+ return;
+ }
+ if (_path.size() < _offset) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLADataType: faild to parse data element index \"" << _path << "\":\n"
<< "Expected field name at the end of the path!");
return;
<< "Expected field name at the end of the path!");
return;
}
- size_t len = _path.find_first_of("[.", _offset) - _offset;
+ std::string::size_type len = std::min(_path.find_first_of("[.", _offset), _path.size()) - _offset;
unsigned index = 0;
while (index < dataType.getNumFields()) {
if (_path.compare(_offset, len, dataType.getFieldName(index)) == 0)
virtual void apply(const HLAVariantRecordDataType& dataType)
{
- if (_path.size() <= _offset) {
+ if (_path.size() == _offset) {
+ _success = true;
+ return;
+ }
+ if (_path.size() < _offset) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLADataType: faild to parse data element index \"" << _path << "\":\n"
<< "Expected alternative name at the end of the path!");
return;
<< "Expected alternative name at the end of the path!");
return;
}
- size_t len = _path.find_first_of("[.", _offset) - _offset;
+ std::string::size_type len = std::min(_path.find_first_of("[.", _offset), _path.size()) - _offset;
unsigned index = 0;
while (index < dataType.getNumAlternatives()) {
if (_path.compare(_offset, len, dataType.getAlternativeName(index)) == 0)
HLADataElementIndex& _index;
const std::string& _path;
- size_t _offset;
+ std::string::size_type _offset;
bool _success;
};
bool
-HLADataType::getDataElementIndex(HLADataElementIndex& index, const std::string& path, size_t offset) const
+HLADataType::getDataElementIndex(HLADataElementIndex& index, const std::string& path, std::string::size_type offset) const
{
_DataElementIndexVisitor visitor(index, path, offset);
accept(visitor);
/// required for propper feeing of memory.
virtual void releaseDataTypeReferences();
- bool getDataElementIndex(HLADataElementIndex& index, const std::string& path, size_t offset) const;
+ bool getDataElementIndex(HLADataElementIndex& index, const std::string& path, std::string::size_type offset) const;
protected:
HLADataType(const std::string& name, unsigned alignment = 1);
}
bool
-HLAObjectClass::getAttributeIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const
+HLAObjectClass::getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const
{
if (path.empty()) {
SG_LOG(SG_NETWORK, SG_ALERT, "HLAObjectClass: failed to parse empty element path!");
return false;
}
- size_t len = path.find_first_of("[.");
+ std::string::size_type len = std::min(path.find_first_of("[."), path.size());
unsigned index = 0;
while (index < getNumAttributes()) {
if (path.compare(0, len, getAttributeName(index)) == 0)
return getAttributeDataType(index)->getDataElementIndex(dataElementIndex, path, len);
}
+HLADataElementIndex
+HLAObjectClass::getDataElementIndex(const std::string& path) const
+{
+ HLADataElementIndex dataElementIndex;
+ getDataElementIndex(dataElementIndex, path);
+ return dataElementIndex;
+}
+
bool
HLAObjectClass::subscribe()
{
HLADataElement::IndexPathPair getIndexPathPair(const std::string& path) const;
/// Get the attribute data element index for the given path, return true if successful
- bool getAttributeIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const;
+ bool getDataElementIndex(HLADataElementIndex& dataElementIndex, const std::string& path) const;
+ HLADataElementIndex getDataElementIndex(const std::string& path) const;
virtual bool subscribe();
virtual bool unsubscribe();
}
bool
-HLAObjectInstance::getAttributeIndex(HLADataElementIndex& index, const std::string& path) const
+HLAObjectInstance::getDataElementIndex(HLADataElementIndex& index, const std::string& path) const
{
HLAObjectClass* objectClass = getObjectClass().get();
if (!objectClass) {
SG_LOG(SG_IO, SG_ALERT, "Could not get the data element index of an object instance with unknown class!");
return false;
}
- return objectClass->getAttributeIndex(index, path);
+ return objectClass->getDataElementIndex(index, path);
+}
+
+HLADataElementIndex
+HLAObjectInstance::getDataElementIndex(const std::string& path) const
+{
+ HLADataElementIndex dataElementIndex;
+ getDataElementIndex(dataElementIndex, path);
+ return dataElementIndex;
}
HLADataElement*
setAttributeDataElement(index[0], dataElement);
} else {
SGSharedPtr<HLADataElement> attributeDataElement = getAttributeDataElement(index[0]);
- if (!attributeDataElement.valid())
- attributeDataElement = createAttributeDataElement(index[0]);
+ if (!attributeDataElement.valid()) {
+ createAndSetAttributeDataElement(index[0]);
+ attributeDataElement = getAttributeDataElement(index[0]);
+ }
if (!attributeDataElement.valid())
return;
attributeDataElement->setDataElement(index.begin() + 1, index.end(), dataElement.get());
HLAObjectInstance::getAttributeDataElement(const std::string& path)
{
HLADataElementIndex index;
- if (!getAttributeIndex(index, path))
+ if (!getDataElementIndex(index, path))
return 0;
return getAttributeDataElement(index);
}
HLAObjectInstance::getAttributeDataElement(const std::string& path) const
{
HLADataElementIndex index;
- if (!getAttributeIndex(index, path))
+ if (!getDataElementIndex(index, path))
return 0;
return getAttributeDataElement(index);
}
HLAObjectInstance::setAttributeDataElement(const std::string& path, const SGSharedPtr<HLADataElement>& dataElement)
{
HLADataElementIndex index;
- if (!getAttributeIndex(index, path))
+ if (!getDataElementIndex(index, path))
return;
setAttributeDataElement(index, dataElement);
}
void setAttributes(const HLAAttributePathElementMap& attributePathElementMap);
/// Retrieve the data element index for the given path.
- bool getAttributeIndex(HLADataElementIndex& index, const std::string& path) const;
+ bool getDataElementIndex(HLADataElementIndex& index, const std::string& path) const;
+ HLADataElementIndex getDataElementIndex(const std::string& path) const;
/// Return the data element of the attribute with the given index
HLADataElement* getAttributeDataElement(const HLADataElementIndex& index);