xo-unit: refactor: bpu_store.hpp -> bu_store.hpp for consistency

This commit is contained in:
Roland Conybeare 2024-05-08 16:48:10 -04:00
commit 6ab163b2ea
4 changed files with 59 additions and 83 deletions

View file

@ -6,7 +6,7 @@
#pragma once
#include "basis_unit.hpp"
#include "bpu_store.hpp"
#include "bu_store.hpp"
namespace xo {
namespace qty {

View file

@ -1,4 +1,4 @@
/** @file bpu_store.hpp **/
/** @file bu_store.hpp **/
#pragma once
@ -115,8 +115,8 @@ namespace xo {
* @brief Store known basis units for runtime
**/
//template <typename Tag>
struct basis_unit2_store {
constexpr basis_unit2_store() {
struct bu_store {
constexpr bu_store() {
// ----- mass -----
this->bu_establish_abbrev(detail::bu::picogram, bu_abbrev_type::from_chars("pg"));
@ -190,28 +190,6 @@ namespace xo {
}
}
#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 <dim BasisDim, std::int64_t InnerScaleNum, std::int64_t InnerScaleDen>
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<std::size_t>(bu.native_dim_)];
@ -226,7 +204,7 @@ namespace xo {
std::array<bu_dim_store, n_dim> bu_abbrev_vv_;
};
static constexpr basis_unit2_store bu_abbrev_store = basis_unit2_store();
static constexpr bu_store bu_abbrev_store = bu_store();
constexpr bu_abbrev_type
bu_abbrev(const basis_unit & bu)
@ -236,4 +214,4 @@ namespace xo {
} /*namespace qty*/
} /*namespace xo*/
/** end bpu_store.hpp **/
/** end bu_store.hpp **/

View file

@ -1,7 +1,7 @@
/* @file bu.test.cpp */
#include "xo/unit/basis_unit.hpp"
#include "xo/unit/bpu_store.hpp"
#include "xo/unit/bu_store.hpp"
#include "xo/indentlog/scope.hpp"
//#include "xo/indentlog/print/tag.hpp"
#include <catch2/catch.hpp>

View file

@ -2,7 +2,7 @@
#include "xo/unit/scaled_unit_iostream.hpp"
//#include "xo/unit/scaled_unit.hpp"
#include "xo/unit/bpu_store.hpp"
#include "xo/unit/bu_store.hpp"
#include "xo/unit/bpu.hpp"
#include "xo/indentlog/scope.hpp"
#include "xo/indentlog/print/tag.hpp"
@ -12,11 +12,11 @@ namespace xo {
namespace ut {
/* compile-time tests */
using xo::qty::dim;
using xo::qty::bu_abbrev_store;
using xo::qty::bu_abbrev_type;
using xo::qty::scalefactor_ratio_type;
using xo::qty::basis_unit2_store;
using xo::qty::power_ratio_type;
using xo::qty::dim;
TEST_CASE("basis_unit2_store", "[basis_unit2_store]") {
constexpr bool c_debug_flag = false;
@ -30,57 +30,55 @@ namespace xo {
scope log(XO_DEBUG2(c_debug_flag, "TEST_CASE.basis_unit2_store"));
//log && log("(A)", xtag("foo", foo));
basis_unit2_store/*<class AnyTag>*/ bu_store;
log && log(xtag("mass*10^-9", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000000))));
log && log(xtag("mass*10^-6", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000))));
log && log(xtag("mass*10^-3", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000))));
log && log(xtag("mass", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1))));
log && log(xtag("mass*10^3", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000, 1))));
log && log(xtag("mass*10^6", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000, 1))));
log && log(xtag("mass*10^9", bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000000, 1))));
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))));
log && log(xtag("mass*10^-3", bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000))));
log && log(xtag("mass", bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1))));
log && log(xtag("mass*10^3", bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000, 1))));
log && log(xtag("mass*10^6", bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000, 1))));
log && log(xtag("mass*10^9", bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000000, 1))));
log && log(xtag("distance*10^-9", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000000))));
log && log(xtag("distance*10^-6", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000))));
log && log(xtag("distance*10^-3", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000))));
log && log(xtag("distance", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1))));
log && log(xtag("distance*10^3", bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1000, 1))));
log && log(xtag("distance*10^-9", bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000000))));
log && log(xtag("distance*10^-6", bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000))));
log && log(xtag("distance*10^-3", bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000))));
log && log(xtag("distance", bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1))));
log && log(xtag("distance*10^3", bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1000, 1))));
log && log(xtag("time*10^-9", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000000))));
log && log(xtag("time*10^-6", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000))));
log && log(xtag("time*10^-3", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000))));
log && log(xtag("time", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1))));
log && log(xtag("time*60", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 60, 1))));
log && log(xtag("time*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 3600, 1))));
log && log(xtag("time*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 24*3600, 1))));
log && log(xtag("time*250*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(250*24*3600, 1))));
log && log(xtag("time*360*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(360*24*3600, 1))));
log && log(xtag("time*365*24*3600", bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(365*24*3600, 1))));
log && log(xtag("time*10^-9", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000000))));
log && log(xtag("time*10^-6", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000))));
log && log(xtag("time*10^-3", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000))));
log && log(xtag("time", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1))));
log && log(xtag("time*60", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 60, 1))));
log && log(xtag("time*3600", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 3600, 1))));
log && log(xtag("time*24*3600", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 24*3600, 1))));
log && log(xtag("time*250*24*3600", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type(250*24*3600, 1))));
log && log(xtag("time*360*24*3600", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type(360*24*3600, 1))));
log && log(xtag("time*365*24*3600", bu_store.bu_abbrev(dim::time, scalefactor_ratio_type(365*24*3600, 1))));
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000000)).c_str(), "ng") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000)).c_str(), "ug") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000)).c_str(), "mg") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1)).c_str(), "g") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000, 1)).c_str(), "kg") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000, 1)).c_str(), "t") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000000, 1)).c_str(), "kt") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000000)).c_str(), "ng") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000000)).c_str(), "ug") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1000)).c_str(), "mg") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1, 1)).c_str(), "g") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000, 1)).c_str(), "kg") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000, 1)).c_str(), "t") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::mass, scalefactor_ratio_type( 1000000000, 1)).c_str(), "kt") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000000)).c_str(), "nm") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000)).c_str(), "um") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000)).c_str(), "mm") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1)).c_str(), "m") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1000, 1)).c_str(), "km") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000000)).c_str(), "nm") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000000)).c_str(), "um") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1000)).c_str(), "mm") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1, 1)).c_str(), "m") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::distance, scalefactor_ratio_type( 1000, 1)).c_str(), "km") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000000)).c_str(), "ns") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000)).c_str(), "us") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000)).c_str(), "ms") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1)).c_str(), "s") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 60, 1)).c_str(), "min") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 3600, 1)).c_str(), "hr") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type( 24*3600, 1)).c_str(), "dy") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type(250*24*3600, 1)).c_str(), "yr250") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type(360*24*3600, 1)).c_str(), "yr360") == 0);
REQUIRE(::strcmp(bu_store.bu_abbrev(dim::time, scalefactor_ratio_type(365*24*3600, 1)).c_str(), "yr365") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000000)).c_str(), "ns") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000000)).c_str(), "us") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1000)).c_str(), "ms") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 1, 1)).c_str(), "s") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 60, 1)).c_str(), "min") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 3600, 1)).c_str(), "hr") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type( 24*3600, 1)).c_str(), "dy") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(250*24*3600, 1)).c_str(), "yr250") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(360*24*3600, 1)).c_str(), "yr360") == 0);
REQUIRE(::strcmp(bu_abbrev_store.bu_abbrev(dim::time, scalefactor_ratio_type(365*24*3600, 1)).c_str(), "yr365") == 0);
} /*TEST_CASE(basis_unit2_store)*/