Basis Unit Store
#include <xo/unit/bu_store.hpp>
namespace bu = xo::qty::detail::bu;
A xo::qty::bu_store is a small, constexpr, key-value store associating
abbreviations with basis units. To satisfy the constexpr requirement,
all unit abbreviations are irrevocably established from bu_store’s constructor.
The constant bu_abbrev_store contains a single instance of bu_store,
recording all built-in units along with their associated abbreviations
basis-unit store
This class exists to support the implementation of natural_unit::abbrev().
Application code is not expected to interact directly with it.
Class
-
class bu_store
associate basis units with abbreviations
For example, this would be possible:
#include <xo/unit/bu_store.hpp>
namespace bu = using xo::qty::detail::bu;
using xo::qty::detail::bu_store;
using xo::qty::dim;
using xo::flatstring;
constexpr bu_store store;
static_assert(store.bu_abbrev(bu::minute) == flatstring("min"));
static_assert(store.bu_abbrev(bu::microgram) == flatstring("ug"));
- group bu-store constructors
Functions
-
inline constexpr bu_store()
construct canonical instance containing all known basis units
-
inline constexpr bu_store()
- group Bu-store-access-methods
Functions
-
inline bu_abbrev_type bu_abbrev(const basis_unit &bu) const
get basis-unit abbreviation at runtime
-
inline bu_abbrev_type bu_abbrev(const basis_unit &bu) const
- group Bu-store-implementation-methods
Functions
-
static inline bu_abbrev_type bu_fallback_abbrev(dim basis_dim, const scalefactor_ratio_type &scalefactor)
report fallback abbreviation for a basis unit.
Typically unused. Will be invoked only if a basis unit exists for which bu_store::bu_establish_abbrev was not called by bu_store’s constructor.
Tries to produce something unambiguous, while still supplying enough information to indicate what’s needed to resolve the problem.
Example
bu_store.bu_fallback_abbrev(dim::mass, scalefactor_ratio_type(1234,1)) => "1234g"
-
inline void bu_establish_abbrev(const basis_unit &bu, const bu_abbrev_type &abbrev)
associate abbreviation
abbrevwith basis unitbuExample:
// femtograms bu_store.bu_establish_abbrev(detail::bu::mass_unit(1, 1000000000000000), "fg")
-
static inline bu_abbrev_type bu_fallback_abbrev(dim basis_dim, const scalefactor_ratio_type &scalefactor)
-
class bu_dim_store
store basis-unit abbreviations for a particular dimension
- group bu-dim-store type traits
Typedefs
-
using entry_type = std::pair<scalefactor2x_ratio_type, bu_abbrev_type>
-
using native_scale_v = std::array<entry_type, max_bu_per_dim>
-
using entry_type = std::pair<scalefactor2x_ratio_type, bu_abbrev_type>
- group bu-dim-store instance vars
Constants
Provides dictionary of unit abbreviations
Application code is not expected to interact directly with bu_abbrev_store.
Functions
-
bu_abbrev_type xo::qty::bu_abbrev(const basis_unit &bu)
get abbreviation for basis-unit
bu
For example:
#include <xo/unit/bu_store.hpp>
namespace bu = xo::qty::bu;
using xo::qty::bu_abbrev;
using xo::flatstring;
static_assert(bu_abbrev(bu::kilogram) == xo::flatstring("kg"));