]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLADataElement.hxx
hla: Make use of SGLocation.
[simgear.git] / simgear / hla / HLADataElement.hxx
1 // Copyright (C) 2009 - 2011  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #ifndef HLADataElement_hxx
19 #define HLADataElement_hxx
20
21 #include <list>
22 #include <map>
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"
29
30 class SGTimeStamp;
31
32 namespace simgear {
33
34 class HLADataElementVisitor;
35 class HLAConstDataElementVisitor;
36
37 class HLADataElement : public SGReferenced {
38 public:
39     virtual ~HLADataElement();
40
41     virtual void accept(HLADataElementVisitor& visitor) = 0;
42     virtual void accept(HLAConstDataElementVisitor& visitor) const = 0;
43
44     virtual bool encode(HLAEncodeStream& stream) const = 0;
45     virtual bool decode(HLADecodeStream& stream) = 0;
46
47     virtual const HLADataType* getDataType() const = 0;
48     virtual bool setDataType(const HLADataType* dataType) = 0;
49
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()); }
56
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;
60
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);
66
67     bool getTimeStampValid() const
68     { if (!_stamp.valid()) return false; return _stamp->getTimeStampValid(); }
69     void setTimeStampValid(bool timeStampValid);
70
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;
74
75     /// Dirty tracking of the attribute/parameter that this data element belongs to
76     bool getDirty() const
77     { if (!_stamp.valid()) return true; return _stamp->getDirty(); }
78     void setDirty(bool dirty)
79     { if (!_stamp.valid()) return; _stamp->setDirty(dirty); }
80
81     /// Stamp handling
82     void createStamp();
83     void attachStamp(HLADataElement& dataElement);
84     void clearStamp();
85
86 protected:
87     // Container for the timestamp the originating attribute was last updated for
88     class Stamp : public SGReferenced {
89     public:
90         Stamp() : _timeStampValid(false), _dirty(true)
91         { }
92
93         const SGTimeStamp& getTimeStamp() const
94         { return _timeStamp; }
95         void setTimeStamp(const SGTimeStamp& timeStamp)
96         { _timeStamp = timeStamp; }
97
98         bool getTimeStampValid() const
99         { return _timeStampValid; }
100         void setTimeStampValid(bool timeStampValid)
101         { _timeStampValid = timeStampValid; }
102
103         bool getDirty() const
104         { return _dirty; }
105         void setDirty(bool dirty)
106         { _dirty = dirty; }
107
108     private:
109         SGTimeStamp _timeStamp;
110         bool _timeStampValid;
111         bool _dirty;
112     };
113
114     /// get the stamp
115     Stamp* _getStamp() const
116     { return _stamp.get(); }
117     /// Set the stamp
118     virtual void _setStamp(Stamp* stamp);
119
120 private:
121     SGSharedPtr<Stamp> _stamp;
122 };
123
124 }
125
126 #endif