1 // Copyright (C) 2009 - 2010 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 RTIObjectInstance_hxx
19 #define RTIObjectInstance_hxx
23 #include "simgear/structure/SGReferenced.hxx"
24 #include "simgear/timing/timestamp.hxx"
25 #include "RTIData.hxx"
26 #include "RTIObjectClass.hxx"
27 #include "HLADataElement.hxx"
34 class HLAObjectInstance;
36 class RTIObjectInstance : public SGReferenced {
38 RTIObjectInstance(HLAObjectInstance* objectInstance);
39 virtual ~RTIObjectInstance();
41 void setObjectInstance(HLAObjectInstance* objectInstance)
42 { _objectInstance = objectInstance; }
44 virtual const RTIObjectClass* getObjectClass() const = 0;
46 virtual std::string getName() const = 0;
48 unsigned getNumAttributes() const;
50 virtual void deleteObjectInstance(const RTIData& tag) = 0;
51 virtual void deleteObjectInstance(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;
52 virtual void localDeleteObjectInstance() = 0;
54 virtual void requestObjectAttributeValueUpdate(const HLAIndexList& indexList) = 0;
56 virtual void updateAttributeValues(const RTIData& tag) = 0;
57 virtual void updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag) = 0;
59 virtual bool isAttributeOwnedByFederate(unsigned index) const = 0;
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);
65 bool encodeAttributeData(unsigned index, const HLADataElement& dataElement)
67 if (_attributeData.size() <= index)
69 return _attributeData[index].encodeAttributeData(dataElement);
72 bool decodeAttributeData(unsigned index, HLADataElement& dataElement) const
74 if (_attributeData.size() <= index)
76 return _attributeData[index].decodeAttributeData(dataElement);
79 bool getAttributeData(unsigned index, RTIData& data) const
81 if (_attributeData.size() <= index)
83 data = _attributeData[index]._data;
87 bool getAttributeOwned(unsigned index) const
89 if (_attributeData.size() <= index)
91 return _attributeData[index]._owned;
94 void setAttributeInScope(unsigned i, bool inScope)
96 if (_attributeData.size() <= i)
98 _attributeData[i]._inScope = inScope;
100 void setAttributeUpdateEnabled(unsigned i, bool enabled)
102 if (_attributeData.size() <= i)
104 _attributeData[i]._updateEnabled = enabled;
108 // Initially set the number of attributes, do an initial query for the attribute ownership
109 void _setNumAttributes(unsigned numAttributes)
111 _attributeData.resize(numAttributes);
112 for (unsigned i = 0; i < numAttributes; ++i)
113 _attributeData[i]._owned = isAttributeOwnedByFederate(i);
116 // The backward reference to the user visible object
117 HLAObjectInstance* _objectInstance;
119 struct AttributeData {
120 AttributeData() : _owned(false), _inScope(true), _updateEnabled(true), _dirty(false)
123 bool encodeAttributeData(const HLADataElement& dataElement)
127 HLAEncodeStream stream(_data);
128 return dataElement.encode(stream);
131 bool decodeAttributeData(HLADataElement& dataElement) const
133 HLADecodeStream stream(_data);
134 return dataElement.decode(stream);
137 // The rti level raw data element
140 // The state of the attribute as tracked from the rti.
145 // Is set to true if _data has be reencoded
148 std::vector<AttributeData> _attributeData;