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 RTIObjectClass_hxx
19 #define RTIObjectClass_hxx
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"
31 class RTIObjectInstance;
34 class RTIObjectClass : public SGReferenced {
36 RTIObjectClass(HLAObjectClass* hlaObjectClass);
37 virtual ~RTIObjectClass();
39 virtual std::string getName() const = 0;
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;
45 virtual bool publish(const std::set<unsigned>& indexSet) = 0;
46 virtual bool unpublish() = 0;
48 virtual bool subscribe(const std::set<unsigned>& indexSet, bool) = 0;
49 virtual bool unsubscribe() = 0;
51 // Factory to create an object instance that can be used in this current federate
52 virtual RTIObjectInstance* registerObjectInstance(HLAObjectInstance*) = 0;
54 void discoverInstance(RTIObjectInstance* objectInstance, const RTIData& tag) const;
56 void startRegistration() const;
57 void stopRegistration() const;
59 void setAttributeDataType(unsigned index, SGSharedPtr<const HLADataType> dataType)
61 if (_attributeDataVector.size() <= index)
63 _attributeDataVector[index]._dataType = dataType;
65 const HLADataType* getAttributeDataType(unsigned index) const
67 if (_attributeDataVector.size() <= index)
69 return _attributeDataVector[index]._dataType.get();
72 HLAUpdateType getAttributeUpdateType(unsigned index) const
74 if (_attributeDataVector.size() <= index)
75 return HLAUndefinedUpdate;
76 return _attributeDataVector[index]._updateType;
78 void setAttributeUpdateType(unsigned index, HLAUpdateType updateType)
80 if (_attributeDataVector.size() <= index)
82 _attributeDataVector[index]._updateType = updateType;
85 bool getAttributeSubscribed(unsigned index) const
87 if (_attributeDataVector.size() <= index)
89 return _attributeDataVector[index]._subscribed;
91 bool getAttributePublished(unsigned index) const
93 if (_attributeDataVector.size() <= index)
95 return _attributeDataVector[index]._published;
97 std::string getAttributeName(unsigned index) const
99 if (_attributeDataVector.size() <= index)
100 return std::string();
101 return _attributeDataVector[index]._name;
105 struct AttributeData {
106 AttributeData(const std::string& name) : _name(name), _subscribed(false), _published(false), _updateType(HLAUndefinedUpdate) {}
108 SGSharedPtr<const HLADataType> _dataType;
111 HLAUpdateType _updateType;
113 typedef std::vector<AttributeData> AttributeDataVector;
114 AttributeDataVector _attributeDataVector;
117 SGWeakPtr<HLAObjectClass> _hlaObjectClass;