1 // Copyright (C) 2009 - 2012 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 HLABasicDataType_hxx
19 #define HLABasicDataType_hxx
22 #include "HLADataType.hxx"
26 class HLABasicDataType : public HLADataType {
28 virtual ~HLABasicDataType();
29 virtual void accept(HLADataTypeVisitor& visitor) const;
31 virtual const HLABasicDataType* toBasicDataType() const;
34 HLABasicDataType(const std::string& name);
37 class HLAInt8DataType : public HLABasicDataType {
39 HLAInt8DataType(const std::string& name = "HLAInt8DataType");
40 virtual ~HLAInt8DataType();
42 virtual void accept(HLADataTypeVisitor& visitor) const;
44 bool skip(HLADecodeStream& stream) const
46 if (!stream.alignOffsetForSize(getAlignment()))
48 return stream.skip(1);
50 bool skip(HLAEncodeStream& stream) const
52 if (!stream.alignOffsetForSize(getAlignment()))
54 return stream.skip(1);
56 bool decode(HLADecodeStream& stream, int8_t& value) const
58 if (!stream.alignOffsetForSize(getAlignment()))
60 return stream.decodeInt8(value);
62 bool encode(HLAEncodeStream& stream, const int8_t& value) const
64 if (!stream.alignOffsetForSize(getAlignment()))
66 return stream.encodeInt8(value);
70 class HLAUInt8DataType : public HLABasicDataType {
72 HLAUInt8DataType(const std::string& name = "HLAUInt8DataType");
73 virtual ~HLAUInt8DataType();
75 virtual void accept(HLADataTypeVisitor& visitor) const;
77 bool skip(HLADecodeStream& stream) const
79 if (!stream.alignOffsetForSize(getAlignment()))
81 return stream.skip(1);
83 bool skip(HLAEncodeStream& stream) const
85 if (!stream.alignOffsetForSize(getAlignment()))
87 return stream.skip(1);
89 bool decode(HLADecodeStream& stream, uint8_t& value) const
91 if (!stream.alignOffsetForSize(getAlignment()))
93 return stream.decodeUInt8(value);
95 bool encode(HLAEncodeStream& stream, const uint8_t& value) const
97 if (!stream.alignOffsetForSize(getAlignment()))
99 return stream.encodeUInt8(value);
103 #define BASIC_DATATYPE_IMPLEMENTATION(type, name) \
104 class HLA##name##DataType : public HLABasicDataType { \
106 virtual ~HLA##name##DataType(); \
108 virtual void accept(HLADataTypeVisitor& visitor) const; \
110 bool skip(HLADecodeStream& stream) const \
112 if (!stream.alignOffsetForSize(getAlignment())) \
114 return stream.skip(sizeof(type)); \
116 bool skip(HLAEncodeStream& stream) const \
118 if (!stream.alignOffsetForSize(getAlignment())) \
120 return stream.skip(sizeof(type)); \
122 virtual bool decode(HLADecodeStream& stream, type& value) const = 0; \
123 virtual bool encode(HLAEncodeStream& stream, const type& value) const = 0;\
125 HLA##name##DataType(const std::string& name); \
127 class HLA##name##LEDataType : public HLA##name##DataType { \
129 HLA##name##LEDataType(const std::string& name = "HLA" #name "LEDataType");\
130 virtual ~HLA##name##LEDataType(); \
131 virtual bool decode(HLADecodeStream& stream, type& value) const; \
132 virtual bool encode(HLAEncodeStream& stream, const type& value) const; \
134 class HLA##name##BEDataType : public HLA##name##DataType { \
136 HLA##name##BEDataType(const std::string& name = "HLA" #name "BEDataType");\
137 virtual ~HLA##name##BEDataType(); \
138 virtual bool decode(HLADecodeStream& stream, type& value) const; \
139 virtual bool encode(HLAEncodeStream& stream, const type& value) const; \
142 BASIC_DATATYPE_IMPLEMENTATION(int16_t, Int16)
143 BASIC_DATATYPE_IMPLEMENTATION(uint16_t, UInt16)
144 BASIC_DATATYPE_IMPLEMENTATION(int32_t, Int32)
145 BASIC_DATATYPE_IMPLEMENTATION(uint32_t, UInt32)
146 BASIC_DATATYPE_IMPLEMENTATION(int64_t, Int64)
147 BASIC_DATATYPE_IMPLEMENTATION(uint64_t, UInt64)
148 BASIC_DATATYPE_IMPLEMENTATION(float, Float32)
149 BASIC_DATATYPE_IMPLEMENTATION(double, Float64)
151 #undef BASIC_DATATYPE_IMPLEMENTATION
153 } // namespace simgear