diff --git a/include/xo/unit/basis_unit.hpp b/include/xo/unit/basis_unit.hpp index d8a28f65..a32ee865 100644 --- a/include/xo/unit/basis_unit.hpp +++ b/include/xo/unit/basis_unit.hpp @@ -4,10 +4,15 @@ #include "dimension.hpp" #include "basis_unit_abbrev.hpp" +//#include "bpu_store.hpp" #include "xo/ratio/ratio.hpp" namespace xo { namespace qty { + using bu_abbrev_type = flatstring<16>; + using scalefactor_ratio_type = xo::ratio::ratio; + using scalefactor2x_ratio_type = xo::ratio::ratio<__int128>; + /** @class basis_unit * @brief A dimensionless multiple of a single natively-specified basis dimension * @@ -31,12 +36,13 @@ namespace xo { constexpr const scalefactor_ratio_type & scalefactor() const { return scalefactor_; } ///@} - constexpr bu_abbrev_type abbrev() const { - return abbrev::basis_unit2_abbrev(native_dim_, - scalefactor_); +#ifdef OBSOLETE // use bu_abbrev(bu) + constexpr bu_abbrev_type abbrev() const { + return basis_unit2_abbrev(native_dim_, scalefactor_); } +#endif - public: /* need public members so that a basis_unit instance can be a non-type template parameter (a structural type) */ + public: /* public so instance can be a non-type template parameter (a structural type) */ /** @defgroup basis-unit-instance-vars **/ ///@{ /** @brief identifies a native unit, e.g. time (in seconds) **/ @@ -172,7 +178,6 @@ namespace xo { } /*namespace bu*/ } /*namespace detail*/ - namespace units { /** for runtime work, would like to be able to promptly find special abbreviation * keyed by (native_dim, scalefactor). diff --git a/include/xo/unit/basis_unit_abbrev.hpp b/include/xo/unit/basis_unit_abbrev.hpp index 43fe9b0c..55fe2b54 100644 --- a/include/xo/unit/basis_unit_abbrev.hpp +++ b/include/xo/unit/basis_unit_abbrev.hpp @@ -11,10 +11,14 @@ namespace xo { namespace qty { +#ifdef OBSOLETE using bu_abbrev_type = flatstring<16>; using scalefactor_ratio_type = xo::ratio::ratio; + using scalefactor2x_ratio_type = xo::ratio::ratio<__int128>; + #endif namespace abbrev { +#ifdef OBSOLETE static constexpr bu_abbrev_type fallback_unit_abbrev(const scalefactor_ratio_type & scalefactor, @@ -237,6 +241,7 @@ namespace xo { return bu_abbrev_type(); } +#endif } /*namespace abbrev*/ } /*namespace qty*/ } /*namespace xo*/ diff --git a/include/xo/unit/bpu.hpp b/include/xo/unit/bpu.hpp index 8c175812..85f5a506 100644 --- a/include/xo/unit/bpu.hpp +++ b/include/xo/unit/bpu.hpp @@ -6,13 +6,10 @@ #pragma once #include "basis_unit.hpp" +#include "bpu_store.hpp" namespace xo { namespace qty { - using bpu_abbrev_type = flatstring<24>; - - using power_ratio_type = xo::ratio::ratio; - namespace abbrev { using power_abbrev_type = flatstring<16>; @@ -43,7 +40,7 @@ namespace xo { { return (bpu_abbrev_type::from_flatstring (flatstring_concat - (basis_unit2_abbrev(native_dim, scalefactor), + (bu_abbrev(basis_unit(native_dim, scalefactor)), flatstring_from_exponent(power.num(), power.den())))); } } diff --git a/include/xo/unit/bpu_store.hpp b/include/xo/unit/bpu_store.hpp index 4298d977..64632b5b 100644 --- a/include/xo/unit/bpu_store.hpp +++ b/include/xo/unit/bpu_store.hpp @@ -2,137 +2,56 @@ #pragma once -#include "bpu.hpp" -#include +//#include "bpu.hpp" +#include "basis_unit.hpp" +#include "xo/ratio/ratio.hpp" +#include +#include namespace xo { namespace qty { - /** @class basis_unit2_store - * @brief Store known basis units for runtime - **/ - template - struct basis_unit2_store { - basis_unit2_store() : bu_abbrev_vv_(static_cast(dim::n_dim)) { - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); + using bpu_abbrev_type = flatstring<24>; - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); + using power_ratio_type = xo::ratio::ratio; - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); - this->bu_establish_abbrev_for(); + struct bu_dim_store { + /** max number of basis-units per dimension **/ + static constexpr std::size_t max_bu_per_dim = 25; - this->bu_establish_abbrev_for(); - - this->bu_establish_abbrev_for(); - } + using entry_type = std::pair; /* e.g. * [(1/1000000000, "nm"), (1/1000000, "um"), (1/1000, "mm"), (1/1, "m"), (1000/1, "km")] */ - using native_scale_v = std::vector>; + using native_scale_v = std::array; - /** @brief get basis-unit abbreviation at runtime **/ - bu_abbrev_type bu_abbrev(dim basis_dim, - const scalefactor_ratio_type & scalefactor) const - { - const auto & bu_abbrev_v = bu_abbrev_vv_[static_cast(basis_dim)]; + public: + constexpr bu_dim_store() = default; - std::size_t i_abbrev = bu_abbrev_lub_ix(basis_dim, scalefactor, bu_abbrev_v); + constexpr bool empty() const { return n_bu_ == 0; } + constexpr std::size_t size() const { return n_bu_; } - if ((i_abbrev < bu_abbrev_v.size()) - && (bu_abbrev_v[i_abbrev].first == scalefactor)) - { - return bu_abbrev_v[i_abbrev].second; - } else { - return units::bu_fallback_abbrev(basis_dim, scalefactor); - } - } + constexpr const entry_type & operator[](std::size_t i) const { return bu_abbrev_v_[i]; } - /** @brief get basis-power-unit abbreviation at runtime **/ - bpu_abbrev_type bpu_abbrev(dim basis_dim, - const scalefactor_ratio_type & scalefactor, - const power_ratio_type & power) - { - return abbrev::bpu_abbrev(basis_dim, - scalefactor, - power); - } - - template - void bu_establish_abbrev_for() { - this->bu_establish_abbrev - (basis_unit(BasisDim, - scalefactor_ratio_type(InnerScaleNum, InnerScaleDen)), - abbrev::basis_unit2_abbrev(BasisDim, scalefactor_ratio_type(InnerScaleNum, InnerScaleDen))); - } - - /** @brief establish abbreviation @p abbrev for basis unit @p bu - **/ - void bu_establish_abbrev(const basis_unit & bu, - const bu_abbrev_type & abbrev) { - - auto & bu_abbrev_v = bu_abbrev_vv_[static_cast(bu.native_dim())]; - - std::int32_t i_abbrev = 0; - - if (!bu_abbrev_v.empty()) { - i_abbrev = bu_abbrev_lub_ix(bu.native_dim(), - bu.scalefactor(), - bu_abbrev_v); - } - - auto entry = std::make_pair(bu.scalefactor(), abbrev); - - if ((i_abbrev < bu_abbrev_v.size()) - && (bu_abbrev_v[i_abbrev].first == bu.scalefactor())) - { - bu_abbrev_v[i_abbrev] = entry; - } else { - bu_abbrev_v.insert(bu_abbrev_v.begin() + i_abbrev, entry); - } - } - - private: /** @brief get least-upper-bound index position in bu_abbrev_v[] * - * return value in [0, n] where n = bu_abbrev_v.size() + * return value in [0, n] where n = .size() **/ - static std::size_t bu_abbrev_lub_ix(dim basis_dim, - const scalefactor_ratio_type & scalefactor, - const native_scale_v & bu_abbrev_v) + constexpr std::size_t abbrev_lub_ix(const scalefactor_ratio_type & scalefactor) const { - std::size_t n = bu_abbrev_v.size(); - - if (n == 0) + if (n_bu_ == 0) return 0; std::size_t lo = 0; - std::size_t hi = n-1; + std::size_t hi = n_bu_-1; - if (scalefactor <= bu_abbrev_v[lo].first) + if (scalefactor <= bu_abbrev_v_[lo].first) return 0; - auto cmp = (scalefactor <=> bu_abbrev_v[hi].first); + auto cmp = (scalefactor <=> bu_abbrev_v_[hi].first); if (cmp > 0) - return n; + return n_bu_; if (cmp == 0) return hi; @@ -144,7 +63,7 @@ namespace xo { std::size_t mid = lo + (hi - lo)/2; - if (scalefactor > bu_abbrev_v[mid].first) + if (scalefactor > bu_abbrev_v_[mid].first) lo = mid; else hi = mid; @@ -153,10 +72,167 @@ namespace xo { return hi; } - private: - /* bu_abbrev_v[dim] holds known units for native unit dim */ - std::vector bu_abbrev_vv_; + constexpr void insert_aux(std::size_t ix, + const entry_type & entry) + { + + if (n_bu_ >= max_bu_per_dim) + return; + + ++n_bu_; + + for (std::size_t dest_ix = n_bu_; dest_ix > ix; --dest_ix) + bu_abbrev_v_[dest_ix] = bu_abbrev_v_[dest_ix - 1]; + + bu_abbrev_v_[ix] = entry; + } + + /** @brief establish abbreviation @p abbrev for basis unit @p bu + **/ + constexpr void bu_establish_abbrev(const scalefactor_ratio_type & scalefactor, + const bu_abbrev_type & abbrev) + { + + std::int32_t i_abbrev = this->abbrev_lub_ix(scalefactor); + + auto entry = std::make_pair(scalefactor, abbrev); + + if ((i_abbrev < bu_abbrev_v_.size()) + && (bu_abbrev_v_[i_abbrev].first == scalefactor)) + { + bu_abbrev_v_[i_abbrev] = entry; + } else { + this->insert_aux(i_abbrev, entry); + } + } + + public: + std::size_t n_bu_ = 0; + std::array bu_abbrev_v_; }; + + /** @class basis_unit2_store + * @brief Store known basis units for runtime + **/ + //template + struct basis_unit2_store { + constexpr basis_unit2_store() { + // ----- mass ----- + + this->bu_establish_abbrev(detail::bu::picogram, bu_abbrev_type::from_chars("pg")); + this->bu_establish_abbrev(detail::bu::nanogram, bu_abbrev_type::from_chars("ng")); + this->bu_establish_abbrev(detail::bu::microgram, bu_abbrev_type::from_chars("ug")); + this->bu_establish_abbrev(detail::bu::milligram, bu_abbrev_type::from_chars("mg")); + this->bu_establish_abbrev(detail::bu::gram, bu_abbrev_type::from_chars("g")); + this->bu_establish_abbrev(detail::bu::kilogram, bu_abbrev_type::from_chars("kg")); + this->bu_establish_abbrev(detail::bu::tonne, bu_abbrev_type::from_chars("t")); + this->bu_establish_abbrev(detail::bu::kilotonne, bu_abbrev_type::from_chars("kt")); + this->bu_establish_abbrev(detail::bu::megatonne, bu_abbrev_type::from_chars("Mt")); + this->bu_establish_abbrev(detail::bu::gigatonne, bu_abbrev_type::from_chars("Gt")); + + // ----- distance ----- + + this->bu_establish_abbrev(detail::bu::picometer, bu_abbrev_type::from_chars("pm")); + this->bu_establish_abbrev(detail::bu::nanometer, bu_abbrev_type::from_chars("nm")); + this->bu_establish_abbrev(detail::bu::micrometer, bu_abbrev_type::from_chars("um")); + this->bu_establish_abbrev(detail::bu::millimeter, bu_abbrev_type::from_chars("mm")); + this->bu_establish_abbrev(detail::bu::meter, bu_abbrev_type::from_chars("m")); + this->bu_establish_abbrev(detail::bu::kilometer, bu_abbrev_type::from_chars("km")); + this->bu_establish_abbrev(detail::bu::megameter, bu_abbrev_type::from_chars("Mm")); + this->bu_establish_abbrev(detail::bu::gigameter, bu_abbrev_type::from_chars("Gm")); + + this->bu_establish_abbrev(detail::bu::lightsecond, bu_abbrev_type::from_chars("lsec")); + this->bu_establish_abbrev(detail::bu::astronomicalunit, bu_abbrev_type::from_chars("AU")); + + this->bu_establish_abbrev(detail::bu::inch, bu_abbrev_type::from_chars("in")); + this->bu_establish_abbrev(detail::bu::foot, bu_abbrev_type::from_chars("ft")); + this->bu_establish_abbrev(detail::bu::yard, bu_abbrev_type::from_chars("yd")); + this->bu_establish_abbrev(detail::bu::mile, bu_abbrev_type::from_chars("mi")); + + // ----- time ----- + + this->bu_establish_abbrev(detail::bu::picosecond, bu_abbrev_type::from_chars("ps")); + this->bu_establish_abbrev(detail::bu::nanosecond, bu_abbrev_type::from_chars("ns")); + this->bu_establish_abbrev(detail::bu::microsecond, bu_abbrev_type::from_chars("us")); + this->bu_establish_abbrev(detail::bu::millisecond, bu_abbrev_type::from_chars("ms")); + this->bu_establish_abbrev(detail::bu::second, bu_abbrev_type::from_chars("s")); + this->bu_establish_abbrev(detail::bu::minute, bu_abbrev_type::from_chars("min")); + this->bu_establish_abbrev(detail::bu::hour, bu_abbrev_type::from_chars("hr")); + this->bu_establish_abbrev(detail::bu::day, bu_abbrev_type::from_chars("dy")); + this->bu_establish_abbrev(detail::bu::week, bu_abbrev_type::from_chars("wk")); + this->bu_establish_abbrev(detail::bu::month, bu_abbrev_type::from_chars("mo")); + this->bu_establish_abbrev(detail::bu::year250, bu_abbrev_type::from_chars("yr250")); + this->bu_establish_abbrev(detail::bu::year, bu_abbrev_type::from_chars("yr")); + this->bu_establish_abbrev(detail::bu::year360, bu_abbrev_type::from_chars("yr360")); + this->bu_establish_abbrev(detail::bu::year365, bu_abbrev_type::from_chars("yr365")); + + // ----- misc (currency, price) ----- + + this->bu_establish_abbrev(detail::bu::currency, bu_abbrev_type::from_chars("ccy")); + this->bu_establish_abbrev(detail::bu::price, bu_abbrev_type::from_chars("px")); + //this->bu_establish_abbrev_for(); + } + + /** @brief get basis-unit abbreviation at runtime **/ + constexpr bu_abbrev_type bu_abbrev(dim basis_dim, + const scalefactor_ratio_type & scalefactor) const + { + const auto & bu_abbrev_v = bu_abbrev_vv_[static_cast(basis_dim)]; + + std::size_t i_abbrev = bu_abbrev_v.abbrev_lub_ix(scalefactor); + + if ((i_abbrev < bu_abbrev_v.size()) + && (bu_abbrev_v[i_abbrev].first == scalefactor)) + { + return bu_abbrev_v[i_abbrev].second; + } else { + return units::bu_fallback_abbrev(basis_dim, scalefactor); + } + } + +#ifdef OBSOLETE + /** @brief get basis-power-unit abbreviation at runtime **/ + bpu_abbrev_type bpu_abbrev(dim basis_dim, + const scalefactor_ratio_type & scalefactor, + const power_ratio_type & power) + { + return abbrev::bpu_abbrev(basis_dim, + scalefactor, + power); + } +#endif + +#ifdef OBSOLETE + template + void bu_establish_abbrev_for() { + this->bu_establish_abbrev + (basis_unit(BasisDim, + scalefactor_ratio_type(InnerScaleNum, InnerScaleDen)), + abbrev::basis_unit2_abbrev(BasisDim, scalefactor_ratio_type(InnerScaleNum, InnerScaleDen))); + } +#endif + + constexpr void bu_establish_abbrev(const basis_unit & bu, + const bu_abbrev_type & abbrev) { + auto & dim_store = bu_abbrev_vv_[static_cast(bu.native_dim_)]; + + dim_store.bu_establish_abbrev(bu.scalefactor_, abbrev); + } + + private: + + public: + /** **/ + std::array bu_abbrev_vv_; + }; + + static constexpr basis_unit2_store bu_abbrev_store = basis_unit2_store(); + + constexpr bu_abbrev_type + bu_abbrev(const basis_unit & bu) + { + return bu_abbrev_store.bu_abbrev(bu.native_dim(), bu.scalefactor()); + } } /*namespace qty*/ } /*namespace xo*/ diff --git a/utest/basis_unit.test.cpp b/utest/basis_unit.test.cpp index cc9191f4..bb5fd165 100644 --- a/utest/basis_unit.test.cpp +++ b/utest/basis_unit.test.cpp @@ -1,13 +1,14 @@ /* @file bu.test.cpp */ #include "xo/unit/basis_unit.hpp" +#include "xo/unit/bpu_store.hpp" #include "xo/indentlog/scope.hpp" //#include "xo/indentlog/print/tag.hpp" #include namespace xo { using xo::qty::scalefactor_ratio_type; - using xo::qty::abbrev::basis_unit2_abbrev; + using xo::qty::bu_abbrev; using xo::qty::basis_unit; using xo::qty::bu_abbrev_type; using xo::qty::native_unit2_v; @@ -21,11 +22,11 @@ namespace xo { * we will need this for quantity> */ template - constexpr bu_abbrev_type bu_mpl_abbrev = bu.abbrev(); + constexpr bu_abbrev_type bu_mpl_abbrev = bu_abbrev(bu); TEST_CASE("basis_unit", "[basis_unit]") { - static_assert(bu_mpl_abbrev == bu::gram.abbrev()); - REQUIRE(bu_mpl_abbrev == bu::gram.abbrev()); + static_assert(bu_mpl_abbrev == bu_abbrev(bu::gram)); + REQUIRE(bu_mpl_abbrev == bu_abbrev(bu::gram)); } /*TEST_CASE(basis_unit)*/ TEST_CASE("basis_unit1", "[basis_unit]") { @@ -39,9 +40,9 @@ namespace xo { static_assert(native_unit2_v[static_cast(dim::currency)].native_dim() == dim::currency); static_assert(native_unit2_v[static_cast(dim::price)].native_dim() == dim::price); - log && log(xtag("mass*10^3", basis_unit2_abbrev(dim::mass, scalefactor_ratio_type(1000, 1)))); + log && log(xtag("mass*10^3", bu_abbrev(bu::kilogram))); - static_assert(basis_unit2_abbrev(dim::mass, scalefactor_ratio_type(1000, 1)) + static_assert(bu_abbrev(bu::kilogram) == bu_abbrev_type::from_chars("kg")); log && log("---------------------"); @@ -50,97 +51,97 @@ namespace xo { # define REQUIRE_x2(x) static_assert(x); REQUIRE(x) - log && log(xtag("mass", basis_unit2_abbrev(dim::distance, scalefactor_ratio_type(1, 1)))); + log && log(xtag("mass", bu_abbrev(bu::meter))); - REQUIRE_x2(bu::picogram.abbrev() == bu_abbrev_type::from_chars("pg")); - REQUIRE_x2(bu::nanogram.abbrev() + REQUIRE_x2(bu_abbrev(bu::picogram) == bu_abbrev_type::from_chars("pg")); + REQUIRE_x2(bu_abbrev(bu::nanogram) == bu_abbrev_type::from_chars("ng")); - REQUIRE_x2(bu::microgram.abbrev() + REQUIRE_x2(bu_abbrev(bu::microgram) == bu_abbrev_type::from_chars("ug")); - REQUIRE_x2(bu::milligram.abbrev() + REQUIRE_x2(bu_abbrev(bu::milligram) == bu_abbrev_type::from_chars("mg")); - REQUIRE_x2(bu::gram.abbrev() + REQUIRE_x2(bu_abbrev(bu::gram) == bu_abbrev_type::from_chars("g")); - REQUIRE_x2(bu::kilogram.abbrev() + REQUIRE_x2(bu_abbrev(bu::kilogram) == bu_abbrev_type::from_chars("kg")); - REQUIRE_x2(bu::tonne.abbrev() + REQUIRE_x2(bu_abbrev(bu::tonne) == bu_abbrev_type::from_chars("t")); - REQUIRE_x2(bu::kilotonne.abbrev() + REQUIRE_x2(bu_abbrev(bu::kilotonne) == bu_abbrev_type::from_chars("kt")); - REQUIRE_x2(bu::megatonne.abbrev() + REQUIRE_x2(bu_abbrev(bu::megatonne) == bu_abbrev_type::from_chars("Mt")); - REQUIRE_x2(bu::gigatonne.abbrev() + REQUIRE_x2(bu_abbrev(bu::gigatonne) == bu_abbrev_type::from_chars("Gt")); - log && log(xtag("distance", basis_unit2_abbrev(dim::distance, scalefactor_ratio_type(1, 1)))); + log && log(xtag("distance", bu_abbrev(bu::meter))); - REQUIRE_x2(bu::picometre.abbrev() + REQUIRE_x2(bu_abbrev(bu::picometre) == bu_abbrev_type::from_chars("pm")); - REQUIRE_x2(bu::nanometre.abbrev() + REQUIRE_x2(bu_abbrev(bu::nanometre) == bu_abbrev_type::from_chars("nm")); - REQUIRE_x2(bu::micrometre.abbrev() + REQUIRE_x2(bu_abbrev(bu::micrometre) == bu_abbrev_type::from_chars("um")); - REQUIRE_x2(bu::millimetre.abbrev() + REQUIRE_x2(bu_abbrev(bu::millimetre) == bu_abbrev_type::from_chars("mm")); - REQUIRE_x2(bu::metre.abbrev() + REQUIRE_x2(bu_abbrev(bu::metre) == bu_abbrev_type::from_chars("m")); - REQUIRE_x2(bu::kilometre.abbrev() + REQUIRE_x2(bu_abbrev(bu::kilometre) == bu_abbrev_type::from_chars("km")); - REQUIRE_x2(bu::megametre.abbrev() + REQUIRE_x2(bu_abbrev(bu::megametre) == bu_abbrev_type::from_chars("Mm")); - REQUIRE_x2(bu::gigametre.abbrev() + REQUIRE_x2(bu_abbrev(bu::gigametre) == bu_abbrev_type::from_chars("Gm")); - REQUIRE_x2(bu::picometer.abbrev() + REQUIRE_x2(bu_abbrev(bu::picometer) == bu_abbrev_type::from_chars("pm")); - REQUIRE_x2(bu::nanometer.abbrev() + REQUIRE_x2(bu_abbrev(bu::nanometer) == bu_abbrev_type::from_chars("nm")); - REQUIRE_x2(bu::micrometer.abbrev() + REQUIRE_x2(bu_abbrev(bu::micrometer) == bu_abbrev_type::from_chars("um")); - REQUIRE_x2(bu::millimeter.abbrev() + REQUIRE_x2(bu_abbrev(bu::millimeter) == bu_abbrev_type::from_chars("mm")); - REQUIRE_x2(bu::meter.abbrev() + REQUIRE_x2(bu_abbrev(bu::meter) == bu_abbrev_type::from_chars("m")); - REQUIRE_x2(bu::kilometer.abbrev() + REQUIRE_x2(bu_abbrev(bu::kilometer) == bu_abbrev_type::from_chars("km")); - REQUIRE_x2(bu::megameter.abbrev() + REQUIRE_x2(bu_abbrev(bu::megameter) == bu_abbrev_type::from_chars("Mm")); - REQUIRE_x2(bu::gigameter.abbrev() + REQUIRE_x2(bu_abbrev(bu::gigameter) == bu_abbrev_type::from_chars("Gm")); - REQUIRE_x2(bu::lightsecond.abbrev() == flatstring("lsec")); - REQUIRE_x2(bu::astronomicalunit.abbrev() == flatstring("AU")); + REQUIRE_x2(bu_abbrev(bu::lightsecond) == flatstring("lsec")); + REQUIRE_x2(bu_abbrev(bu::astronomicalunit) == flatstring("AU")); - REQUIRE_x2(bu::inch.abbrev() == flatstring("in")); - REQUIRE_x2(bu::foot.abbrev() == flatstring("ft")); - REQUIRE_x2(bu::yard.abbrev() == flatstring("yd")); - REQUIRE_x2(bu::mile.abbrev() == flatstring("mi")); + REQUIRE_x2(bu_abbrev(bu::inch) == flatstring("in")); + REQUIRE_x2(bu_abbrev(bu::foot) == flatstring("ft")); + REQUIRE_x2(bu_abbrev(bu::yard) == flatstring("yd")); + REQUIRE_x2(bu_abbrev(bu::mile) == flatstring("mi")); - log && log(xtag("time", basis_unit2_abbrev(dim::time, scalefactor_ratio_type(1, 1)))); + log && log(xtag("time", bu_abbrev(bu::second))); - REQUIRE_x2(bu::picosecond.abbrev() == bu_abbrev_type::from_chars("ps")); - REQUIRE_x2(bu::nanosecond.abbrev() == bu_abbrev_type::from_chars("ns")); - REQUIRE_x2(bu::microsecond.abbrev() == bu_abbrev_type::from_chars("us")); - REQUIRE_x2(bu::millisecond.abbrev() == bu_abbrev_type::from_chars("ms")); - REQUIRE_x2(bu::second.abbrev() == bu_abbrev_type::from_chars("s")); - REQUIRE_x2(bu::minute.abbrev() == bu_abbrev_type::from_chars("min")); - REQUIRE_x2(bu::hour.abbrev() == bu_abbrev_type::from_chars("hr")); - REQUIRE_x2(bu::day.abbrev() == bu_abbrev_type::from_chars("dy")); - REQUIRE_x2(bu::week.abbrev() == bu_abbrev_type::from_chars("wk")); - REQUIRE_x2(bu::month.abbrev() == bu_abbrev_type::from_chars("mo")); + REQUIRE_x2(bu_abbrev(bu::picosecond) == bu_abbrev_type::from_chars("ps")); + REQUIRE_x2(bu_abbrev(bu::nanosecond) == bu_abbrev_type::from_chars("ns")); + REQUIRE_x2(bu_abbrev(bu::microsecond) == bu_abbrev_type::from_chars("us")); + REQUIRE_x2(bu_abbrev(bu::millisecond) == bu_abbrev_type::from_chars("ms")); + REQUIRE_x2(bu_abbrev(bu::second) == bu_abbrev_type::from_chars("s")); + REQUIRE_x2(bu_abbrev(bu::minute) == bu_abbrev_type::from_chars("min")); + REQUIRE_x2(bu_abbrev(bu::hour) == bu_abbrev_type::from_chars("hr")); + REQUIRE_x2(bu_abbrev(bu::day) == bu_abbrev_type::from_chars("dy")); + REQUIRE_x2(bu_abbrev(bu::week) == bu_abbrev_type::from_chars("wk")); + REQUIRE_x2(bu_abbrev(bu::month) == bu_abbrev_type::from_chars("mo")); - REQUIRE_x2(bu::year.abbrev() == bu_abbrev_type::from_chars("yr")); - REQUIRE_x2(bu::year250.abbrev() == bu_abbrev_type::from_chars("yr250")); - REQUIRE_x2(bu::year360.abbrev() == bu_abbrev_type::from_chars("yr360")); - REQUIRE_x2(bu::year365.abbrev() == bu_abbrev_type::from_chars("yr365")); + REQUIRE_x2(bu_abbrev(bu::year) == bu_abbrev_type::from_chars("yr")); + REQUIRE_x2(bu_abbrev(bu::year250) == bu_abbrev_type::from_chars("yr250")); + REQUIRE_x2(bu_abbrev(bu::year360) == bu_abbrev_type::from_chars("yr360")); + REQUIRE_x2(bu_abbrev(bu::year365) == bu_abbrev_type::from_chars("yr365")); - log && log(xtag("currency", basis_unit2_abbrev(dim::currency, scalefactor_ratio_type(1, 1)))); + log && log(xtag("currency", bu_abbrev(bu::currency))); - REQUIRE_x2(bu::currency.abbrev() == flatstring("ccy")); + REQUIRE_x2(bu_abbrev(bu::currency) == flatstring("ccy")); - log && log(xtag("price", basis_unit2_abbrev(dim::price, scalefactor_ratio_type(1, 1)))); + log && log(xtag("price", bu_abbrev(bu::price))); - REQUIRE_x2(bu::price.abbrev() == flatstring("px")); + REQUIRE_x2(bu_abbrev(bu::price) == flatstring("px")); # undef REQUIRE_x2 diff --git a/utest/unit.test.cpp b/utest/unit.test.cpp index b2d9b0eb..f479c6fc 100644 --- a/utest/unit.test.cpp +++ b/utest/unit.test.cpp @@ -12,8 +12,6 @@ namespace xo { namespace ut { /* compile-time tests */ - namespace u = xo::qty::u; - using xo::qty::dim; using xo::qty::bu_abbrev_type; using xo::qty::scalefactor_ratio_type; @@ -32,7 +30,7 @@ namespace xo { scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.basis_unit2_store")); //log && log("(A)", xtag("foo", foo)); - basis_unit2_store bu_store; + basis_unit2_store/**/ bu_store; log && log(xtag("mass*10^-9", bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000000)))); log && log(xtag("mass*10^-6", bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000))));