]> git.mxchange.org Git - simgear.git/blob - simgear/hla/RTIObjectInstance.hxx
hla: Remove deprecated methods from HLAObjectClass
[simgear.git] / simgear / hla / RTIObjectInstance.hxx
1 // Copyright (C) 2009 - 2010  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 RTIObjectInstance_hxx
19 #define RTIObjectInstance_hxx
20
21 #include <string>
22 #include <vector>
23 #include "simgear/structure/SGReferenced.hxx"
24 #include "simgear/timing/timestamp.hxx"
25 #include "RTIData.hxx"
26 #include "RTIObjectClass.hxx"
27 #include "HLADataElement.hxx"
28
29 class SGTimeStamp;
30
31 namespace simgear {
32
33 class RTIObjectClass;
34 class HLAObjectInstance;
35
36 class RTIObjectInstance : public SGReferenced {
37 public:
38     RTIObjectInstance(HLAObjectInstance* objectInstance);
39     virtual ~RTIObjectInstance();
40
41     void setObjectInstance(HLAObjectInstance* objectInstance)
42     { _objectInstance = objectInstance; }
43
44     virtual const RTIObjectClass* getObjectClass() const = 0;
45
46     virtual std::string getName() const = 0;
47
48     unsigned getNumAttributes() const;
49
50     virtual void deleteObjectInstance(const RTIData& tag) = 0;
51     virtual void deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;
52     virtual void localDeleteObjectInstance() = 0;
53
54     virtual void requestObjectAttributeValueUpdate(const HLAIndexList& indexList) = 0;
55
56     virtual void updateAttributeValues(const RTIData& tag) = 0;
57     virtual void updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;
58
59     virtual bool isAttributeOwnedByFederate(unsigned index) const = 0;
60
61     void removeInstance(const RTIData& tag);
62     void reflectAttributeValues(const HLAIndexList& indexList, const RTIData& tag);
63     void reflectAttributeValues(const HLAIndexList& indexList, const SGTimeStamp& timeStamp, const RTIData& tag);
64
65     bool encodeAttributeData(unsigned index, const HLADataElement& dataElement)
66     {
67         if (_attributeData.size() <= index)
68             return false;
69         return _attributeData[index].encodeAttributeData(dataElement);
70     }
71
72     bool decodeAttributeData(unsigned index, HLADataElement& dataElement) const
73     {
74         if (_attributeData.size() <= index)
75             return false;
76         return _attributeData[index].decodeAttributeData(dataElement);
77     }
78
79     bool getAttributeData(unsigned index, RTIData& data) const
80     {
81         if (_attributeData.size() <= index)
82             return false;
83         data = _attributeData[index]._data;
84         return true;
85     }
86
87     bool getAttributeOwned(unsigned index) const
88     {
89         if (_attributeData.size() <= index)
90             return false;
91         return _attributeData[index]._owned;
92     }
93
94     void setAttributeInScope(unsigned i, bool inScope)
95     {
96         if (_attributeData.size() <= i)
97             return;
98         _attributeData[i]._inScope = inScope;
99     }
100     void setAttributeUpdateEnabled(unsigned i, bool enabled)
101     {
102         if (_attributeData.size() <= i)
103             return;
104         _attributeData[i]._updateEnabled = enabled;
105     }
106
107 protected:
108     // Initially set the number of attributes, do an initial query for the attribute ownership
109     void _setNumAttributes(unsigned numAttributes)
110     {
111         _attributeData.resize(numAttributes);
112         for (unsigned i = 0; i < numAttributes; ++i)
113             _attributeData[i]._owned = isAttributeOwnedByFederate(i);
114     }
115
116     // The backward reference to the user visible object
117     HLAObjectInstance* _objectInstance;
118
119     struct AttributeData {
120         AttributeData() : _owned(false), _inScope(true), _updateEnabled(true), _dirty(false)
121         { }
122
123         bool encodeAttributeData(const HLADataElement& dataElement)
124         {
125             _dirty = true;
126             _data.resize(0);
127             HLAEncodeStream stream(_data);
128             return dataElement.encode(stream);
129         }
130
131         bool decodeAttributeData(HLADataElement& dataElement) const
132         {
133             HLADecodeStream stream(_data);
134             return dataElement.decode(stream);
135         }
136
137         // The rti level raw data element
138         RTIData _data;
139
140         // The state of the attribute as tracked from the rti.
141         bool _owned;
142         bool _inScope;
143         bool _updateEnabled;
144
145         // Is set to true if _data has be reencoded
146         bool _dirty;
147     };
148     std::vector<AttributeData> _attributeData;
149 };
150
151 }
152
153 #endif