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 HLAOMTXmlVisitor_hxx
19 #define HLAOMTXmlVisitor_hxx
24 #include <simgear/structure/exception.hxx>
25 #include <simgear/structure/SGSharedPtr.hxx>
26 #include <simgear/xml/easyxml.hxx>
27 #include "HLADataType.hxx"
31 class HLAOMTXmlVisitor : public XMLVisitor {
33 /// structures representing the federate object model data
34 struct Attribute : public SGReferenced {
35 Attribute(const std::string& name) :
38 const std::string& getName() const
40 const std::string& getDimensions() const
41 { return _dimensions; }
42 const std::string& getTransportation() const
43 { return _transportation; }
44 const std::string& getOrder() const
48 std::string _dataType;
49 std::string _updateType;
50 std::string _updateCondition;
51 std::string _ownership;
53 std::string _dimensions;
54 std::string _transportation;
56 friend class HLAOMTXmlVisitor;
58 typedef std::vector<SGSharedPtr<Attribute> > AttributeList;
60 struct ObjectClass : public SGReferenced {
61 ObjectClass(const std::string& name, const std::string& sharing);
64 const std::string& getName() const;
65 const std::string& getSharing() const;
67 unsigned getNumAttributes() const;
68 const Attribute* getAttribute(unsigned index) const;
69 const Attribute* getAttribute(const std::string& name) const;
71 const ObjectClass* getParentObjectClass() const;
74 friend class HLAOMTXmlVisitor;
77 AttributeList _attributes;
78 SGSharedPtr<ObjectClass> _parentObjectClass;
80 typedef std::vector<SGSharedPtr<ObjectClass> > ObjectClassList;
82 struct Parameter : public SGReferenced {
83 Parameter(const std::string& name) :
86 const std::string& getName() const
88 const std::string& getDataType() const
93 std::string _dataType;
94 friend class HLAOMTXmlVisitor;
96 typedef std::vector<SGSharedPtr<Parameter> > ParameterList;
98 struct InteractionClass : public SGReferenced {
99 InteractionClass(const std::string& name);
102 const std::string& getName() const;
103 const std::string& getDimensions() const;
104 const std::string& getTransportation() const;
105 const std::string& getOrder() const;
107 unsigned getNumParameters() const;
108 const Parameter* getParameter(unsigned index) const;
109 const Parameter* getParameter(const std::string& name) const;
111 const InteractionClass* getParentInteractionClass() const;
114 friend class HLAOMTXmlVisitor;
116 std::string _dimensions;
117 std::string _transportation;
119 ParameterList _parameters;
120 SGSharedPtr<InteractionClass> _parentInteractionClass;
122 typedef std::vector<SGSharedPtr<InteractionClass> > InteractionClassList;
127 unsigned getNumObjectClasses() const;
128 const ObjectClass* getObjectClass(unsigned i) const;
129 const ObjectClass* getObjectClass(const std::string& name) const;
131 /// Return the data type from the fom data
132 const Attribute* getAttribute(const std::string& objectClassName, const std::string& attributeName) const;
133 /// Return the data type from the fom data
134 HLADataType* getAttributeDataType(const std::string& objectClassName, const std::string& attributeName) const;
136 unsigned getNumInteractionClasses() const;
137 const InteractionClass* getInteractionClass(unsigned i) const;
138 const InteractionClass* getInteractionClass(const std::string& name) const;
140 /// Return the data type from the fom data
141 const Parameter* getParameter(const std::string& interactionClassName, const std::string& parameterName) const;
143 /// Return the data type from the fom data
144 HLADataType* getParameterDataType(const std::string& interactionClassName, const std::string& parameterName) const;
146 HLADataType* getDataType(const std::string& dataTypeName) const;
149 typedef std::map<std::string, SGSharedPtr<HLADataType> > StringDataTypeMap;
150 SGSharedPtr<HLADataType> getDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const;
151 SGSharedPtr<HLABasicDataType> getBasicDataType(const std::string& dataTypeName) const;
152 SGSharedPtr<HLADataType> getSimpleDataType(const std::string& dataTypeName) const;
153 SGSharedPtr<HLAEnumeratedDataType> getEnumeratedDataType(const std::string& dataTypeName) const;
154 SGSharedPtr<HLADataType> getArrayDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const;
155 SGSharedPtr<HLAFixedRecordDataType> getFixedRecordDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const;
156 SGSharedPtr<HLAVariantDataType> getVariantDataType(const std::string& dataTypeName, StringDataTypeMap& dataTypeMap) const;
168 InteractionClassMode,
172 BasicDataRepresentationsMode,
176 EnumeratedDataTypesMode,
181 FixedRecordDataTypesMode,
184 VariantRecordDataTypesMode,
185 VariantRecordDataMode,
189 Mode getCurrentMode();
190 void pushMode(Mode mode);
193 virtual void startXML();
194 virtual void endXML ();
195 virtual void startElement(const char* name, const XMLAttributes& atts);
196 virtual void endElement(const char* name);
198 std::string getAttribute(const char* name, const XMLAttributes& atts);
199 std::string getAttribute(const std::string& name, const XMLAttributes& atts);
202 // std::string _name;
206 typedef std::map<std::string, BasicData> BasicDataMap;
209 // std::string _name;
210 std::string _representation;
212 std::string _resolution;
213 std::string _accuracy;
215 typedef std::map<std::string, SimpleData> SimpleDataMap;
221 typedef std::vector<Enumerator> EnumeratorList;
223 struct EnumeratedData {
224 // std::string _name;
225 std::string _representation;
226 EnumeratorList _enumeratorList;
228 typedef std::map<std::string, EnumeratedData> EnumeratedDataMap;
231 // std::string _name;
232 std::string _dataType;
233 std::string _cardinality;
234 std::string _encoding;
236 typedef std::map<std::string, ArrayData> ArrayDataMap;
240 std::string _dataType;
242 typedef std::vector<Field> FieldList;
244 struct FixedRecordData {
245 // std::string _name;
246 std::string _encoding;
247 FieldList _fieldList;
249 typedef std::map<std::string, FixedRecordData> FixedRecordDataMap;
253 std::string _dataType;
254 std::string _semantics;
255 std::string _enumerator;
257 typedef std::vector<Alternative> AlternativeList;
259 struct VariantRecordData {
260 // std::string _name;
261 std::string _encoding;
262 std::string _dataType;
263 std::string _discriminant;
264 std::string _semantics;
265 AlternativeList _alternativeList;
267 typedef std::map<std::string, VariantRecordData> VariantRecordDataMap;
269 std::vector<Mode> _modeStack;
271 /// The total list of object classes
272 ObjectClassList _objectClassList;
273 ObjectClassList _objectClassStack;
275 /// The total list of interaction classes
276 InteractionClassList _interactionClassList;
277 InteractionClassList _interactionClassStack;
279 /// DataType definitions
280 BasicDataMap _basicDataMap;
281 SimpleDataMap _simpleDataMap;
282 std::string _enumeratedDataName;
283 EnumeratedDataMap _enumeratedDataMap;
284 ArrayDataMap _arrayDataMap;
285 std::string _fixedRecordDataName;
286 FixedRecordDataMap _fixedRecordDataMap;
287 std::string _variantRecordDataName;
288 VariantRecordDataMap _variantRecordDataMap;
291 } // namespace simgear