]> git.mxchange.org Git - simgear.git/blob - simgear/hla/RTIObjectClass.hxx
hla: Initially request update for subscribed unowned attributes.
[simgear.git] / simgear / hla / RTIObjectClass.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 RTIObjectClass_hxx
19 #define RTIObjectClass_hxx
20
21 #include <string>
22 #include <vector>
23 #include "simgear/structure/SGReferenced.hxx"
24 #include "simgear/structure/SGSharedPtr.hxx"
25 #include "simgear/structure/SGWeakPtr.hxx"
26 #include "RTIData.hxx"
27 #include "HLAObjectClass.hxx"
28
29 namespace simgear {
30
31 class RTIObjectInstance;
32 class HLAObjectClass;
33
34 class RTIObjectClass : public SGReferenced {
35 public:
36     RTIObjectClass(HLAObjectClass* hlaObjectClass);
37     virtual ~RTIObjectClass();
38
39     virtual std::string getName() const = 0;
40
41     virtual unsigned getNumAttributes() const = 0;
42     virtual unsigned getAttributeIndex(const std::string& name) const = 0;
43     virtual unsigned getOrCreateAttributeIndex(const std::string& name) = 0;
44
45     virtual bool publish(const std::set<unsigned>& indexSet) = 0;
46     virtual bool unpublish() = 0;
47
48     virtual bool subscribe(const std::set<unsigned>& indexSet, bool) = 0;
49     virtual bool unsubscribe() = 0;
50
51     // Factory to create an object instance that can be used in this current federate
52     virtual RTIObjectInstance* registerObjectInstance(HLAObjectInstance*) = 0;
53
54     void discoverInstance(RTIObjectInstance* objectInstance, const RTIData& tag) const;
55
56     void startRegistration() const;
57     void stopRegistration() const;
58
59     void setAttributeDataType(unsigned index, SGSharedPtr<const HLADataType> dataType)
60     {
61         if (_attributeDataVector.size() <= index)
62             return;
63         _attributeDataVector[index]._dataType = dataType;
64     }
65     const HLADataType* getAttributeDataType(unsigned index) const
66     {
67         if (_attributeDataVector.size() <= index)
68             return 0;
69         return _attributeDataVector[index]._dataType.get();
70     }
71
72     HLAUpdateType getAttributeUpdateType(unsigned index) const
73     {
74         if (_attributeDataVector.size() <= index)
75             return HLAUndefinedUpdate;
76         return _attributeDataVector[index]._updateType;
77     }
78     void setAttributeUpdateType(unsigned index, HLAUpdateType updateType)
79     {
80         if (_attributeDataVector.size() <= index)
81             return;
82         _attributeDataVector[index]._updateType = updateType;
83     }
84
85     bool getAttributeSubscribed(unsigned index) const
86     {
87         if (_attributeDataVector.size() <= index)
88             return false;
89         return _attributeDataVector[index]._subscribed;
90     }
91     bool getAttributePublished(unsigned index) const
92     {
93         if (_attributeDataVector.size() <= index)
94             return false;
95         return _attributeDataVector[index]._published;
96     }
97     std::string getAttributeName(unsigned index) const
98     {
99         if (_attributeDataVector.size() <= index)
100             return std::string();
101         return _attributeDataVector[index]._name;
102     }
103
104 protected:
105     struct AttributeData {
106         AttributeData(const std::string& name) : _name(name), _subscribed(false), _published(false), _updateType(HLAUndefinedUpdate) {}
107         std::string _name;
108         SGSharedPtr<const HLADataType> _dataType;
109         bool _subscribed;
110         bool _published;
111         HLAUpdateType _updateType;
112     };
113     typedef std::vector<AttributeData> AttributeDataVector;
114     AttributeDataVector _attributeDataVector;
115
116 private:
117     SGWeakPtr<HLAObjectClass> _hlaObjectClass;
118 };
119
120 }
121
122 #endif