]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLABasicDataElement.hxx
Add an initial implementation of a rti/hla dispatcher.
[simgear.git] / simgear / hla / HLABasicDataElement.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 HLABasicDataElement_hxx
19 #define HLABasicDataElement_hxx
20
21 #include "HLABasicDataType.hxx"
22 #include "HLADataElement.hxx"
23
24 namespace simgear {
25
26 class HLABasicDataElement : public HLADataElement {
27 public:
28     HLABasicDataElement(const HLABasicDataType* dataType);
29     virtual ~HLABasicDataElement();
30
31     virtual const HLABasicDataType* getDataType() const;
32     virtual bool setDataType(const HLADataType* dataType);
33     void setDataType(const HLABasicDataType* dataType);
34
35 protected:
36     SGSharedPtr<const HLABasicDataType> _dataType;
37 };
38
39 #define TYPED_HLA_BASIC_DATA_ELEMENT(type, ctype)                             \
40 class HLAAbstract##type##DataElement : public HLABasicDataElement {           \
41 public:                                                                       \
42     HLAAbstract##type##DataElement(const HLABasicDataType* dataType = 0);     \
43     virtual ~HLAAbstract##type##DataElement();                                \
44     virtual bool encode(HLAEncodeStream& stream) const;                       \
45     virtual bool decode(HLADecodeStream& stream);                             \
46                                                                               \
47     virtual ctype getValue() const = 0;                                       \
48     virtual void setValue(ctype) = 0;                                         \
49 };                                                                            \
50 class HLA##type##DataElement : public HLAAbstract##type##DataElement {        \
51 public:                                                                       \
52     HLA##type##DataElement(const HLABasicDataType* dataType = 0);             \
53     HLA##type##DataElement(const HLABasicDataType* dataType,                  \
54                            const ctype& value);                               \
55     virtual ~HLA##type##DataElement();                                        \
56     virtual ctype getValue() const;                                           \
57     virtual void setValue(ctype value);                                       \
58 private:                                                                      \
59     ctype _value;                                                             \
60 };                                                                            \
61 class HLA##type##Data {                                                       \
62 public:                                                                       \
63     HLA##type##Data() :                                                       \
64         _value(new HLA##type##DataElement(0))                                 \
65     { }                                                                       \
66     HLA##type##Data(const ctype& value) :                                     \
67         _value(new HLA##type##DataElement(0, value))                          \
68     { }                                                                       \
69     operator ctype() const                                                    \
70     { return _value->getValue(); }                                            \
71     HLA##type##Data& operator=(const ctype& value)                            \
72     { _value->setValue(value); return *this; }                                \
73     ctype getValue() const                                                    \
74     { return _value->getValue(); }                                            \
75     void setValue(const ctype& value)                                         \
76     { _value->setValue(value); }                                              \
77     const HLA##type##DataElement* getDataElement() const                      \
78     { return _value.get(); }                                                  \
79     HLA##type##DataElement* getDataElement()                                  \
80     { return _value.get(); }                                                  \
81     const HLABasicDataType* getDataType() const                               \
82     { return _value->getDataType(); }                                         \
83     void setDataType(const HLABasicDataType* dataType)                        \
84     { _value->setDataType(dataType); }                                        \
85                                                                               \
86 private:                                                                      \
87     SGSharedPtr<HLA##type##DataElement> _value;                               \
88 };
89
90
91 TYPED_HLA_BASIC_DATA_ELEMENT(Char, char);
92 TYPED_HLA_BASIC_DATA_ELEMENT(WChar, wchar_t);
93 TYPED_HLA_BASIC_DATA_ELEMENT(SChar, signed char);
94 TYPED_HLA_BASIC_DATA_ELEMENT(UChar, unsigned char);
95 TYPED_HLA_BASIC_DATA_ELEMENT(Short, short);
96 TYPED_HLA_BASIC_DATA_ELEMENT(UShort, unsigned short);
97 TYPED_HLA_BASIC_DATA_ELEMENT(Int, int);
98 TYPED_HLA_BASIC_DATA_ELEMENT(UInt, unsigned int);
99 TYPED_HLA_BASIC_DATA_ELEMENT(Long, long);
100 TYPED_HLA_BASIC_DATA_ELEMENT(ULong, unsigned long);
101 TYPED_HLA_BASIC_DATA_ELEMENT(Float, float);
102 TYPED_HLA_BASIC_DATA_ELEMENT(Double, double);
103
104 #undef TYPED_HLA_BASIC_DATA_ELEMENT
105
106 }
107
108 #endif