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.
19 # include <simgear_config.h>
22 #include <simgear/compiler.h>
24 #include "HLABasicDataElement.hxx"
26 #include "HLADataElementVisitor.hxx"
27 #include "HLADataTypeVisitor.hxx"
31 HLABasicDataElement::HLABasicDataElement(const HLABasicDataType* dataType) :
36 HLABasicDataElement::~HLABasicDataElement()
41 HLABasicDataElement::accept(HLADataElementVisitor& visitor)
47 HLABasicDataElement::accept(HLAConstDataElementVisitor& visitor) const
52 const HLABasicDataType*
53 HLABasicDataElement::getDataType() const
55 return _dataType.get();
59 HLABasicDataElement::setDataType(const HLADataType* dataType)
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!");
66 setDataType(scalarDataType);
71 HLABasicDataElement::setDataType(const HLABasicDataType* dataType)
76 #define IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(type, ctype) \
77 HLAAbstract##type##DataElement::HLAAbstract##type##DataElement(const HLABasicDataType* dataType) :\
78 HLABasicDataElement(dataType) \
82 HLAAbstract##type##DataElement::~HLAAbstract##type##DataElement() \
87 HLAAbstract##type##DataElement::encode(HLAEncodeStream& stream) const \
89 if (!_dataType.valid()) \
91 HLATemplateEncodeVisitor<ctype> visitor(stream, getValue()); \
92 _dataType->accept(visitor); \
97 HLAAbstract##type##DataElement::decode(HLADecodeStream& stream) \
99 if (!_dataType.valid()) \
101 HLATemplateDecodeVisitor<ctype> visitor(stream); \
102 _dataType->accept(visitor); \
103 setValue(visitor.getValue()); \
107 HLA##type##DataElement::HLA##type##DataElement(const HLABasicDataType* dataType) : \
108 HLAAbstract##type##DataElement(dataType), \
113 HLA##type##DataElement::HLA##type##DataElement(const HLABasicDataType* dataType, \
114 const ctype& value) : \
115 HLAAbstract##type##DataElement(dataType), \
120 HLA##type##DataElement::~HLA##type##DataElement() \
125 HLA##type##DataElement::getValue() const \
131 HLA##type##DataElement::setValue(ctype value) \
137 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Bool, bool);
138 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Char, char);
139 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(WChar, wchar_t);
140 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(SChar, signed char);
141 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UChar, unsigned char);
142 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Short, short);
143 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UShort, unsigned short);
144 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Int, int);
145 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UInt, unsigned int);
146 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Long, long);
147 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(ULong, unsigned long);
148 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Float, float);
149 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Double, double);
151 #undef IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT