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.
18 #include "HLABasicDataElement.hxx"
20 #include "HLADataTypeVisitor.hxx"
24 HLABasicDataElement::HLABasicDataElement(const HLABasicDataType* dataType) :
29 HLABasicDataElement::~HLABasicDataElement()
33 const HLABasicDataType*
34 HLABasicDataElement::getDataType() const
36 return _dataType.get();
40 HLABasicDataElement::setDataType(const HLADataType* dataType)
42 const HLABasicDataType* scalarDataType = dynamic_cast<const HLABasicDataType*>(dataType);
43 if (!scalarDataType) {
44 SG_LOG(SG_NETWORK, SG_WARN, "HLABasicDataType: unable to set data type!");
47 setDataType(scalarDataType);
52 HLABasicDataElement::setDataType(const HLABasicDataType* dataType)
57 #define IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(type, ctype) \
58 HLAAbstract##type##DataElement::HLAAbstract##type##DataElement(const HLABasicDataType* dataType) :\
59 HLABasicDataElement(dataType) \
63 HLAAbstract##type##DataElement::~HLAAbstract##type##DataElement() \
68 HLAAbstract##type##DataElement::encode(HLAEncodeStream& stream) const \
70 if (!_dataType.valid()) \
72 HLATemplateEncodeVisitor<ctype> visitor(stream, getValue()); \
73 _dataType->accept(visitor); \
78 HLAAbstract##type##DataElement::decode(HLADecodeStream& stream) \
80 if (!_dataType.valid()) \
82 HLATemplateDecodeVisitor<ctype> visitor(stream); \
83 _dataType->accept(visitor); \
84 setValue(visitor.getValue()); \
88 HLA##type##DataElement::HLA##type##DataElement(const HLABasicDataType* dataType) : \
89 HLAAbstract##type##DataElement(dataType), \
94 HLA##type##DataElement::HLA##type##DataElement(const HLABasicDataType* dataType, \
95 const ctype& value) : \
96 HLAAbstract##type##DataElement(dataType), \
101 HLA##type##DataElement::~HLA##type##DataElement() \
106 HLA##type##DataElement::getValue() const \
112 HLA##type##DataElement::setValue(ctype value) \
117 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Char, char);
118 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(WChar, wchar_t);
119 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(SChar, signed char);
120 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UChar, unsigned char);
121 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Short, short);
122 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UShort, unsigned short);
123 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Int, int);
124 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(UInt, unsigned int);
125 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Long, long);
126 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(ULong, unsigned long);
127 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Float, float);
128 IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT(Double, double);
130 #undef IMPLEMENT_TYPED_HLA_BASIC_DATA_ELEMENT