ADTF  3.18.2
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 getAlignment() const;
126 
127 private:
130  // the enumtype
131  std::shared_ptr<dd::EnumType> _enum_type;
132 };
133 
147 template <typename EnumDataType, typename Enable = void>
148 class DDEnumGenerator : public DDEnum {
149 public:
156  DDEnumGenerator(const std::string& name,
157  const std::vector<std::pair<std::string, EnumDataType>> elements = {})
158  : DDEnum(name, DataType<typename std::underlying_type<EnumDataType>::type>())
159  {
160  for (const auto& elem: elements) {
162  elem.first,
164  static_cast<typename std::underlying_type<EnumDataType>::type>(elem.second))));
165  }
166  }
167 
176  DDEnumGenerator& addElement(const std::string& name, EnumDataType value)
177  {
179  name,
180  std::to_string(static_cast<typename std::underlying_type<EnumDataType>::type>(value))));
181  return *this;
182  }
183 };
184 
196 template <typename EnumDataType>
197 class DDEnumGenerator<EnumDataType,
198  typename std::enable_if<std::is_arithmetic<EnumDataType>::value>::type>
199  : public DDEnum {
200 public:
207  DDEnumGenerator(const std::string& name,
208  const std::vector<std::pair<std::string, EnumDataType>> elements = {})
209  : DDEnum(name, DataType<EnumDataType>())
210  {
211  for (const auto& elem: elements) {
212  DDEnum::addElement(dd::EnumType::Element(elem.first, std::to_string(elem.second)));
213  }
214  }
215 };
216 
217 } // namespace ddl
218 
219 #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:207
This is used to create the DD representation of an enumeration type.
Definition: ddenum.h:148
DDEnumGenerator & addElement(const std::string &name, EnumDataType value)
Adds a element for the enumeration with name and value.
Definition: ddenum.h:176
DDEnumGenerator(const std::string &name, const std::vector< std::pair< std::string, EnumDataType >> elements={})
CTOR.
Definition: ddenum.h:156
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:129
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 data type.
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.
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:87
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.
@ data_type
value for data type
Definition: ddl_capi.h:55
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.
Utility for the Neutrino gcc5 compiler which has really no std::to_string implementation!