xo-unit: refactor: bpu2_abbrev_type -> bpu_abbrev_type

This commit is contained in:
Roland Conybeare 2024-04-22 20:35:20 -04:00
commit d1938abd15
3 changed files with 17 additions and 33 deletions

View file

@ -1,4 +1,4 @@
/** @file native_bpu2.hpp
/** @file bpu.hpp
*
* Author: Roland Conybeare
**/
@ -11,7 +11,7 @@
namespace xo {
namespace qty {
using bpu2_abbrev_type = flatstring<24>;
using bpu_abbrev_type = flatstring<24>;
using power_ratio_type = xo::ratio::ratio<std::int64_t>;
@ -38,12 +38,12 @@ namespace xo {
}
}
static constexpr bpu2_abbrev_type
static constexpr bpu_abbrev_type
bpu2_abbrev(dim native_dim,
const scalefactor_ratio_type & scalefactor,
const power_ratio_type & power)
{
return (bpu2_abbrev_type::from_flatstring
return (bpu_abbrev_type::from_flatstring
(flatstring_concat
(basis_unit2_abbrev(native_dim, scalefactor),
flatstring_from_exponent(power.num(), power.den()))));
@ -90,7 +90,7 @@ namespace xo {
* power_ratio_type(-2,1)).abbrev() => "min^-2"
* @endcode
**/
constexpr bpu2_abbrev_type abbrev() const
constexpr bpu_abbrev_type abbrev() const
{
return abbrev::bpu2_abbrev(native_dim_,
scalefactor_,
@ -111,23 +111,7 @@ namespace xo {
return bpu<Int>::unit_power(bu);
}
#ifdef NOT_USING
template <
dim BasisDim,
std::int64_t InnerScaleNum, std::int64_t InnerScaleDen,
std::int64_t PowerNum, std::int64_t PowerDen
>
constexpr bpu2_abbrev_type
bpu2_assemble_abbrev_helper()
{
return (bpu2_abbrev_type::from_flatstring
(flatstring_concat
(units::scaled_native_unit2_abbrev_v<BasisDim, InnerScaleNum, InnerScaleDen>,
flatstring_from_exponent<PowerNum, PowerDen>())));
};
#endif
} /*namespace qty*/
} /*namespace xo*/
/** end native_bpu2.hpp **/
/** end bpu.hpp **/

View file

@ -65,7 +65,7 @@ namespace xo {
}
/** @brief get basis-power-unit abbreviation at runtime **/
bpu2_abbrev_type bpu_abbrev(dim basis_dim,
bpu_abbrev_type bpu_abbrev(dim basis_dim,
const scalefactor_ratio_type & scalefactor,
const power_ratio_type & power)
{

View file

@ -35,7 +35,7 @@ namespace xo {
using xo::qty::units::scaled_native_unit2_abbrev_v;
using xo::qty::basis_unit;
using xo::qty::abbrev::basis_unit2_abbrev;;
using xo::qty::bpu2_abbrev_type;
using xo::qty::bpu_abbrev_type;
using xo::qty::abbrev::bpu2_abbrev;
using xo::qty::basis_unit2_store;
using xo::qty::power_ratio_type;
@ -312,24 +312,24 @@ namespace xo {
log && log(xtag("kg*kg", bpu2_abbrev(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(2, 1))));
static_assert(bpu<int64_t>(dim::mass, scalefactor_ratio_type(1, 1), power_ratio_type(1, 1)).abbrev()
== bpu2_abbrev_type::from_chars("g"));
== bpu_abbrev_type::from_chars("g"));
static_assert(bpu<int64_t>(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(1, 1)).abbrev()
== bpu2_abbrev_type::from_chars("kg"));
== bpu_abbrev_type::from_chars("kg"));
static_assert(bpu<int64_t>(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(-1, 1)).abbrev()
== bpu2_abbrev_type::from_chars("kg^-1"));
== bpu_abbrev_type::from_chars("kg^-1"));
static_assert(bpu<int64_t>(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(-2, 1)).abbrev()
== bpu2_abbrev_type::from_chars("kg^-2"));
== bpu_abbrev_type::from_chars("kg^-2"));
static_assert(bpu<int64_t>(dim::time, scalefactor_ratio_type(60, 1), power_ratio_type(-2, 1)).abbrev()
== bpu2_abbrev_type::from_chars("min^-2"));
== bpu_abbrev_type::from_chars("min^-2"));
static_assert(bpu<int64_t>(dim::time, scalefactor_ratio_type(3600, 1), power_ratio_type(-1, 1)).abbrev()
== bpu2_abbrev_type::from_chars("hr^-1"));
== bpu_abbrev_type::from_chars("hr^-1"));
static_assert(bpu<int64_t>(dim::time, scalefactor_ratio_type(24*3600, 1), power_ratio_type(-1, 1)).abbrev()
== bpu2_abbrev_type::from_chars("dy^-1"));
== bpu_abbrev_type::from_chars("dy^-1"));
static_assert(bpu<int64_t>(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 1)).abbrev()
== bpu2_abbrev_type::from_chars("yr360^-1"));
== bpu_abbrev_type::from_chars("yr360^-1"));
static_assert(bpu<int64_t>(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 2)).abbrev()
== bpu2_abbrev_type::from_chars("yr360^(-1/2)"));
== bpu_abbrev_type::from_chars("yr360^(-1/2)"));
} /*TEST_CASE(bpu2_abbrev)*/