41 {
"cm", { 0.01,
UnitSI().
m() } },
42 {
"dm", { 0.1,
UnitSI().
m() } },
44 {
"min", { 60,
UnitSI().
s() } },
45 {
"h", { 3600,
UnitSI().
s() } },
46 {
"d", { 24*3600,
UnitSI().
s() } },
47 {
"y", { 365*24*3600,
UnitSI().
s() } },
68 for (it=base_units_map.begin(); it!=base_units_map.end(); ++it) {
69 if (it->first.at(0)==
'*') {
70 std::string shortcut = it->first.substr(1);
71 double coef = it->second.coef_;
74 std::string key = prefix_it->first + shortcut;
75 units_map_.insert(std::pair<std::string, DerivedUnit>( key, { coef*prefix_it->second, it->second.unit_ } ));
78 units_map_.insert( std::pair<std::string, DerivedUnit>( it->first, it->second ) );
97 typedef spirit_namespace::position_iterator< std::string::iterator > PosnIterT;
99 std::string::iterator begin = s.begin();
100 std::string::iterator end = s.end();
102 const PosnIterT posn_begin( begin, end );
103 const PosnIterT posn_end( end, end );
108 spirit_namespace::parse( begin, end,
110 spirit_namespace::space_p );
112 }
catch (ExcInvalidUnit &e) {
113 e << EI_UnitDefinition(s);
126 Formula &formula = unit_data.find(
"")->second;
138 ASSERT_DBG(it != UnitConverter::basic_factors.units_map_.end())(factor.
factor_).error(
"Undefined unit.");
139 coef *= pow(it->second.coef_, factor.
exponent_);
144 coef *= pow(it->second.coef_, factor.
exponent_);
Helper class. Defines basic factors of SI, non-SI and derived units.
UnitsMap units_map_
Define all base and derived units given by their symbol.
UnitData read_unit(std::string s)
Parse and check unit defined in string format.
bool basic_
unit is basic (strict defined in application) / derived (defined by user as formula) ...
UnitSI unit_si() const
Return unit_si_.
void check_unit_data()
Check unit_data_ object.
Definition of unit grammar.
UnitConverter()
Constructor.
void add_converted_unit(Factor factor, UnitData &unit_data, UnitSI &unit_si, double &coef)
Calculates UnitSi and coeficient of Factor, recursively calls this method for user defined formula...
Class manages parsing of user defined field unit.
double convert(std::string actual_unit)
Convert string to coeficient and UnitSI representation, return coeficient.
void multiply(const UnitSI &other, int exp=1)
Multiply with power of given unit.
std::string factor_
string represantation of unit or user defined constant
UnitData unit_data() const
Store structure given by parser.
void reset()
Reset UnitSI object (set vector of exponents to zeros and set undef flag)
BasicFactors()
Constructor.
UnitSI & m(int exp=1)
Methods set values of exponents for SI units with similar name.
Class for representation SI units of Fields.
static const BasicFactors basic_factors
Define all base and derived units given by their symbol.