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 #ifndef HLABasicDataElement_hxx
19 #define HLABasicDataElement_hxx
21 #include "HLABasicDataType.hxx"
22 #include "HLADataElement.hxx"
26 class HLABasicDataElement : public HLADataElement {
28 HLABasicDataElement(const HLABasicDataType* dataType);
29 virtual ~HLABasicDataElement();
31 virtual void accept(HLADataElementVisitor& visitor);
32 virtual void accept(HLAConstDataElementVisitor& visitor) const;
34 virtual bool encode(HLAEncodeStream& stream) const = 0;
35 virtual bool decode(HLADecodeStream& stream) = 0;
37 virtual const HLABasicDataType* getDataType() const;
38 virtual bool setDataType(const HLADataType* dataType);
39 void setDataType(const HLABasicDataType* dataType);
42 SGSharedPtr<const HLABasicDataType> _dataType;
45 #define TYPED_HLA_BASIC_DATA_ELEMENT(type, ctype) \
46 class HLAAbstract##type##DataElement : public HLABasicDataElement { \
48 HLAAbstract##type##DataElement(const HLABasicDataType* dataType = 0); \
49 virtual ~HLAAbstract##type##DataElement(); \
51 virtual bool encode(HLAEncodeStream& stream) const; \
52 virtual bool decode(HLADecodeStream& stream); \
54 virtual ctype getValue() const = 0; \
55 virtual void setValue(ctype) = 0; \
57 class HLA##type##DataElement : public HLAAbstract##type##DataElement { \
59 HLA##type##DataElement(const HLABasicDataType* dataType = 0); \
60 HLA##type##DataElement(const HLABasicDataType* dataType, \
61 const ctype& value); \
62 virtual ~HLA##type##DataElement(); \
63 virtual ctype getValue() const; \
64 virtual void setValue(ctype value); \
68 class HLA##type##Data { \
71 _value(new HLA##type##DataElement(0)) \
73 HLA##type##Data(const ctype& value) : \
74 _value(new HLA##type##DataElement(0, value)) \
76 operator ctype() const \
77 { return _value->getValue(); } \
78 HLA##type##Data& operator=(const ctype& value) \
79 { _value->setValue(value); return *this; } \
80 ctype getValue() const \
81 { return _value->getValue(); } \
82 void setValue(const ctype& value) \
83 { _value->setValue(value); } \
84 const HLA##type##DataElement* getDataElement() const \
85 { return _value.get(); } \
86 HLA##type##DataElement* getDataElement() \
87 { return _value.get(); } \
88 const HLABasicDataType* getDataType() const \
89 { return _value->getDataType(); } \
90 void setDataType(const HLABasicDataType* dataType) \
91 { _value->setDataType(dataType); } \
94 SGSharedPtr<HLA##type##DataElement> _value; \
98 TYPED_HLA_BASIC_DATA_ELEMENT(Bool, bool);
99 TYPED_HLA_BASIC_DATA_ELEMENT(Char, char);
100 TYPED_HLA_BASIC_DATA_ELEMENT(WChar, wchar_t);
101 TYPED_HLA_BASIC_DATA_ELEMENT(SChar, signed char);
102 TYPED_HLA_BASIC_DATA_ELEMENT(UChar, unsigned char);
103 TYPED_HLA_BASIC_DATA_ELEMENT(Short, short);
104 TYPED_HLA_BASIC_DATA_ELEMENT(UShort, unsigned short);
105 TYPED_HLA_BASIC_DATA_ELEMENT(Int, int);
106 TYPED_HLA_BASIC_DATA_ELEMENT(UInt, unsigned int);
107 TYPED_HLA_BASIC_DATA_ELEMENT(Long, long);
108 TYPED_HLA_BASIC_DATA_ELEMENT(ULong, unsigned long);
109 TYPED_HLA_BASIC_DATA_ELEMENT(Float, float);
110 TYPED_HLA_BASIC_DATA_ELEMENT(Double, double);
112 #undef TYPED_HLA_BASIC_DATA_ELEMENT