]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLADataTypeVisitor.hxx
Merge branch 'next' of git://gitorious.org/fg/simgear into next
[simgear.git] / simgear / hla / HLADataTypeVisitor.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 HLADataTypeVisitor_hxx
19 #define HLADataTypeVisitor_hxx
20
21 #include <cassert>
22 #include <string>
23 #include <simgear/debug/logstream.hxx>
24 #include <simgear/math/SGMath.hxx>
25 #include "HLAArrayDataType.hxx"
26 #include "HLABasicDataType.hxx"
27 #include "HLADataElement.hxx"
28 #include "HLAEnumeratedDataType.hxx"
29 #include "HLAFixedRecordDataType.hxx"
30 #include "HLAVariantDataType.hxx"
31
32 namespace simgear {
33
34 class HLADataTypeVisitor {
35 public:
36     virtual ~HLADataTypeVisitor() {}
37
38     virtual void apply(const HLADataType& dataType)
39     { }
40
41     virtual void apply(const HLADataTypeReference& dataType)
42     {
43         SGSharedPtr<const HLADataType> dataTypeReference = dataType.getDataType();
44         if (!dataTypeReference.valid()) {
45             SG_LOG(SG_NETWORK, SG_WARN, "HLADataTypeReference weak reference vanished!");
46             return;
47         }
48         dataTypeReference->accept(*this);
49     }
50
51     virtual void apply(const HLABasicDataType& dataType)
52     { apply(static_cast<const HLADataType&>(dataType)); }
53     virtual void apply(const HLAInt8DataType& dataType)
54     { apply(static_cast<const HLABasicDataType&>(dataType)); }
55     virtual void apply(const HLAUInt8DataType& dataType)
56     { apply(static_cast<const HLABasicDataType&>(dataType)); }
57     virtual void apply(const HLAInt16DataType& dataType)
58     { apply(static_cast<const HLABasicDataType&>(dataType)); }
59     virtual void apply(const HLAUInt16DataType& dataType)
60     { apply(static_cast<const HLABasicDataType&>(dataType)); }
61     virtual void apply(const HLAInt32DataType& dataType)
62     { apply(static_cast<const HLABasicDataType&>(dataType)); }
63     virtual void apply(const HLAUInt32DataType& dataType)
64     { apply(static_cast<const HLABasicDataType&>(dataType)); }
65     virtual void apply(const HLAInt64DataType& dataType)
66     { apply(static_cast<const HLABasicDataType&>(dataType)); }
67     virtual void apply(const HLAUInt64DataType& dataType)
68     { apply(static_cast<const HLABasicDataType&>(dataType)); }
69     virtual void apply(const HLAFloat32DataType& dataType)
70     { apply(static_cast<const HLABasicDataType&>(dataType)); }
71     virtual void apply(const HLAFloat64DataType& dataType)
72     { apply(static_cast<const HLABasicDataType&>(dataType)); }
73
74     virtual void apply(const HLAArrayDataType& dataType)
75     { apply(static_cast<const HLADataType&>(dataType)); }
76     virtual void apply(const HLAFixedArrayDataType& dataType)
77     { apply(static_cast<const HLAArrayDataType&>(dataType)); }
78     virtual void apply(const HLAVariableArrayDataType& dataType)
79     { apply(static_cast<const HLAArrayDataType&>(dataType)); }
80
81     virtual void apply(const HLAEnumeratedDataType& dataType)
82     { apply(static_cast<const HLADataType&>(dataType)); }
83
84     virtual void apply(const HLAFixedRecordDataType& dataType)
85     { apply(static_cast<const HLADataType&>(dataType)); }
86
87     virtual void apply(const HLAVariantDataType& dataType)
88     { apply(static_cast<const HLADataType&>(dataType)); }
89 };
90
91 /// Walks the datatype tree and checks if it is completely defined
92 class HLADataTypeCheckVisitor : public HLADataTypeVisitor {
93 public:
94     HLADataTypeCheckVisitor() : _valid(true) {}
95
96     bool valid() const { return _valid; }
97
98     virtual void apply(const HLAInt8DataType& dataType) { }
99     virtual void apply(const HLAUInt8DataType& dataType) { }
100     virtual void apply(const HLAInt16DataType& dataType) { }
101     virtual void apply(const HLAUInt16DataType& dataType) { }
102     virtual void apply(const HLAInt32DataType& dataType) { }
103     virtual void apply(const HLAUInt32DataType& dataType) { }
104     virtual void apply(const HLAInt64DataType& dataType) { }
105     virtual void apply(const HLAUInt64DataType& dataType) { }
106     virtual void apply(const HLAFloat32DataType& dataType) { }
107     virtual void apply(const HLAFloat64DataType& dataType) { }
108
109     virtual void apply(const HLAFixedArrayDataType& dataType)
110     {
111         if (!dataType.getElementDataType())
112             _valid = false;
113         else
114             dataType.getElementDataType()->accept(*this);
115     }
116     virtual void apply(const HLAVariableArrayDataType& dataType)
117     {
118         if (!dataType.getElementDataType())
119             _valid = false;
120         else
121             dataType.getElementDataType()->accept(*this);
122
123         if (!dataType.getSizeDataType())
124             _valid = false;
125         else
126             dataType.getSizeDataType()->accept(*this);
127     }
128
129     virtual void apply(const HLAEnumeratedDataType& dataType)
130     {
131         if (!dataType.getRepresentation())
132             _valid = false;
133         else
134             dataType.getRepresentation()->accept(*this);
135     }
136
137     virtual void apply(const HLAFixedRecordDataType& dataType)
138     {
139         unsigned numFields = dataType.getNumFields();
140         for (unsigned i = 0; i < numFields; ++i) {
141             if (!dataType.getFieldDataType(i))
142                 _valid = false;
143             else
144                 dataType.getFieldDataType(i)->accept(*this);
145         }
146     }
147
148     virtual void apply(const HLAVariantDataType& dataType)
149     { assert(0); }
150
151 protected:
152     bool _valid;
153 };
154
155 class HLADataTypeDecodeVisitor : public HLADataTypeVisitor {
156 public:
157     HLADataTypeDecodeVisitor(HLADecodeStream& stream) : _stream(stream) {}
158     virtual ~HLADataTypeDecodeVisitor() {}
159
160     virtual void apply(const HLAInt8DataType& dataType) { dataType.skip(_stream); }
161     virtual void apply(const HLAUInt8DataType& dataType) { dataType.skip(_stream); }
162     virtual void apply(const HLAInt16DataType& dataType) { dataType.skip(_stream); }
163     virtual void apply(const HLAUInt16DataType& dataType) { dataType.skip(_stream); }
164     virtual void apply(const HLAInt32DataType& dataType) { dataType.skip(_stream); }
165     virtual void apply(const HLAUInt32DataType& dataType) { dataType.skip(_stream); }
166     virtual void apply(const HLAInt64DataType& dataType) { dataType.skip(_stream); }
167     virtual void apply(const HLAUInt64DataType& dataType) { dataType.skip(_stream); }
168     virtual void apply(const HLAFloat32DataType& dataType) { dataType.skip(_stream); }
169     virtual void apply(const HLAFloat64DataType& dataType) { dataType.skip(_stream); }
170
171     virtual void apply(const HLAFixedArrayDataType& dataType)
172     {
173         unsigned numElements = dataType.getNumElements();
174         for (unsigned i = 0; i < numElements; ++i)
175             dataType.getElementDataType()->accept(*this);
176     }
177     virtual void apply(const HLAVariableArrayDataType& dataType);
178
179     virtual void apply(const HLAEnumeratedDataType& dataType)
180     {
181         dataType.getRepresentation()->accept(*this);
182     }
183
184     virtual void apply(const HLAFixedRecordDataType& dataType)
185     {
186         unsigned numFields = dataType.getNumFields();
187         for (unsigned i = 0; i < numFields; ++i)
188             dataType.getFieldDataType(i)->accept(*this);
189     }
190
191     virtual void apply(const HLAVariantDataType& dataType) { assert(0); }
192
193 protected:
194     HLADecodeStream& _stream;
195 };
196
197 class HLADataTypeEncodeVisitor : public HLADataTypeVisitor {
198 public:
199     HLADataTypeEncodeVisitor(HLAEncodeStream& stream) : _stream(stream) {}
200     virtual ~HLADataTypeEncodeVisitor() {}
201
202     virtual void apply(const HLAInt8DataType& dataType) { dataType.skip(_stream); }
203     virtual void apply(const HLAUInt8DataType& dataType) { dataType.skip(_stream); }
204     virtual void apply(const HLAInt16DataType& dataType) { dataType.skip(_stream); }
205     virtual void apply(const HLAUInt16DataType& dataType) { dataType.skip(_stream); }
206     virtual void apply(const HLAInt32DataType& dataType) { dataType.skip(_stream); }
207     virtual void apply(const HLAUInt32DataType& dataType) { dataType.skip(_stream); }
208     virtual void apply(const HLAInt64DataType& dataType) { dataType.skip(_stream); }
209     virtual void apply(const HLAUInt64DataType& dataType) { dataType.skip(_stream); }
210     virtual void apply(const HLAFloat32DataType& dataType) { dataType.skip(_stream); }
211     virtual void apply(const HLAFloat64DataType& dataType) { dataType.skip(_stream); }
212
213     virtual void apply(const HLAFixedArrayDataType& dataType)
214     {
215         /// FIXME, might vanish in this sense ...
216         // dataType.encode(_stream, *this);
217         unsigned numElements = dataType.getNumElements();
218         for (unsigned i = 0; i < numElements; ++i)
219             dataType.getElementDataType()->accept(*this);
220     }
221     virtual void apply(const HLAVariableArrayDataType& dataType);
222
223     virtual void apply(const HLAEnumeratedDataType& dataType)
224     {
225         dataType.getRepresentation()->accept(*this);
226     }
227
228     virtual void apply(const HLAFixedRecordDataType& dataType)
229     {
230         unsigned numFields = dataType.getNumFields();
231         for (unsigned i = 0; i < numFields; ++i)
232             dataType.getFieldDataType(i)->accept(*this);
233     }
234
235     virtual void apply(const HLAVariantDataType& dataType) { assert(0); }
236
237 protected:
238     HLAEncodeStream& _stream;
239 };
240
241 /// Begin implementation of some get/set visitors
242
243 class HLAScalarDecodeVisitor : public HLADataTypeDecodeVisitor {
244 public:
245     HLAScalarDecodeVisitor(HLADecodeStream& stream) :
246         HLADataTypeDecodeVisitor(stream)
247     {}
248
249     virtual void apply(const HLAFixedArrayDataType& dataType)
250     {
251         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing scalar value");
252         HLADataTypeDecodeVisitor::apply(dataType);
253     }
254     virtual void apply(const HLAVariableArrayDataType& dataType)
255     {
256         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing scalar value");
257         HLADataTypeDecodeVisitor::apply(dataType);
258     }
259
260     virtual void apply(const HLAEnumeratedDataType& dataType)
261     {
262         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing scalar value");
263         HLADataTypeDecodeVisitor::apply(dataType);
264     }
265
266     virtual void apply(const HLAFixedRecordDataType& dataType)
267     {
268         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing scalar value");
269         HLADataTypeDecodeVisitor::apply(dataType);
270     }
271
272     virtual void apply(const HLAVariantDataType& dataType)
273     {
274         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing scalar value");
275         HLADataTypeDecodeVisitor::apply(dataType);
276     }
277 };
278
279 class HLAScalarEncodeVisitor : public HLADataTypeEncodeVisitor {
280 public:
281     HLAScalarEncodeVisitor(HLAEncodeStream& stream) :
282         HLADataTypeEncodeVisitor(stream)
283     {}
284
285     virtual void apply(const HLAFixedArrayDataType& dataType)
286     {
287         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing scalar value");
288         HLADataTypeEncodeVisitor::apply(dataType);
289     }
290     virtual void apply(const HLAVariableArrayDataType& dataType)
291     {
292         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing scalar value");
293         HLADataTypeEncodeVisitor::apply(dataType);
294     }
295
296     virtual void apply(const HLAEnumeratedDataType& dataType)
297     {
298         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing scalar value");
299         HLADataTypeEncodeVisitor::apply(dataType);
300     }
301
302     virtual void apply(const HLAFixedRecordDataType& dataType)
303     {
304         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing scalar value");
305         HLADataTypeEncodeVisitor::apply(dataType);
306     }
307
308     virtual void apply(const HLAVariantDataType& dataType)
309     {
310         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing scalar value");
311         HLADataTypeEncodeVisitor::apply(dataType);
312     }
313 };
314
315 class HLAFixedRecordDecodeVisitor : public HLADataTypeDecodeVisitor {
316 public:
317     HLAFixedRecordDecodeVisitor(HLADecodeStream& stream) :
318         HLADataTypeDecodeVisitor(stream)
319     { }
320
321     virtual void apply(const HLAInt8DataType& dataType)
322     {
323         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
324         HLADataTypeDecodeVisitor::apply(dataType);
325     }
326     virtual void apply(const HLAUInt8DataType& dataType)
327     {
328         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
329         HLADataTypeDecodeVisitor::apply(dataType);
330     }
331     virtual void apply(const HLAInt16DataType& dataType)
332     {
333         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
334         HLADataTypeDecodeVisitor::apply(dataType);
335     }
336     virtual void apply(const HLAUInt16DataType& dataType)
337     {
338         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
339         HLADataTypeDecodeVisitor::apply(dataType);
340     }
341     virtual void apply(const HLAInt32DataType& dataType)
342     {
343         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
344         HLADataTypeDecodeVisitor::apply(dataType);
345     }
346     virtual void apply(const HLAUInt32DataType& dataType)
347     {
348         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
349         HLADataTypeDecodeVisitor::apply(dataType);
350     }
351     virtual void apply(const HLAInt64DataType& dataType)
352     {
353         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
354         HLADataTypeDecodeVisitor::apply(dataType);
355     }
356     virtual void apply(const HLAUInt64DataType& dataType)
357     {
358         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
359         HLADataTypeDecodeVisitor::apply(dataType);
360     }
361     virtual void apply(const HLAFloat32DataType& dataType)
362     {
363         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
364         HLADataTypeDecodeVisitor::apply(dataType);
365     }
366     virtual void apply(const HLAFloat64DataType& dataType)
367     {
368         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
369         HLADataTypeDecodeVisitor::apply(dataType);
370     }
371
372     virtual void apply(const HLAFixedArrayDataType& dataType)
373     {
374         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
375         HLADataTypeDecodeVisitor::apply(dataType);
376     }
377     virtual void apply(const HLAVariableArrayDataType& dataType)
378     {
379         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
380         HLADataTypeDecodeVisitor::apply(dataType);
381     }
382
383     virtual void apply(const HLAEnumeratedDataType& dataType)
384     {
385         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
386         HLADataTypeDecodeVisitor::apply(dataType);
387     }
388
389     virtual void apply(const HLAVariantDataType& dataType)
390     {
391         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while decodeing a fixed record value");
392         HLADataTypeDecodeVisitor::apply(dataType);
393     }
394 };
395
396 class HLAFixedRecordEncodeVisitor : public HLADataTypeEncodeVisitor {
397 public:
398     HLAFixedRecordEncodeVisitor(HLAEncodeStream& stream) :
399         HLADataTypeEncodeVisitor(stream)
400     { }
401
402     virtual void apply(const HLAInt8DataType& dataType)
403     {
404         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
405         HLADataTypeEncodeVisitor::apply(dataType);
406     }
407     virtual void apply(const HLAUInt8DataType& dataType)
408     {
409         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
410         HLADataTypeEncodeVisitor::apply(dataType);
411     }
412     virtual void apply(const HLAInt16DataType& dataType)
413     {
414         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
415         HLADataTypeEncodeVisitor::apply(dataType);
416     }
417     virtual void apply(const HLAUInt16DataType& dataType)
418     {
419         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
420         HLADataTypeEncodeVisitor::apply(dataType);
421     }
422     virtual void apply(const HLAInt32DataType& dataType)
423     {
424         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
425         HLADataTypeEncodeVisitor::apply(dataType);
426     }
427     virtual void apply(const HLAUInt32DataType& dataType)
428     {
429         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
430         HLADataTypeEncodeVisitor::apply(dataType);
431     }
432     virtual void apply(const HLAInt64DataType& dataType)
433     {
434         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
435         HLADataTypeEncodeVisitor::apply(dataType);
436     }
437     virtual void apply(const HLAUInt64DataType& dataType)
438     {
439         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
440         HLADataTypeEncodeVisitor::apply(dataType);
441     }
442     virtual void apply(const HLAFloat32DataType& dataType)
443     {
444         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
445         HLADataTypeEncodeVisitor::apply(dataType);
446     }
447     virtual void apply(const HLAFloat64DataType& dataType)
448     {
449         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
450         HLADataTypeEncodeVisitor::apply(dataType);
451     }
452
453     virtual void apply(const HLAFixedArrayDataType& dataType)
454     {
455         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
456         HLADataTypeEncodeVisitor::apply(dataType);
457     }
458     virtual void apply(const HLAVariableArrayDataType& dataType)
459     {
460         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
461         HLADataTypeEncodeVisitor::apply(dataType);
462     }
463
464     virtual void apply(const HLAEnumeratedDataType& dataType)
465     {
466         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
467         HLADataTypeEncodeVisitor::apply(dataType);
468     }
469
470     virtual void apply(const HLAVariantDataType& dataType)
471     {
472         SG_LOG(SG_NETWORK, SG_WARN, "Unexpected HLADataType while writing a fixed record value");
473         HLADataTypeEncodeVisitor::apply(dataType);
474     }
475 };
476
477 template<typename T>
478 class HLATemplateDecodeVisitor : public HLAScalarDecodeVisitor {
479 public:
480     typedef T value_type;
481
482     HLATemplateDecodeVisitor(HLADecodeStream& stream, const value_type& value = value_type()) :
483         HLAScalarDecodeVisitor(stream),
484         _value(value)
485     {}
486
487     void setValue(const value_type& value)
488     { _value = value; }
489     const value_type& getValue() const
490     { return _value; }
491
492     virtual void apply(const HLAInt8DataType& dataType)
493     {
494         int8_t value = 0;
495         dataType.decode(_stream, value);
496         _value = value_type(value);
497     }
498     virtual void apply(const HLAUInt8DataType& dataType)
499     {
500         uint8_t value = 0;
501         dataType.decode(_stream, value);
502         _value = value_type(value);
503     }
504     virtual void apply(const HLAInt16DataType& dataType)
505     {
506         int16_t value = 0;
507         dataType.decode(_stream, value);
508         _value = value_type(value);
509     }
510     virtual void apply(const HLAUInt16DataType& dataType)
511     {
512         uint16_t value = 0;
513         dataType.decode(_stream, value);
514         _value = value_type(value);
515     }
516     virtual void apply(const HLAInt32DataType& dataType)
517     {
518         int32_t value = 0;
519         dataType.decode(_stream, value);
520         _value = value_type(value);
521     }
522     virtual void apply(const HLAUInt32DataType& dataType)
523     {
524         uint32_t value = 0;
525         dataType.decode(_stream, value);
526         _value = value_type(value);
527     }
528     virtual void apply(const HLAInt64DataType& dataType)
529     {
530         int64_t value = 0;
531         dataType.decode(_stream, value);
532         _value = value_type(value);
533     }
534     virtual void apply(const HLAUInt64DataType& dataType)
535     {
536         uint64_t value = 0;
537         dataType.decode(_stream, value);
538         _value = value_type(value);
539     }
540     virtual void apply(const HLAFloat32DataType& dataType)
541     {
542         float value = 0;
543         dataType.decode(_stream, value);
544         _value = value_type(value);
545     }
546     virtual void apply(const HLAFloat64DataType& dataType)
547     {
548         double value = 0;
549         dataType.decode(_stream, value);
550         _value = value_type(value);
551     }
552
553 private:
554     value_type _value;
555 };
556
557 template<typename T>
558 class HLATemplateEncodeVisitor : public HLAScalarEncodeVisitor {
559 public:
560     typedef T value_type;
561
562     HLATemplateEncodeVisitor(HLAEncodeStream& stream, const value_type& value = value_type()) :
563         HLAScalarEncodeVisitor(stream),
564         _value(value)
565     {}
566
567     void setValue(const value_type& value)
568     { _value = value; }
569     const value_type& getValue() const
570     { return _value; }
571
572     virtual void apply(const HLAInt8DataType& dataType)
573     {
574         dataType.encode(_stream, _value);
575     }
576     virtual void apply(const HLAUInt8DataType& dataType)
577     {
578         dataType.encode(_stream, _value);
579     }
580     virtual void apply(const HLAInt16DataType& dataType)
581     {
582         dataType.encode(_stream, _value);
583     }
584     virtual void apply(const HLAUInt16DataType& dataType)
585     {
586         dataType.encode(_stream, _value);
587     }
588     virtual void apply(const HLAInt32DataType& dataType)
589     {
590         dataType.encode(_stream, _value);
591     }
592     virtual void apply(const HLAUInt32DataType& dataType)
593     {
594         dataType.encode(_stream, _value);
595     }
596     virtual void apply(const HLAInt64DataType& dataType)
597     {
598         dataType.encode(_stream, _value);
599     }
600     virtual void apply(const HLAUInt64DataType& dataType)
601     {
602         dataType.encode(_stream, _value);
603     }
604     virtual void apply(const HLAFloat32DataType& dataType)
605     {
606         dataType.encode(_stream, _value);
607     }
608     virtual void apply(const HLAFloat64DataType& dataType)
609     {
610         dataType.encode(_stream, _value);
611     }
612
613 private:
614     value_type _value;
615 };
616
617 inline void HLADataTypeDecodeVisitor::apply(const HLAVariableArrayDataType& dataType)
618 {
619     HLATemplateDecodeVisitor<unsigned> numElementsVisitor(_stream);
620     dataType.getSizeDataType()->accept(numElementsVisitor);
621     unsigned numElements = numElementsVisitor.getValue();
622     for (unsigned i = 0; i < numElements; ++i)
623         dataType.getElementDataType()->accept(*this);
624 }
625
626 inline void HLADataTypeEncodeVisitor::apply(const HLAVariableArrayDataType& dataType)
627 {
628     HLATemplateEncodeVisitor<unsigned> numElementsVisitor(_stream, 0);
629     dataType.getSizeDataType()->accept(numElementsVisitor);
630 }
631
632 /// Generate standard data elements according to the traversed type
633 class HLADataElementFactoryVisitor : public HLADataTypeVisitor {
634 public:
635     virtual ~HLADataElementFactoryVisitor();
636
637     virtual void apply(const HLADataType& dataType);
638
639     virtual void apply(const HLAInt8DataType& dataType);
640     virtual void apply(const HLAUInt8DataType& dataType);
641     virtual void apply(const HLAInt16DataType& dataType);
642     virtual void apply(const HLAUInt16DataType& dataType);
643     virtual void apply(const HLAInt32DataType& dataType);
644     virtual void apply(const HLAUInt32DataType& dataType);
645     virtual void apply(const HLAInt64DataType& dataType);
646     virtual void apply(const HLAUInt64DataType& dataType);
647     virtual void apply(const HLAFloat32DataType& dataType);
648     virtual void apply(const HLAFloat64DataType& dataType);
649
650     virtual void apply(const HLAFixedArrayDataType& dataType);
651     virtual void apply(const HLAVariableArrayDataType& dataType);
652
653     virtual void apply(const HLAEnumeratedDataType& dataType);
654
655     virtual void apply(const HLAFixedRecordDataType& dataType);
656
657     virtual void apply(const HLAVariantDataType& dataType);
658
659     HLADataElement* getDataElement()
660     { return _dataElement.release(); }
661
662 protected:
663     class ArrayDataElementFactory;
664     class VariantDataElementFactory;
665
666     SGSharedPtr<HLADataElement> _dataElement;
667 };
668
669 } // namespace simgear
670
671 #endif