]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAObjectInstance.hxx
Merge branch 'next' of git://gitorious.org/fg/simgear into next
[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     void registerInstance();
56     void deleteInstance(const RTIData& tag);
57
58     class AttributeCallback : public SGReferenced {
59     public:
60         virtual ~AttributeCallback() {}
61         // Notification about reflect and whatever TBD
62         // Hmm, don't know yet how this should look like
63         virtual void updateAttributeValues(HLAObjectInstance& objectInstance, const RTIData& tag)
64         { }
65
66         virtual void reflectAttributeValues(HLAObjectInstance& objectInstance,
67                                             const RTIIndexDataPairList& dataPairList, const RTIData& tag)
68         { }
69         virtual void reflectAttributeValues(HLAObjectInstance& objectInstance, const RTIIndexDataPairList& dataPairList,
70                                             const SGTimeStamp& timeStamp, const RTIData& tag)
71         { reflectAttributeValues(objectInstance, dataPairList, tag); }
72     };
73
74     void setAttributeCallback(const SGSharedPtr<AttributeCallback>& attributeCallback)
75     { _attributeCallback = attributeCallback; }
76     const SGSharedPtr<AttributeCallback>& getAttributeCallback() const
77     { return _attributeCallback; }
78
79     // Push the current values into the RTI
80     void updateAttributeValues(const RTIData& tag);
81     void updateAttributeValues(const SGTimeStamp& timeStamp, const RTIData& tag);
82
83 private:
84     void removeInstance(const RTIData& tag);
85     void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const RTIData& tag);
86     void reflectAttributeValues(const RTIIndexDataPairList& dataPairList, const SGTimeStamp& timeStamp, const RTIData& tag);
87     friend class RTIObjectInstance;
88     friend class HLAObjectClass;
89
90     class DataElementFactoryVisitor;
91
92     std::string _name;
93
94     SGWeakPtr<HLAObjectClass> _objectClass;
95     SGSharedPtr<RTIObjectInstance> _rtiObjectInstance;
96     SGSharedPtr<AttributeCallback> _attributeCallback;
97 };
98
99 } // namespace simgear
100
101 #endif