Dev Essential
Loading...
Searching...
No Matches
dd_predefined_datatypes.h
Go to the documentation of this file.
1
14
15#ifndef DD_PREDEFINED_DATATYPES_H_INCLUDED
16#define DD_PREDEFINED_DATATYPES_H_INCLUDED
17
22
23#include <limits>
24#include <memory>
25#include <string>
26#include <type_traits>
27#include <unordered_map>
28#include <vector>
29
30namespace ddl {
31
37template <typename T>
39public:
43 DataType(const std::string&)
44 {
45 static_assert(std::is_arithmetic<T>::value,
46 "To use this type, only primitive types are allowed");
47 }
48
53 {
54 static_assert(std::is_arithmetic<T>::value,
55 "To use this type, only primitive types are allowed");
56 }
57};
58
59} // namespace ddl
60
61#if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
62#pragma GCC diagnostic push
63#pragma GCC diagnostic ignored "-Wattributes"
64#endif // defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
65
71#define DDL_DATA_TYPE_INT(type, default_name) \
72 namespace ddl { \
73 template <> \
74 class DataType<type> : public dd::datamodel::DataType { \
75 public: \
76 DataType(const std::string& name) \
77 : dd::datamodel::DataType(name, \
78 sizeof(type) * 8, \
79 std::string("Predefined DataType for ") + name, \
80 1, \
81 "", \
82 std::to_string((std::numeric_limits<type>::min)()), \
83 std::to_string((std::numeric_limits<type>::max)()), \
84 alignof(type)) \
85 { \
86 } \
87 DataType() : DataType(default_name) \
88 { \
89 } \
90 }; \
91 } /* namespace ddl */ \
92 static_assert(true, "Simply to make sure a closing semicolon ';' is used for the macro")
93
95DDL_DATA_TYPE_INT(uint8_t, "tUInt8");
96DDL_DATA_TYPE_INT(uint16_t, "tUInt16");
97DDL_DATA_TYPE_INT(uint32_t, "tUInt32");
98DDL_DATA_TYPE_INT(uint64_t, "tUInt64");
99
100DDL_DATA_TYPE_INT(int8_t, "tInt8");
101DDL_DATA_TYPE_INT(int16_t, "tInt16");
102DDL_DATA_TYPE_INT(int32_t, "tInt32");
103DDL_DATA_TYPE_INT(int64_t, "tInt64");
105
106namespace ddl {
107
113template <>
114class DataType<bool> : public dd::datamodel::DataType {
115public:
121 DataType(const std::string& name)
122 : dd::datamodel::DataType(name,
123 sizeof(bool) * 8,
124 std::string("Predefined DataType for ") + name,
125 1,
126 {},
127 {},
128 {},
129 alignof(bool))
130 {
131 }
132
136 DataType() : DataType("tBool")
137 {
138 }
139};
140
146template <>
147class DataType<char> : public dd::datamodel::DataType {
148public:
154 DataType(const std::string& name)
155 : dd::datamodel::DataType(name,
156 sizeof(char) * 8,
157 std::string("Predefined DataType for ") + name,
158 1,
159 {},
160 {},
161 {},
162 alignof(char))
163 {
164 }
165
169 DataType() : DataType("tChar")
170 {
171 }
172};
173
179template <>
180class DataType<float> : public dd::datamodel::DataType {
181public:
187 DataType(const std::string& name)
188 : dd::datamodel::DataType(name,
189 sizeof(float) * 8,
190 std::string("Predefined DataType for ") + name,
191 1,
192 {},
193 {},
194 {},
195 alignof(float))
196 {
197 }
198
202 DataType() : DataType("tFloat32")
203 {
204 }
205};
206
212template <>
213class DataType<double> : public dd::datamodel::DataType {
214public:
220 DataType(const std::string& name)
221 : dd::datamodel::DataType(name,
222 sizeof(double) * 8,
223 std::string("Predefined DataType for ") + name,
224 1,
225 {},
226 {},
227 {},
228 alignof(double))
229 {
230 }
231
235 DataType() : DataType("tFloat64")
236 {
237 }
238};
239
271class PredefinedDataTypes {
272private:
277 PredefinedDataTypes();
282 ~PredefinedDataTypes();
283
284public:
290 static const PredefinedDataTypes& getInstance();
297 std::shared_ptr<dd::datamodel::DataType> getPredefinedType(const std::string& name) const;
304 dd::OptionalSize getDefaultAlignment(const std::string& name) const;
311 std::vector<std::string> getAliasTypes(const std::string& name) const;
317 std::vector<std::shared_ptr<dd::datamodel::DataType>> getPredefinedTypes() const;
318
319private:
320 struct PredefInfo {
321 std::shared_ptr<dd::datamodel::DataType> _type;
322 std::vector<std::string> _aliases;
323 };
324 const std::unordered_map<std::string, PredefInfo> _defined_types;
325};
326
327} // namespace ddl
328
329#if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
330#pragma GCC diagnostic pop
331#endif // defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
332
333#endif // DD_PREDEFINED_DATATYPES_H_INCLUDED
DataType(const std::string &name)
CTOR. creates the datatype with a different name then defined by default.
Definition dd_predefined_datatypes.h:121
DataType()
CTOR. creates the datatype with the default name for the type bool.
Definition dd_predefined_datatypes.h:136
DataType()
CTOR. creates the datatype with the default name for the type char.
Definition dd_predefined_datatypes.h:169
DataType(const std::string &name)
CTOR. creates the datatype with a different name then defined by default.
Definition dd_predefined_datatypes.h:154
DataType(const std::string &name)
CTOR. creates the datatype with a different name then defined by default.
Definition dd_predefined_datatypes.h:220
DataType()
CTOR. creates the datatype with the default name for the type double.
Definition dd_predefined_datatypes.h:235
DataType(const std::string &name)
CTOR. creates the datatype with a different name then defined by default.
Definition dd_predefined_datatypes.h:187
DataType()
CTOR. creates the datatype with the default name for the type float.
Definition dd_predefined_datatypes.h:202
DataType(const std::string &)
CTOR. creates the datatype with a different name then defined by default.
Definition dd_predefined_datatypes.h:43
DataType()
CTOR. creates the datatype with the default name for the type T.
Definition dd_predefined_datatypes.h:52
std::shared_ptr< dd::datamodel::DataType > getPredefinedType(const std::string &name) const
Get the Predefined Type object by name.
std::vector< std::string > getAliasTypes(const std::string &name) const
Get the aliases for this type to determine similar type (like tBool and bool)
static const PredefinedDataTypes & getInstance()
Get the Instance object.
std::vector< std::shared_ptr< dd::datamodel::DataType > > getPredefinedTypes() const
Gets a vector of all the predefined data types.
dd::OptionalSize getDefaultAlignment(const std::string &name) const
Get the default alignment of a Predefined Type by name.
observable DataDefinition object class to describe (POD) DataType.
Definition datamodel_types.h:113
#define DDL_DATA_TYPE_INT(type, default_name)
Definition dd_predefined_datatypes.h:71
definition of the dd namespace
Definition datamodel_base.h:26
utility::Optional< size_t > OptionalSize
Optional Size Type.
Definition dd_common_types.h:38
definition of the ddl namespace
Definition codec.h:21