X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fhla%2FHLADataElement.hxx;h=ffbaf5df8dade297be8249e6bd569358d9a29cfd;hb=7dc8bf3aa41655e8ae63a7193fe99b5a7802a6b7;hp=284422b8e6130b4bf55dd5a73788c508e1d94e5e;hpb=baf511684119e219906fa37f3e7c7f43151bb435;p=simgear.git diff --git a/simgear/hla/HLADataElement.hxx b/simgear/hla/HLADataElement.hxx index 284422b8..ffbaf5df 100644 --- a/simgear/hla/HLADataElement.hxx +++ b/simgear/hla/HLADataElement.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2009 - 2010 Mathias Froehlich - Mathias.Froehlich@web.de +// Copyright (C) 2009 - 2011 Mathias Froehlich - Mathias.Froehlich@web.de // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -25,49 +25,63 @@ #include #include "RTIData.hxx" #include "HLADataType.hxx" +#include "HLATypes.hxx" class SGTimeStamp; namespace simgear { +class HLADataElementVisitor; +class HLAConstDataElementVisitor; + class HLADataElement : public SGReferenced { public: virtual ~HLADataElement(); + virtual void accept(HLADataElementVisitor& visitor) = 0; + virtual void accept(HLAConstDataElementVisitor& visitor) const = 0; + virtual bool encode(HLAEncodeStream& stream) const = 0; virtual bool decode(HLADecodeStream& stream) = 0; virtual const HLADataType* getDataType() const = 0; virtual bool setDataType(const HLADataType* dataType) = 0; - // Container for the timestamp the originating attribute was last updated for - // class TimeStamp : public SGReferenced { - // public: - // const SGTimeStamp& getTimeStamp() const - // { return _timeStamp; } - // void setTimeStamp(const SGTimeStamp& timeStamp) - // { _timeStamp = timeStamp; } - // private: - // SGTimeStamp _timeStamp; - // }; - - // const TimeStamp* getTimeStamp() const - // { return _timeStamp.get(); } - // void setTimeStamp(const TimeStamp* timeStamp) - // { _timeStamp = timeStamp; } - - // struct ChangeCount : public SGReferenced { - // ChangeCount() : _value(0) {} - // unsigned _value; - // }; - // SGSharedPtr _changeCount; - // unsigned getChangeCount() const - // { - // // If we don't have return allways the same - // if (!_changeCount.valid()) - // return 0; - // return _changeCount->_value; - // } + bool setDataElement(const HLADataElementIndex& index, HLADataElement* dataElement) + { return setDataElement(index.begin(), index.end(), dataElement); } + HLADataElement* getDataElement(const HLADataElementIndex& index) + { return getDataElement(index.begin(), index.end()); } + const HLADataElement* getDataElement(const HLADataElementIndex& index) const + { return getDataElement(index.begin(), index.end()); } + + virtual bool setDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end, HLADataElement* dataElement); + virtual HLADataElement* getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end); + virtual const HLADataElement* getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end) const; + + /// Returns the time stamp if this data element. + /// Do not access this getter if the getTimeStampValid() method returns false. + const SGTimeStamp& getTimeStamp() const + { return _stamp->getTimeStamp(); } + void setTimeStamp(const SGTimeStamp& timeStamp); + + bool getTimeStampValid() const + { if (!_stamp.valid()) return false; return _stamp->getTimeStampValid(); } + void setTimeStampValid(bool timeStampValid); + + /// Convenience function that gives the time difference in seconds to a given timestamp + /// This function returns 0 if the timestamp is not valid. + double getTimeDifference(const SGTimeStamp& timeStamp) const; + + /// Dirty tracking of the attribute/parameter that this data element belongs to + bool getDirty() const + { if (!_stamp.valid()) return true; return _stamp->getDirty(); } + void setDirty(bool dirty) + { if (!_stamp.valid()) return; _stamp->setDirty(dirty); } + + /// Stamp handling + void createStamp(); + 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 @@ -144,18 +158,52 @@ public: SGSharedPtr _data; }; typedef std::list Path; - typedef std::pair AttributePathPair; + typedef std::pair StringPathPair; typedef std::pair IndexPathPair; static std::string toString(const Path& path); - static std::string toString(const AttributePathPair& path) + static std::string toString(const StringPathPair& path) { return path.first + toString(path.second); } - static AttributePathPair toAttributePathPair(const std::string& s); + static StringPathPair toStringPathPair(const std::string& s); static Path toPath(const std::string& s) - { return toAttributePathPair(s).second; } + { return toStringPathPair(s).second; } + +protected: + // Container for the timestamp the originating attribute was last updated for + class Stamp : public SGReferenced { + public: + Stamp() : _timeStampValid(false), _dirty(true) + { } + + const SGTimeStamp& getTimeStamp() const + { return _timeStamp; } + void setTimeStamp(const SGTimeStamp& timeStamp) + { _timeStamp = timeStamp; } + + bool getTimeStampValid() const + { return _timeStampValid; } + void setTimeStampValid(bool timeStampValid) + { _timeStampValid = timeStampValid; } + + bool getDirty() const + { return _dirty; } + void setDirty(bool dirty) + { _dirty = dirty; } + + private: + SGTimeStamp _timeStamp; + bool _timeStampValid; + bool _dirty; + }; + + /// get the stamp + Stamp* _getStamp() const + { return _stamp.get(); } + /// Set the stamp + virtual void _setStamp(Stamp* stamp); private: - // SGSharedPtr _timeStamp; + SGSharedPtr _stamp; }; class HLADataElementProvider {