- /// 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 StringPathPair AttributePathPair; // deprecated
- 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 AttributePathPair toAttributePathPair(const std::string& s) // deprecated
- { return toStringPathPair(s); }
- static Path toPath(const std::string& s)
- { return toStringPathPair(s).second; }
-