Dev Essential  1.6.3
Loading...
Searching...
No Matches
ddenum.h
Go to the documentation of this file.
1
14
15#ifndef DDENUM_H_INCLUDED
16#define DDENUM_H_INCLUDED
17
18#include <ddl/dd/dd.h>
19#include <ddl/dd/dddatatype.h>
21
22namespace ddl {
23
29class DDEnum {
30public:
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
134private:
137 // the enumtype
138 std::shared_ptr<dd::EnumType> _enum_type;
139};
140
154template <typename EnumDataType, typename Enable = void>
155class DDEnumGenerator : public DDEnum {
156public:
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,
170 std::to_string(
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
203template <typename EnumDataType>
204class DDEnumGenerator<EnumDataType,
205 typename std::enable_if<std::is_arithmetic<EnumDataType>::value>::type>
206 : public DDEnum {
207public:
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. (i.e. Units!)
Definition dddatatype.h:30
DDEnumGenerator(const std::string &name, const std::vector< std::pair< std::string, EnumDataType > > elements={})
CTOR.
Definition ddenum.h:214
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 & operator=(const DDEnum &other)
copies a DDEnum object
size_t getTypeByteSize() const
returns the size of the underlying datatype.
DDEnum(const DDEnum &other)
Construct a new DDEnum object.
DDEnum(const std::string &name, const dd::DataType &data_type, const std::vector< dd::EnumType::Element > &elements={})
Construct a new DDEnum object.
const dd::EnumType & getEnumType() const
Get the Enum Type object.
DDEnum & operator=(DDEnum &&)
DDEnum & addElement(const dd::EnumType::Element &element)
adds a EnumType element.
DDEnum(DDEnum &&)
Construct a new DDEnum object.
DDEnum()=delete
Construct a new DDEnum object.
DDEnum(const std::string &name, const DDDataType &data_type, const std::vector< dd::EnumType::Element > &elements={})
Construct a new DDEnum object.
const dd::DataDefinition & getDD() const
return the valid data definition.
DDEnum & addElements(const std::vector< dd::EnumType::Element > &elements)
adds a vector of EnumType elements.
size_t getAlignment() const
returns the alignment of the underlying datatype.
DDEnum & addElement(const std::string &name, int64_t value)
adds a EnumType element.
Generator template to create DataType for the plain c-types.
Definition dd_predefined_datatypes.h:38
The Data Definiton class uses the validation model to keep a Data Definition datamodel (ddl::dd::data...
Definition dd.h:92
KeyValuePair Element
Enum type element defintion as Name Value pair.
Definition datamodel_types.h:326
datamodel::DataType DataType
Definition dd.h:51
datamodel::EnumType EnumType
Definition dd.h:55
definition of the ddl namespace
Definition codec.h:21