]> git.mxchange.org Git - simgear.git/blob - simgear/hla/HLABasicDataElement.cxx
hla: Remove deprecated methods from HLAObjectClass
[simgear.git] / simgear / hla / HLABasicDataElement.cxx
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 #ifdef HAVE_CONFIG_H
19 #  include <simgear_config.h>
20 #endif
21
22 #include <simgear/compiler.h>
23
24 #include "HLABasicDataElement.hxx"
25
26 #include "HLADataElementVisitor.hxx"
27 #include "HLADataTypeVisitor.hxx"
28
29 namespace simgear {
30
31 HLABasicDataElement::HLABasicDataElement(const HLABasicDataType* dataType) :
32     _dataType(dataType)
33 {
34 }
35
36 HLABasicDataElement::~HLABasicDataElement()
37 {
38 }
39
40 void
41 HLABasicDataElement::accept(HLADataElementVisitor& visitor)
42 {
43     visitor.apply(*this);
44 }
45
46 void
47 HLABasicDataElement::accept(HLAConstDataElementVisitor& visitor) const
48 {
49     visitor.apply(*this);
50 }
51
52 const HLABasicDataType*
53 HLABasicDataElement::getDataType() const
54 {
55     return _dataType.get();
56 }
57
58 bool
59 HLABasicDataElement::setDataType(const HLADataType* dataType)
60 {
61     const HLABasicDataType* scalarDataType = dynamic_cast<const HLABasicDataType*>(dataType);
62     if (!scalarDataType) {
63         SG_LOG(SG_NETWORK, SG_WARN, "HLABasicDataType: unable to set data type!");
64         return false;
65     }
66     setDataType(scalarDataType);
67     return true;
68 }
69
70 void
71 HLABasicDataElement::setDataType(const HLABasicDataType* dataType)
72 {
73     _dataType = dataType;
74 }
75
76 #define IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(type, ctype)                                       \
77 HLAAbstract##type##DataElement::HLAAbstract##type##DataElement(const HLABasicDataType* dataType) :\
78     HLABasicDataElement(dataType)                                                                 \
79 {                                                                                                 \
80 }                                                                                                 \
81                                                                                                   \
82 HLAAbstract##type##DataElement::~HLAAbstract##type##DataElement()                                 \
83 {                                                                                                 \
84 }                                                                                                 \
85                                                                                                   \
86 bool                                                                                              \
87 HLAAbstract##type##DataElement::encode(HLAEncodeStream& stream) const                             \
88 {                                                                                                 \
89     if (!_dataType.valid())                                                                       \
90         return false;                                                                             \
91     HLATemplateEncodeVisitor<ctype> visitor(stream, getValue());                                  \
92     _dataType->accept(visitor);                                                                   \
93     return true;                                                                                  \
94 }                                                                                                 \
95                                                                                                   \
96 bool                                                                                              \
97 HLAAbstract##type##DataElement::decode(HLADecodeStream& stream)                                   \
98 {                                                                                                 \
99     if (!_dataType.valid())                                                                       \
100         return false;                                                                             \
101     HLATemplateDecodeVisitor<ctype> visitor(stream);                                              \
102     _dataType->accept(visitor);                                                                   \
103     setValue(visitor.getValue());                                                                 \
104     return true;                                                                                  \
105 }                                                                                                 \
106                                                                                                   \
107 HLA##type##DataElement::HLA##type##DataElement(const HLABasicDataType* dataType) :                \
108     HLAAbstract##type##DataElement(dataType),                                                     \
109     _value(0)                                                                                     \
110 {                                                                                                 \
111 }                                                                                                 \
112                                                                                                   \
113 HLA##type##DataElement::HLA##type##DataElement(const HLABasicDataType* dataType,                  \
114                                                const ctype& value) :                              \
115     HLAAbstract##type##DataElement(dataType),                                                     \
116     _value(value)                                                                                 \
117 {                                                                                                 \
118 }                                                                                                 \
119                                                                                                   \
120 HLA##type##DataElement::~HLA##type##DataElement()                                                 \
121 {                                                                                                 \
122 }                                                                                                 \
123                                                                                                   \
124 ctype                                                                                             \
125 HLA##type##DataElement::getValue() const                                                          \
126 {                                                                                                 \
127     return _value;                                                                                \
128 }                                                                                                 \
129                                                                                                   \
130 void                                                                                              \
131 HLA##type##DataElement::setValue(ctype value)                                                     \
132 {                                                                                                 \
133     _value = value;                                                                               \
134     setDirty(true);                                                                               \
135 }
136
137 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Char, char);
138 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(WChar, wchar_t);
139 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(SChar, signed char);
140 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UChar, unsigned char);
141 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Short, short);
142 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UShort, unsigned short);
143 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Int, int);
144 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UInt, unsigned int);
145 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Long, long);
146 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(ULong, unsigned long);
147 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Float, float);
148 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Double, double);
149
150 #undef IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT
151
152 }