ADTF  3.18.2
dd_predefined_units.h
Go to the documentation of this file.
1 
15 #ifndef DD_PREDEFINED_UNITS_H_INCLUDED
16 #define DD_PREDEFINED_UNITS_H_INCLUDED
17 
19 
20 #include <memory>
21 #include <string>
22 #include <type_traits>
23 #include <unordered_map>
24 
25 namespace ddl {
26 
32 template <typename T>
34  BaseUnit() : dd::datamodel::BaseUnit(T::_name, T::_symbol, T::_description)
35  {
36  }
37 };
38 
44 template <typename T>
46  UnitPrefix() : dd::datamodel::UnitPrefix(T::_name, T::_symbol, T::_power)
47  {
48  }
49 };
50 
55 namespace unit {
56 }
61 namespace unit_prefix {
62 }
63 } // namespace ddl
64 
73 #define DDL_BASE_UNIT_DEFINITION(classname, baseunitname, baseunitsymbol, baseunitdescription) \
74  namespace unit { \
75  struct classname { \
76  constexpr static const char* const _name = baseunitname; \
77  constexpr static const char* const _symbol = baseunitsymbol; \
78  constexpr static const char* const _description = baseunitdescription; \
79  }; \
80  } \
81  static_assert(true, "Simply to make sure a closing semicolon ';' is used for the macro")
82 
91 #define DDL_UNIT_PREFIX_DEFINITION(classname, unitprefixname, unitprefixsymbol, unitprefixpower) \
92  namespace unit_prefix { \
93  struct classname { \
94  constexpr static const char* const _name = unitprefixname; \
95  constexpr static const char* const _symbol = unitprefixsymbol; \
96  constexpr static const int32_t _power = unitprefixpower; \
97  }; \
98  } \
99  static_assert(true, "Simply to make sure a closing semicolon ';' is used for the macro")
100 
101 namespace ddl {
103 DDL_BASE_UNIT_DEFINITION(Metre, "Metre", "m", "Fundamental unit for length");
104 DDL_BASE_UNIT_DEFINITION(Kilogram, "Kilogram", "kg", "Fundamental unit for mass");
105 DDL_BASE_UNIT_DEFINITION(Second, "Second", "s", "Fundamental unit for time");
106 DDL_BASE_UNIT_DEFINITION(Ampere, "Ampere", "A", "Fundamental unit for electric current");
107 DDL_BASE_UNIT_DEFINITION(Kelvin, "Kelvin", "K", "Fundamental unit for temperature");
108 DDL_BASE_UNIT_DEFINITION(Mole, "Mole", "mol", "Fundamental unit for amount of substance");
109 DDL_BASE_UNIT_DEFINITION(Candela, "Candela", "cd", "Fundamental unit for luminous intensity");
110 DDL_BASE_UNIT_DEFINITION(Degree, "Degree", "deg", "Non-SI standard unit for angle");
111 DDL_BASE_UNIT_DEFINITION(Radiant, "Radiant", "rad", "Non-SI standard unit for angle");
112 DDL_BASE_UNIT_DEFINITION(Unitless, "Unitless", "", "No SI, but needed for own unit definitions");
113 DDL_BASE_UNIT_DEFINITION(Nou, "nou", "", "No SI, but needed for no unit definitions");
114 
115 DDL_UNIT_PREFIX_DEFINITION(yotta, "yotta", "Y", 24);
116 DDL_UNIT_PREFIX_DEFINITION(zetta, "zetta", "Z", 21);
117 DDL_UNIT_PREFIX_DEFINITION(exa, "exa", "E", 18);
118 DDL_UNIT_PREFIX_DEFINITION(peta, "peta", "P", 15);
119 DDL_UNIT_PREFIX_DEFINITION(tera, "tera", "T", 12);
120 DDL_UNIT_PREFIX_DEFINITION(giga, "giga", "G", 9);
121 DDL_UNIT_PREFIX_DEFINITION(mega, "mega", "M", 6);
122 DDL_UNIT_PREFIX_DEFINITION(kilo, "kilo", "k", 3);
123 DDL_UNIT_PREFIX_DEFINITION(hecto, "hecto", "h", 2);
124 DDL_UNIT_PREFIX_DEFINITION(deca, "deca", "da", 1);
125 DDL_UNIT_PREFIX_DEFINITION(deci, "deci", "d", -1);
126 DDL_UNIT_PREFIX_DEFINITION(centi, "centi", "c", -2);
127 DDL_UNIT_PREFIX_DEFINITION(milli, "mili", "m", -3);
128 DDL_UNIT_PREFIX_DEFINITION(micro, "micro", "u", -6);
129 DDL_UNIT_PREFIX_DEFINITION(nano, "nano", "n", -9);
130 DDL_UNIT_PREFIX_DEFINITION(pico, "pico", "p", -12);
131 DDL_UNIT_PREFIX_DEFINITION(femto, "femto", "f", -15);
132 DDL_UNIT_PREFIX_DEFINITION(atto, "atto", "a", -18);
133 DDL_UNIT_PREFIX_DEFINITION(zepto, "zepto", "z", -21);
134 DDL_UNIT_PREFIX_DEFINITION(yocto, "yocto", "y", -24);
136 
179 private:
190 
191 public:
197  static const PredefinedUnits& getInstance();
204  std::shared_ptr<dd::datamodel::BaseUnit> getPredefinedBaseUnit(const std::string& name) const;
211  std::shared_ptr<dd::datamodel::UnitPrefix> getPredefinedUnitPrefix(
212  const std::string& name) const;
213 
219  std::vector<std::shared_ptr<dd::datamodel::BaseUnit>> getPredefinedBaseUnits() const;
225  std::vector<std::shared_ptr<dd::datamodel::UnitPrefix>> getPredefinedUnitPrefixes() const;
226 
227 private:
228  const std::unordered_map<std::string, std::shared_ptr<dd::datamodel::BaseUnit>>
229  _defined_base_units;
230  const std::unordered_map<std::string, std::shared_ptr<dd::datamodel::UnitPrefix>>
231  _defined_unit_prefixes;
232 };
233 
234 } // namespace ddl
235 
236 #endif // DD_PREDEFINED_UNITS_H_INCLUDED
Static class for predefined units.
~PredefinedUnits()
Destructor.
std::shared_ptr< dd::datamodel::BaseUnit > getPredefinedBaseUnit(const std::string &name) const
Get the Predefined Base Unit by name.
static const PredefinedUnits & getInstance()
Get the Instance object.
std::vector< std::shared_ptr< dd::datamodel::UnitPrefix > > getPredefinedUnitPrefixes() const
Gets a vector of all the predefined unit prefixes types.
std::vector< std::shared_ptr< dd::datamodel::BaseUnit > > getPredefinedBaseUnits() const
Gets a vector of all the predefined base units.
PredefinedUnits()
Construct a new Predefined Units object.
std::shared_ptr< dd::datamodel::UnitPrefix > getPredefinedUnitPrefix(const std::string &name) const
Get the Predefined Unit Prefix by name.
Unit Prefix - datamodel pefixes.
DataDefinition Unit definitions.
#define DDL_UNIT_PREFIX_DEFINITION(classname, unitprefixname, unitprefixsymbol, unitprefixpower)
Unit prefix template definiton.
#define DDL_BASE_UNIT_DEFINITION(classname, baseunitname, baseunitsymbol, baseunitdescription)
Base unit template definiton.
datamodel::BaseUnit BaseUnit
Reuse of datamodel base unit class - ddl::dd::datamodel::BaseUnit.
Definition: dd.h:34
datamodel::UnitPrefix UnitPrefix
Reuse of datamodel unit prefix class - ddl::dd::datamodel::UnitPrefix.
Definition: dd.h:38
@ unit
the unit is a unit (Unit)
Generator template to create baseunits.
Generator template to create UnitPrefix.