ADTF  3.18.2
dd_predefined_datatypes.h
Go to the documentation of this file.
1 
15 #ifndef DD_PREDEFINED_DATATYPES_H_INCLUDED
16 #define DD_PREDEFINED_DATATYPES_H_INCLUDED
17 
20 #include <ddl/dd/dd_common_types.h>
22 
23 #include <limits>
24 #include <memory>
25 #include <string>
26 #include <type_traits>
27 #include <unordered_map>
28 #include <vector>
29 
30 namespace ddl {
31 
37 template <typename T>
39 public:
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  }
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 
95 DDL_DATA_TYPE_INT(uint8_t, "tUInt8");
96 DDL_DATA_TYPE_INT(uint16_t, "tUInt16");
97 DDL_DATA_TYPE_INT(uint32_t, "tUInt32");
98 DDL_DATA_TYPE_INT(uint64_t, "tUInt64");
99 
100 DDL_DATA_TYPE_INT(int8_t, "tInt8");
101 DDL_DATA_TYPE_INT(int16_t, "tInt16");
102 DDL_DATA_TYPE_INT(int32_t, "tInt32");
103 DDL_DATA_TYPE_INT(int64_t, "tInt64");
105 
106 namespace ddl {
107 
113 template <>
114 class DataType<bool> : public dd::datamodel::DataType {
115 public:
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  }
136  DataType() : DataType("tBool")
137  {
138  }
139 };
140 
146 template <>
147 class DataType<char> : public dd::datamodel::DataType {
148 public:
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  }
169  DataType() : DataType("tChar")
170  {
171  }
172 };
173 
179 template <>
180 class DataType<float> : public dd::datamodel::DataType {
181 public:
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  }
202  DataType() : DataType("tFloat32")
203  {
204  }
205 };
206 
212 template <>
213 class DataType<double> : public dd::datamodel::DataType {
214 public:
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  }
235  DataType() : DataType("tFloat64")
236  {
237  }
238 };
239 
272 private:
283 
284 public:
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 
319 private:
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.
DataType(const std::string &name)
CTOR.
DataType(const std::string &name)
CTOR.
DataType(const std::string &name)
CTOR.
Generator template to create DataType for the plain c-types.
DataType(const std::string &)
CTOR.
Predefined types of the DataDefinition.
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.
PredefinedDataTypes()
Construct a new Predefined Data Types object.
std::vector< std::string > getAliasTypes(const std::string &name) const
Get the aliases for this type to determine similar type (like tBool and bool)
~PredefinedDataTypes()
Destructor.
std::shared_ptr< dd::datamodel::DataType > getPredefinedType(const std::string &name) const
Get the Predefined Type object by name.
static const PredefinedDataTypes & getInstance()
Get the Instance object.
observable DataDefinition object class to describe (POD) DataType.
OO DataDefinition Type objects (DataType, EnumType, StructType, StreamMetaType)
OO DataDefinition Common Design.
#define DDL_DATA_TYPE_INT(type, default_name)
Expands to DataType<type> inheriting from dd::datamodel::DataType.
Definition of preprocessor macros to disable/enable compiler warnings.
Utility for the Neutrino gcc5 compiler which has really no std::to_string implementation!