1571 using Quantity_t = Quantity;
1572 using value_t =
typename Quantity_t::value_t;
1573 using unit_t =
typename Quantity_t::unit_t;
1574 using baseunit_t =
typename unit_t::baseunit_t;
1579 using PrefixMap_t = std::map<std::string, value_t>;
1580 using PrefixValue_t =
typename PrefixMap_t::value_type;
1581 static PrefixMap_t
const factors {
1582 PrefixValue_t{
"a"s, 1
e-18 },
1583 PrefixValue_t{
"f"s, 1e-15 },
1584 PrefixValue_t{
"p"s, 1e-12 },
1585 PrefixValue_t{
"n"s, 1e-09 },
1586 PrefixValue_t{
"u"s, 1e-06 },
1587 PrefixValue_t{
"m"s, 1e-03 },
1588 PrefixValue_t{
"c"s, 1e-02 },
1589 PrefixValue_t{
"d"s, 1e-01 },
1590 PrefixValue_t{
""s, 1e+00 },
1591 PrefixValue_t{
"da"s, 1e+01 },
1592 PrefixValue_t{
"h"s, 1e+02 },
1593 PrefixValue_t{
"k"s, 1e+03 },
1594 PrefixValue_t{
"M"s, 1e+06 },
1595 PrefixValue_t{
"G"s, 1e+09 },
1596 PrefixValue_t{
"T"s, 1e+12 },
1597 PrefixValue_t{
"P"s, 1e+15 },
1598 PrefixValue_t{
"E"s, 1e+18 }
1600 static auto const composePrefixPattern = [](
auto b,
auto e) ->
std::string 1604 pattern +=
b->first;
1605 while (++
b != e) { pattern +=
'|'; pattern +=
b->first; }
1607 return pattern +=
")";
1610 = composePrefixPattern(factors.begin(), factors.end());
1613 std::regex
const unitPattern {
1614 "[[:blank:]]*(" + prefixPattern +
"?" 1618 std::smatch unitMatch;
1619 if (!std::regex_search(
str, unitMatch, unitPattern)) {
1620 if (!unitOptional) {
1621 throw MissingUnit(
"Unit is mandatory and must derive from '" 1625 return {
str, value_t{ 1 } };
1633 auto const iFactor = factors.
find(unitMatch.str(2U));
1634 if (iFactor == factors.end()) {
1635 throw InvalidUnitPrefix(
1636 "Unit '" + unitMatch.str(1U)
1637 +
"' has unsupported prefix '" + unitMatch.str(2U)
1638 +
"' (parsing '" +
str +
"')" 1644 static_cast<value_t>(unit_t::scale(iFactor->second))
int find(char c, int index=0, bool cs=TRUE) const
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.