1 // Copyright (C) 2009 - 2011 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef HLADataElement_hxx
19 #define HLADataElement_hxx
23 #include <simgear/structure/SGReferenced.hxx>
24 #include <simgear/structure/SGSharedPtr.hxx>
25 #include <simgear/timing/timestamp.hxx>
26 #include "RTIData.hxx"
27 #include "HLADataType.hxx"
28 #include "HLATypes.hxx"
34 class HLADataElementVisitor;
35 class HLAConstDataElementVisitor;
37 class HLADataElement : public SGReferenced {
39 virtual ~HLADataElement();
41 virtual void accept(HLADataElementVisitor& visitor) = 0;
42 virtual void accept(HLAConstDataElementVisitor& visitor) const = 0;
44 virtual bool encode(HLAEncodeStream& stream) const = 0;
45 virtual bool decode(HLADecodeStream& stream) = 0;
47 virtual const HLADataType* getDataType() const = 0;
48 virtual bool setDataType(const HLADataType* dataType) = 0;
50 bool setDataElement(const HLADataElementIndex& index, HLADataElement* dataElement)
51 { return setDataElement(index.begin(), index.end(), dataElement); }
52 HLADataElement* getDataElement(const HLADataElementIndex& index)
53 { return getDataElement(index.begin(), index.end()); }
54 const HLADataElement* getDataElement(const HLADataElementIndex& index) const
55 { return getDataElement(index.begin(), index.end()); }
57 virtual bool setDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end, HLADataElement* dataElement);
58 virtual HLADataElement* getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end);
59 virtual const HLADataElement* getDataElement(HLADataElementIndex::const_iterator begin, HLADataElementIndex::const_iterator end) const;
61 /// Returns the time stamp if this data element.
62 /// Do not access this getter if the getTimeStampValid() method returns false.
63 const SGTimeStamp& getTimeStamp() const
64 { return _stamp->getTimeStamp(); }
65 void setTimeStamp(const SGTimeStamp& timeStamp);
67 bool getTimeStampValid() const
68 { if (!_stamp.valid()) return false; return _stamp->getTimeStampValid(); }
69 void setTimeStampValid(bool timeStampValid);
71 /// Convenience function that gives the time difference in seconds to a given timestamp
72 /// This function returns 0 if the timestamp is not valid.
73 double getTimeDifference(const SGTimeStamp& timeStamp) const;
75 /// Dirty tracking of the attribute/parameter that this data element belongs to
77 { if (!_stamp.valid()) return true; return _stamp->getDirty(); }
78 void setDirty(bool dirty)
79 { if (!_stamp.valid()) return; _stamp->setDirty(dirty); }
83 void attachStamp(HLADataElement& dataElement);
87 // Container for the timestamp the originating attribute was last updated for
88 class Stamp : public SGReferenced {
90 Stamp() : _timeStampValid(false), _dirty(true)
93 const SGTimeStamp& getTimeStamp() const
94 { return _timeStamp; }
95 void setTimeStamp(const SGTimeStamp& timeStamp)
96 { _timeStamp = timeStamp; }
98 bool getTimeStampValid() const
99 { return _timeStampValid; }
100 void setTimeStampValid(bool timeStampValid)
101 { _timeStampValid = timeStampValid; }
103 bool getDirty() const
105 void setDirty(bool dirty)
109 SGTimeStamp _timeStamp;
110 bool _timeStampValid;
115 Stamp* _getStamp() const
116 { return _stamp.get(); }
118 virtual void _setStamp(Stamp* stamp);
121 SGSharedPtr<Stamp> _stamp;