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 HLAObjectInstance_hxx
19 #define HLAObjectInstance_hxx
21 #include <simgear/structure/SGWeakPtr.hxx>
23 #include "HLADataElement.hxx"
29 class RTIObjectInstance;
32 class HLAObjectInstance : public SGWeakReferenced {
34 HLAObjectInstance(HLAObjectClass* objectClass);
35 HLAObjectInstance(HLAObjectClass* objectClass, RTIObjectInstance* rtiObjectInstance);
36 virtual ~HLAObjectInstance();
38 const std::string& getName() const
41 SGSharedPtr<HLAObjectClass> getObjectClass() const;
43 unsigned getNumAttributes() const;
44 unsigned getAttributeIndex(const std::string& name) const;
45 std::string getAttributeName(unsigned index) const;
47 const HLADataType* getAttributeDataType(unsigned index) const;
49 void setAttributeDataElement(unsigned index, SGSharedPtr<HLADataElement> dataElement);
50 HLADataElement* getAttributeDataElement(unsigned index);
51 const HLADataElement* getAttributeDataElement(unsigned index) const;
52 void setAttribute(unsigned index, const HLAPathElementMap& pathElementMap);
53 void setAttributes(const HLAAttributePathElementMap& attributePathElementMap);
55 // Ask the rti to provide the attribute at index
56 void requestAttributeUpdate(unsigned index);
57 void requestAttributeUpdate();
59 void registerInstance();
60 void deleteInstance(const RTIData& tag);
61 void localDeleteInstance();
63 class AttributeCallback : public SGReferenced {
65 virtual ~AttributeCallback() {}
66 // Notification about reflect and whatever TBD
67 // Hmm, don't know yet how this should look like
68 virtual void updateAttributeValues(HLAObjectInstance& objectInstance, const RTIData& tag)
71 virtual void reflectAttributeValues(HLAObjectInstance& objectInstance,
72 const RTIIndexDataPairList& dataPairList, const RTIData& tag)
74 virtual void reflectAttributeValues(HLAObjectInstance& objectInstance, const RTIIndexDataPairList& dataPairList,
75 const SGTimeStamp& timeStamp, const RTIData& tag)
76 { reflectAttributeValues(objectInstance, dataPairList, tag); }
79 void setAttributeCallback(const SGSharedPtr<AttributeCallback>& attributeCallback)
80 { _attributeCallback = attributeCallback; }
81 const SGSharedPtr<AttributeCallback>& getAttributeCallback() const
82 { return _attributeCallback; }
84 // Push the current values into the RTI
85 void updateAttributeValues(const RTIData& tag);
86 void updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag);
88 // Retrieve queued up updates up to and including timestamp,
89 // Note that this only applies to timestamped updates.
90 // The unordered updates are reflected as they arrive
91 void reflectQueuedAttributeValues(const SGTimeStamp& timeStamp);
94 void removeInstance(const RTIData& tag);
95 void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const RTIData& tag);
96 void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const SGTimeStamp& timeStamp, const RTIData& tag);
97 friend class RTIObjectInstance;
98 friend class HLAObjectClass;
100 class DataElementFactoryVisitor;
104 SGWeakPtr<HLAObjectClass> _objectClass;
105 SGSharedPtr<RTIObjectInstance> _rtiObjectInstance;
106 SGSharedPtr<AttributeCallback> _attributeCallback;
109 } // namespace simgear