]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLAOMTXmlVisitor.hxx
hla: add missing file fir the last commit.
[simgear.git] / simgear / hla / HLAOMTXmlVisitor.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 HLAOMTXmlVisitor_hxx
19 #define HLAOMTXmlVisitor_hxx
20
21 #include <map>
22 #include <string>
23
24 #include <simgear/structure/exception.hxx>
25 #include <simgear/structure/SGSharedPtr.hxx>
26 #include <simgear/xml/easyxml.hxx>
27 #include "HLADataType.hxx"
28
29 namespace simgear {
30
31 class HLAOMTXmlVisitor : public XMLVisitor {
32 public:
33     /// structures representing the federate object model data
34     struct Attribute : public SGReferenced {
35         Attribute(const std::string& name) :
36             _name(name)
37         { }
38         const std::string& getName() const
39         { return _name; }
40         const std::string& getDimensions() const
41         { return _dimensions; }
42         const std::string& getTransportation() const
43         { return _transportation; }
44         const std::string& getOrder() const
45         { return _order; }
46
47         std::string _name;
48         std::string _dataType;
49         std::string _updateType;
50         std::string _updateCondition;
51         std::string _ownership;
52         std::string _sharing;
53         std::string _dimensions;
54         std::string _transportation;
55         std::string _order;
56         friend class HLAOMTXmlVisitor;
57     };
58     typedef std::vector<SGSharedPtr<Attribute> > AttributeList;
59
60     struct ObjectClass : public SGReferenced {
61         ObjectClass(const std::string& name, const std::string& sharing);
62         ~ObjectClass();
63
64         const std::string& getName() const;
65         const std::string& getSharing() const;
66
67         unsigned getNumAttributes() const;
68         const Attribute* getAttribute(unsigned index) const;
69         const Attribute* getAttribute(const std::string& name) const;
70
71         const ObjectClass* getParentObjectClass() const;
72
73     private:
74         friend class HLAOMTXmlVisitor;
75         std::string _name;
76         std::string _sharing;
77         AttributeList _attributes;
78         SGSharedPtr<ObjectClass> _parentObjectClass;
79     };
80     typedef std::vector<SGSharedPtr<ObjectClass> > ObjectClassList;
81
82     struct Parameter : public SGReferenced {
83         Parameter(const std::string& name) :
84             _name(name)
85         { }
86         const std::string& getName() const
87         { return _name; }
88         const std::string& getDataType() const
89         { return _dataType; }
90
91     private:
92         std::string _name;
93         std::string _dataType;
94         friend class HLAOMTXmlVisitor;
95     };
96     typedef std::vector<SGSharedPtr<Parameter> > ParameterList;
97
98     struct InteractionClass : public SGReferenced {
99         InteractionClass(const std::string& name);
100         ~InteractionClass();
101
102         const std::string& getName() const;
103         const std::string& getDimensions() const;
104         const std::string& getTransportation() const;
105         const std::string& getOrder() const;
106
107         unsigned getNumParameters() const;
108         const Parameter* getParameter(unsigned index) const;
109         const Parameter* getParameter(const std::string& name) const;
110
111         const InteractionClass* getParentInteractionClass() const;
112
113     private:
114         friend class HLAOMTXmlVisitor;
115         std::string _name;
116         std::string _dimensions;
117         std::string _transportation;
118         std::string _order;
119         ParameterList _parameters;
120         SGSharedPtr<InteractionClass> _parentInteractionClass;
121     };
122     typedef std::vector<SGSharedPtr<InteractionClass> > InteractionClassList;
123
124     HLAOMTXmlVisitor();
125     ~HLAOMTXmlVisitor();
126
127     unsigned getNumObjectClasses() const;
128     const ObjectClass* getObjectClass(unsigned i) const;
129     const ObjectClass* getObjectClass(const std::string& name) const;
130
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;
135
136     unsigned getNumInteractionClasses() const;
137     const InteractionClass* getInteractionClass(unsigned i) const;
138     const InteractionClass* getInteractionClass(const std::string& name) const;
139
140     /// Return the data type from the fom data
141     const Parameter* getParameter(const std::string& interactionClassName, const std::string& parameterName) const;
142
143     /// Return the data type from the fom data
144     HLADataType* getParameterDataType(const std::string& interactionClassName, const std::string& parameterName) const;
145
146     HLADataType* getDataType(const std::string& dataTypeName) const;
147
148 private:
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;
157
158     enum Mode {
159         UnknownMode,
160
161         ObjectModelMode,
162
163         ObjectsMode,
164         ObjectClassMode,
165         AttributeMode,
166
167         InteractionsMode,
168         InteractionClassMode,
169         ParameterMode,
170
171         DataTypesMode,
172         BasicDataRepresentationsMode,
173         BasicDataMode,
174         SimpleDataTypesMode,
175         SimpleDataMode,
176         EnumeratedDataTypesMode,
177         EnumeratedDataMode,
178         EnumeratorMode,
179         ArrayDataTypesMode,
180         ArrayDataMode,
181         FixedRecordDataTypesMode,
182         FixedRecordDataMode,
183         FieldMode,
184         VariantRecordDataTypesMode,
185         VariantRecordDataMode,
186         AlternativeDataMode
187     };
188
189     Mode getCurrentMode();
190     void pushMode(Mode mode);
191     void popMode();
192
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);
197
198     std::string getAttribute(const char* name, const XMLAttributes& atts);
199     std::string getAttribute(const std::string& name, const XMLAttributes& atts);
200
201     struct BasicData {
202         // std::string _name;
203         std::string _size;
204         std::string _endian;
205     };
206     typedef std::map<std::string, BasicData> BasicDataMap;
207
208     struct SimpleData {
209         // std::string _name;
210         std::string _representation;
211         std::string _units;
212         std::string _resolution;
213         std::string _accuracy;
214     };
215     typedef std::map<std::string, SimpleData> SimpleDataMap;
216
217     struct Enumerator {
218         std::string _name;
219         std::string _values;
220     };
221     typedef std::vector<Enumerator> EnumeratorList;
222
223     struct EnumeratedData {
224         // std::string _name;
225         std::string _representation;
226         EnumeratorList _enumeratorList;
227     };
228     typedef std::map<std::string, EnumeratedData> EnumeratedDataMap;
229
230     struct ArrayData {
231         // std::string _name;
232         std::string _dataType;
233         std::string _cardinality;
234         std::string _encoding;
235     };
236     typedef std::map<std::string, ArrayData> ArrayDataMap;
237
238     struct Field {
239         std::string _name;
240         std::string _dataType;
241     };
242     typedef std::vector<Field> FieldList;
243
244     struct FixedRecordData {
245         // std::string _name;
246         std::string _encoding;
247         FieldList _fieldList;
248     };
249     typedef std::map<std::string, FixedRecordData> FixedRecordDataMap;
250
251     struct Alternative {
252         std::string _name;
253         std::string _dataType;
254         std::string _semantics;
255         std::string _enumerator;
256     };
257     typedef std::vector<Alternative> AlternativeList;
258
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;
266     };
267     typedef std::map<std::string, VariantRecordData> VariantRecordDataMap;
268
269     std::vector<Mode> _modeStack;
270
271     /// The total list of object classes
272     ObjectClassList _objectClassList;
273     ObjectClassList _objectClassStack;
274
275     /// The total list of interaction classes
276     InteractionClassList _interactionClassList;
277     InteractionClassList _interactionClassStack;
278
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;
289 };
290
291 } // namespace simgear
292
293 #endif