ADTF
ddenum.h
Go to the documentation of this file.
1 
15 #ifndef DDENUM_H_INCLUDED
16 #define DDENUM_H_INCLUDED
17 
18 #include <ddl/dd/dd.h>
19 #include <ddl/dd/dddatatype.h>
21 
22 namespace ddl {
23 
29 class DDEnum {
30 public:
35  DDEnum() = delete;
52  DDEnum(const DDEnum& other);
58  DDEnum& operator=(const DDEnum& other);
67  DDEnum(const std::string& name,
68  const dd::DataType& data_type,
69  const std::vector<dd::EnumType::Element>& elements = {});
70 
80  DDEnum(const std::string& name,
81  const DDDataType& data_type,
82  const std::vector<dd::EnumType::Element>& elements = {});
83 
98  DDEnum& addElement(const std::string& name, int64_t value);
105  DDEnum& addElements(const std::vector<dd::EnumType::Element>& elements);
106 
112  const dd::EnumType& getEnumType() const;
118  const dd::DataDefinition& getDD() const;
119 
125  size_t getTypeByteSize() const;
126 
132  size_t getAlignment() const;
133 
134 private:
137  // the enumtype
138  std::shared_ptr<dd::EnumType> _enum_type;
139 };
140 
154 template <typename EnumDataType, typename Enable = void>
155 class DDEnumGenerator : public DDEnum {
156 public:
163  DDEnumGenerator(const std::string& name,
164  const std::vector<std::pair<std::string, EnumDataType>> elements = {})
165  : DDEnum(name, DataType<typename std::underlying_type<EnumDataType>::type>())
166  {
167  for (const auto& elem: elements) {
169  elem.first,
171  static_cast<typename std::underlying_type<EnumDataType>::type>(elem.second))));
172  }
173  }
174 
183  DDEnumGenerator& addElement(const std::string& name, EnumDataType value)
184  {
186  name,
187  std::to_string(static_cast<typename std::underlying_type<EnumDataType>::type>(value))));
188  return *this;
189  }
190 };
191 
203 template <typename EnumDataType>
204 class DDEnumGenerator<EnumDataType,
205  typename std::enable_if<std::is_arithmetic<EnumDataType>::value>::type>
206  : public DDEnum {
207 public:
214  DDEnumGenerator(const std::string& name,
215  const std::vector<std::pair<std::string, EnumDataType>> elements = {})
216  : DDEnum(name, DataType<EnumDataType>())
217  {
218  for (const auto& elem: elements) {
219  DDEnum::addElement(dd::EnumType::Element(elem.first, std::to_string(elem.second)));
220  }
221  }
222 };
223 
224 } // namespace ddl
225 
226 #endif // DDENUM_H_INCLUDED
A DataType class holding the DD for a Datatype with dependencies.
Definition: dddatatype.h:30
DDEnumGenerator(const std::string &name, const std::vector< std::pair< std::string, EnumDataType >> elements={})
CTOR.
Definition: ddenum.h:214
This is used to create the DD representation of an enumeration type.
Definition: ddenum.h:155
DDEnumGenerator & addElement(const std::string &name, EnumDataType value)
Adds a element for the enumeration with name and value.
Definition: ddenum.h:183
DDEnumGenerator(const std::string &name, const std::vector< std::pair< std::string, EnumDataType >> elements={})
CTOR.
Definition: ddenum.h:163
Utility class for a complete valid data definition of one EnumType and its dependencies.
Definition: ddenum.h:29
DDEnum(DDEnum &&)
Construct a new DDEnum object.
DDEnum & operator=(DDEnum &&)
const dd::DataDefinition & getDD() const
return the valid data definition.
DDEnum(const std::string &name, const dd::DataType &data_type, const std::vector< dd::EnumType::Element > &elements={})
Construct a new DDEnum object.
DDEnum & operator=(const DDEnum &other)
copies a DDEnum object
dd::DataDefinition _dd
the data definition
Definition: ddenum.h:136
DDEnum & addElement(const std::string &name, int64_t value)
adds a EnumType element.
DDEnum(const std::string &name, const DDDataType &data_type, const std::vector< dd::EnumType::Element > &elements={})
Construct a new DDEnum object.
size_t getAlignment() const
returns the alignment of the underlying datatype.
const dd::EnumType & getEnumType() const
Get the Enum Type object.
DDEnum(const DDEnum &other)
Construct a new DDEnum object.
DDEnum & addElement(const dd::EnumType::Element &element)
adds a EnumType element.
DDEnum & addElements(const std::vector< dd::EnumType::Element > &elements)
adds a vector of EnumType elements.
size_t getTypeByteSize() const
returns the size of the underlying datatype.
DDEnum()=delete
Construct a new DDEnum object.
Generator template to create DataType for the plain c-types.
The Data Definiton class uses the validation model to keep a Data Definition datamodel (ddl::dd::data...
Definition: dd.h:92
observable DataDefinition object class to describe (POD) DataType.
observable DataDefinition object class to describe EnumType.
OO DataDefinition - Data Definition.
OO DataDefinition DataTypes header for template based DataType usages.
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.
@ data_type
the type is a data type (DataType)
Utility for the Neutrino gcc5 compiler which has really no std::to_string implementation!