20#include <unordered_map>
60 X1(astronomical_unit, au) \
63 X1(solar_radius, rsol) \
64 X1(earth_radius, rearth) \
65 X1(solar_mass, sol_mass) \
66 X1(electron_volt, eV) \
68 X1(british_pint, pint)
71#define XMAC_UNIT_PREFIX \
93 #define X(longname, shortname, value) longname = value, shortname = value,
100 template<
class T, UnitPrefix p>
107 static const std::unordered_map<std::string, UnitPrefix> map_name_to_unit_prefix{
109 #define X(longname, shortname, value) {#longname, longname}, {#shortname, shortname},
117 static const std::unordered_map<UnitPrefix, std::string> map_u_to_name_prefix = {
119 #define X(longname, shortname, value) {shortname, #shortname},
128 map_u_to_name_prefix.find(p);
130 if (
auto search = map_u_to_name_prefix.find(p); search != map_u_to_name_prefix.end()) {
131 return search->second;
134 return "[Unknown Unit prefix name]";
140 map_name_to_unit_prefix.find(p);
142 if (
auto search = map_name_to_unit_prefix.find(p);
143 search != map_name_to_unit_prefix.end()) {
144 return search->second;
147 throw std::invalid_argument(
"this unit prefix name is unknown");
157 #define X1(longname, shortname) longname, shortname = longname,
163 static const std::unordered_map<std::string, UnitName> map_name_to_unit{
165 #define X1(longname, shortname) {#longname, longname}, {#shortname, shortname},
171 static const std::unordered_map<UnitName, std::string> map_u_to_name = {
173 #define X1(longname, shortname) {shortname, #shortname},
182 map_u_to_name.find(p);
184 if (
auto search = map_u_to_name.find(p); search != map_u_to_name.end()) {
185 return search->second;
188 return "[Unknown Unit name]";
194 auto search = map_name_to_unit.find(p);
196 if (search != map_name_to_unit.end()) {
197 return search->second;
200 throw std::invalid_argument(
"this unit name is unknown : " + p);
#define XMAC_UNITS
Definition of all units.
UnitName
List of all units name.
const UnitName unit_from_name(std::string p)
Get the UnitName enum value from a unit name as a string.
const std::string get_unit_name(UnitName p)
Get the unit name for a UnitName enum value.
#define XMAC_UNIT_PREFIX
Definition of all prefixes.
namespace containing the units library
const std::string get_unit_prefix_name(UnitPrefix p)
Get the prefix name for a UnitPrefix enum value.
UnitPrefix
Enum of all prefixes.
constexpr T get_prefix_val()
Get the value of a prefix.
const UnitPrefix unit_prefix_from_name(std::string p)
Get the UnitPrefix enum value from a prefix name as a string.
constexpr T pow_constexpr_fast_inv(T a, T a_inv) noexcept
Constexpr power expansion function with supplied inverse for negative values.