ADTF
Loading...
Searching...
No Matches
dd_predefined_units.h
Go to the documentation of this file.
1
14
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
25namespace ddl {
26
32template <typename T>
33struct BaseUnit : public dd::datamodel::BaseUnit {
34 BaseUnit() : dd::datamodel::BaseUnit(T::_name, T::_symbol, T::_description)
35 {
36 }
37};
38
44template <typename T>
45struct UnitPrefix : public dd::datamodel::UnitPrefix {
46 UnitPrefix() : dd::datamodel::UnitPrefix(T::_name, T::_symbol, T::_power)
47 {
48 }
49};
50
55namespace unit {
56}
57
61namespace 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
101namespace ddl {
103DDL_BASE_UNIT_DEFINITION(Metre, "Metre", "m", "Fundamental unit for length");
104DDL_BASE_UNIT_DEFINITION(Kilogram, "Kilogram", "kg", "Fundamental unit for mass");
105DDL_BASE_UNIT_DEFINITION(Second, "Second", "s", "Fundamental unit for time");
106DDL_BASE_UNIT_DEFINITION(Ampere, "Ampere", "A", "Fundamental unit for electric current");
107DDL_BASE_UNIT_DEFINITION(Kelvin, "Kelvin", "K", "Fundamental unit for temperature");
108DDL_BASE_UNIT_DEFINITION(Mole, "Mole", "mol", "Fundamental unit for amount of substance");
109DDL_BASE_UNIT_DEFINITION(Candela, "Candela", "cd", "Fundamental unit for luminous intensity");
110DDL_BASE_UNIT_DEFINITION(Degree, "Degree", "deg", "Non-SI standard unit for angle");
111DDL_BASE_UNIT_DEFINITION(Radiant, "Radiant", "rad", "Non-SI standard unit for angle");
112DDL_BASE_UNIT_DEFINITION(Unitless, "Unitless", "", "No SI, but needed for own unit definitions");
113DDL_BASE_UNIT_DEFINITION(Nou, "nou", "", "No SI, but needed for no unit definitions");
114
115DDL_UNIT_PREFIX_DEFINITION(yotta, "yotta", "Y", 24);
116DDL_UNIT_PREFIX_DEFINITION(zetta, "zetta", "Z", 21);
117DDL_UNIT_PREFIX_DEFINITION(exa, "exa", "E", 18);
118DDL_UNIT_PREFIX_DEFINITION(peta, "peta", "P", 15);
119DDL_UNIT_PREFIX_DEFINITION(tera, "tera", "T", 12);
120DDL_UNIT_PREFIX_DEFINITION(giga, "giga", "G", 9);
121DDL_UNIT_PREFIX_DEFINITION(mega, "mega", "M", 6);
122DDL_UNIT_PREFIX_DEFINITION(kilo, "kilo", "k", 3);
123DDL_UNIT_PREFIX_DEFINITION(hecto, "hecto", "h", 2);
124DDL_UNIT_PREFIX_DEFINITION(deca, "deca", "da", 1);
125DDL_UNIT_PREFIX_DEFINITION(none, "none", "", 0);
126DDL_UNIT_PREFIX_DEFINITION(deci, "deci", "d", -1);
127DDL_UNIT_PREFIX_DEFINITION(centi, "centi", "c", -2);
128DDL_UNIT_PREFIX_DEFINITION(milli, "mili", "m", -3);
129DDL_UNIT_PREFIX_DEFINITION(micro, "micro", "u", -6);
130DDL_UNIT_PREFIX_DEFINITION(nano, "nano", "n", -9);
131DDL_UNIT_PREFIX_DEFINITION(pico, "pico", "p", -12);
132DDL_UNIT_PREFIX_DEFINITION(femto, "femto", "f", -15);
133DDL_UNIT_PREFIX_DEFINITION(atto, "atto", "a", -18);
134DDL_UNIT_PREFIX_DEFINITION(zepto, "zepto", "z", -21);
135DDL_UNIT_PREFIX_DEFINITION(yocto, "yocto", "y", -24);
137
179class PredefinedUnits {
180private:
185 PredefinedUnits();
190 ~PredefinedUnits();
191
192public:
198 static const PredefinedUnits& getInstance();
205 std::shared_ptr<dd::datamodel::BaseUnit> getPredefinedBaseUnit(const std::string& name) const;
212 std::shared_ptr<dd::datamodel::UnitPrefix> getPredefinedUnitPrefix(
213 const std::string& name) const;
214
220 std::vector<std::shared_ptr<dd::datamodel::BaseUnit>> getPredefinedBaseUnits() const;
226 std::vector<std::shared_ptr<dd::datamodel::UnitPrefix>> getPredefinedUnitPrefixes() const;
227
228private:
229 const std::unordered_map<std::string, std::shared_ptr<dd::datamodel::BaseUnit>>
230 _defined_base_units;
231 const std::unordered_map<std::string, std::shared_ptr<dd::datamodel::UnitPrefix>>
232 _defined_unit_prefixes;
233};
234
235} // namespace ddl
236
237#endif // DD_PREDEFINED_UNITS_H_INCLUDED
static const PredefinedUnits & getInstance()
Get the Instance object.
std::vector< std::shared_ptr< dd::datamodel::BaseUnit > > getPredefinedBaseUnits() const
Gets a vector of all the predefined base units.
std::vector< std::shared_ptr< dd::datamodel::UnitPrefix > > getPredefinedUnitPrefixes() const
Gets a vector of all the predefined unit prefixes types.
std::shared_ptr< dd::datamodel::BaseUnit > getPredefinedBaseUnit(const std::string &name) const
Get the Predefined Base Unit by name.
std::shared_ptr< dd::datamodel::UnitPrefix > getPredefinedUnitPrefix(const std::string &name) const
Get the Predefined Unit Prefix by name.
BaseUnit.
Definition datamodel_units.h:108
Unit Prefix - datamodel pefixes.
Definition datamodel_units.h:221
#define DDL_UNIT_PREFIX_DEFINITION(classname, unitprefixname, unitprefixsymbol, unitprefixpower)
Unit prefix template definiton.
Definition dd_predefined_units.h:91
#define DDL_BASE_UNIT_DEFINITION(classname, baseunitname, baseunitsymbol, baseunitdescription)
Definition dd_predefined_units.h:73
definiton of the unit prefixes namespace
Definition dd_predefined_units.h:61
definiton of the unit namespace
Definition dd_predefined_units.h:55
definition of the ddl namespace
Definition codec.h:21