]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAObjectInstance.hxx
hla: add missing file fir the last commit.
[simgear.git] / simgear / hla / HLAObjectInstance.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 HLAObjectInstance_hxx
19 #define HLAObjectInstance_hxx
20
21 #include <simgear/structure/SGWeakPtr.hxx>
22
23 #include "HLADataElement.hxx"
24
25 class SGTimeStamp;
26
27 namespace simgear {
28
29 class RTIObjectInstance;
30 class HLAObjectClass;
31
32 class HLAObjectInstance : public SGWeakReferenced {
33 public:
34     HLAObjectInstance(HLAObjectClass* objectClass);
35     HLAObjectInstance(HLAObjectClass* objectClass, RTIObjectInstance* rtiObjectInstance);
36     virtual ~HLAObjectInstance();
37
38     const std::string& getName() const
39     { return _name; }
40
41     SGSharedPtr<HLAObjectClass> getObjectClass() const;
42
43     unsigned getNumAttributes() const;
44     unsigned getAttributeIndex(const std::string& name) const;
45     std::string getAttributeName(unsigned index) const;
46
47     const HLADataType* getAttributeDataType(unsigned index) const;
48
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);
54
55     // Ask the rti to provide the attribute at index
56     void requestAttributeUpdate(unsigned index);
57     void requestAttributeUpdate();
58
59     void registerInstance();
60     void deleteInstance(const RTIData& tag);
61     void localDeleteInstance();
62
63     class AttributeCallback : public SGReferenced {
64     public:
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)
69         { }
70
71         virtual void reflectAttributeValues(HLAObjectInstance& objectInstance,
72                                             const RTIIndexDataPairList& dataPairList, const RTIData& tag)
73         { }
74         virtual void reflectAttributeValues(HLAObjectInstance& objectInstance, const RTIIndexDataPairList& dataPairList,
75                                             const SGTimeStamp& timeStamp, const RTIData& tag)
76         { reflectAttributeValues(objectInstance, dataPairList, tag); }
77     };
78
79     void setAttributeCallback(const SGSharedPtr<AttributeCallback>& attributeCallback)
80     { _attributeCallback = attributeCallback; }
81     const SGSharedPtr<AttributeCallback>& getAttributeCallback() const
82     { return _attributeCallback; }
83
84     // Push the current values into the RTI
85     void updateAttributeValues(const RTIData& tag);
86     void updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag);
87
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);
92
93 private:
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;
99
100     class DataElementFactoryVisitor;
101
102     std::string _name;
103
104     SGWeakPtr<HLAObjectClass> _objectClass;
105     SGSharedPtr<RTIObjectInstance> _rtiObjectInstance;
106     SGSharedPtr<AttributeCallback> _attributeCallback;
107 };
108
109 } // namespace simgear
110
111 #endif