xo-unit: move types: xo::obs:: -> xo::unit::
This commit is contained in:
parent
06a7e938e4
commit
7e61533caf
14 changed files with 147 additions and 114 deletions
|
|
@ -4,7 +4,7 @@
|
|||
#include "ratio_util.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
/** @class basis_unit
|
||||
*
|
||||
* @brief A dimensionless multiple with natively-specified (i.e. at compile-time) dimension
|
||||
|
|
@ -56,9 +56,9 @@ namespace xo {
|
|||
template<dim BasisDim>
|
||||
constexpr auto native_unit_abbrev_v = native_unit_abbrev_helper<BasisDim>::value;
|
||||
|
||||
// ----- scaled_native_unit_abbrev_helper -----
|
||||
|
||||
namespace units {
|
||||
// ----- scaled_native_unit_abbrev_helper -----
|
||||
|
||||
/* Require: InnerScale is ratio type; InnerScale >= 1 */
|
||||
template <dim BasisDim, typename InnerScale>
|
||||
struct scaled_native_unit_abbrev;
|
||||
|
|
@ -80,7 +80,7 @@ namespace xo {
|
|||
template <dim BasisDim, typename InnerScale>
|
||||
constexpr auto scaled_native_unit_abbrev_v = scaled_native_unit_abbrev<BasisDim, InnerScale>::value;
|
||||
}
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/** end basis_unit.hpp **/
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "stringliteral.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
enum class dim {
|
||||
/** weight. native unit = 1 gram **/
|
||||
mass,
|
||||
|
|
@ -52,8 +53,7 @@ namespace xo {
|
|||
|
||||
template <dim Dim>
|
||||
constexpr auto native_unit_for_v = native_unit_for<Dim>::value;
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end dim_util.hpp */
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "native_bpu_concept.hpp"
|
||||
//#include <concepts>
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
/** checks most non-empty BPU (basis power unit) node types;
|
||||
* cannot check BpuList::rest_type, because concept definition
|
||||
* can't (as of c++23) be recursive.
|
||||
|
|
@ -83,7 +82,7 @@ namespace xo {
|
|||
&& (ratio_concept<typename Unit::scalefactor_type>
|
||||
&& bpu_list_concept<typename Unit::dim_type>
|
||||
&& bpu_list_concept<typename Unit::canon_type>);
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end dimension_concept.hpp */
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace xo {
|
|||
* - bpu_list -> bpu_node
|
||||
*/
|
||||
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
// ----- lookup_bpu -----
|
||||
|
||||
/**
|
||||
|
|
@ -510,7 +510,7 @@ namespace xo {
|
|||
template<typename D>
|
||||
using canonical_t = canonical_impl<D>::dim_type;
|
||||
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end dimension_impl.hpp */
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <ratio>
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
// ----- native_bpu -----
|
||||
|
||||
/** @class native_bpu
|
||||
|
|
@ -253,7 +253,7 @@ namespace xo {
|
|||
_p_type /*Power*/ >;
|
||||
};
|
||||
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end native_bpu.hpp */
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <concepts>
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
/**
|
||||
* e.g. see native_bpu<native_dim_id, std::ratio<..>>
|
||||
*
|
||||
|
|
@ -35,8 +35,7 @@ namespace xo {
|
|||
&& (std::is_signed_v<decltype(NativeBpu::c_den)>))
|
||||
// && std::copyable<Foo>
|
||||
;
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end native_bpu_concept.hpp */
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
//#include "xo/indentlog/scope.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
/** @class promoter
|
||||
*
|
||||
* Aux class assister for quantity::promote()
|
||||
|
|
@ -35,7 +35,7 @@ namespace xo {
|
|||
* - Repr * Repr -> Repr
|
||||
* - Repr / Repr -> Repr
|
||||
**/
|
||||
template <typename Unit, typename Repr> //, typename RequiredDimensionType = Unit>
|
||||
template <typename Unit, typename Repr = double>
|
||||
class quantity {
|
||||
public:
|
||||
using unit_type = Unit;
|
||||
|
|
@ -415,7 +415,7 @@ namespace xo {
|
|||
};
|
||||
|
||||
template <typename Repr = double>
|
||||
inline auto kilograms(Repr x) -> quantity<units::gram, Repr> {
|
||||
inline auto kilograms(Repr x) -> quantity<units::kilogram, Repr> {
|
||||
return quantity<units::kilogram, Repr>::promote(x);
|
||||
};
|
||||
|
||||
|
|
@ -495,7 +495,7 @@ namespace xo {
|
|||
return quantity<units::volatility_250d, Repr>::promote(x);
|
||||
}
|
||||
} /*namespace qty*/
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end quantity.hpp */
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <concepts>
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
template <typename Quantity>
|
||||
concept quantity_concept = requires(Quantity qty, typename Quantity::repr_type repr)
|
||||
{
|
||||
|
|
@ -17,5 +17,5 @@ namespace xo {
|
|||
{ Quantity::unit_quantity() } -> std::same_as<Quantity>;
|
||||
{ Quantity::promote(repr) } -> std::same_as<Quantity>;
|
||||
};
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
#include <concepts>
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
template <typename Ratio>
|
||||
concept ratio_concept = (std::is_signed_v<decltype(Ratio::num)>
|
||||
&& std::is_signed_v<decltype(Ratio::den)>);
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <numeric>
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
// ----- ratio_floor -----
|
||||
|
||||
template <typename Ratio>
|
||||
|
|
@ -236,7 +236,7 @@ namespace xo {
|
|||
return exponent2str_aux<Ratio::type::num, Ratio::type::den>().value;
|
||||
};
|
||||
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ratio_util.hpp */
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
|
||||
// ----- stringliteral -----
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ namespace xo {
|
|||
static constexpr auto value = stringliteral_concat("-", _suffix.value_);
|
||||
};
|
||||
|
||||
} /*namespace obs*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end stringliteral.hpp */
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/* @file dimension.hpp */
|
||||
/* @file unit.hpp */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "dimension_impl.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace obs {
|
||||
namespace unit {
|
||||
// ----- wrap_unit -----
|
||||
|
||||
template <typename Scalefactor, typename BpuList>
|
||||
|
|
@ -26,6 +26,7 @@ namespace xo {
|
|||
|
||||
// ----- normalize_unit -----
|
||||
|
||||
/* like Unit, but with scalefactor 1 */
|
||||
template <typename Unit>
|
||||
struct normalize_unit {
|
||||
static_assert(unit_concept<Unit>);
|
||||
|
|
@ -239,7 +240,7 @@ namespace xo {
|
|||
|
||||
using milligram = wrap_unit< std::ratio<1>,
|
||||
bpu_node< bpu<dim::mass,
|
||||
std::ratio<1, 1000>> > >;
|
||||
std::ratio<1, 1000>> > >;
|
||||
|
||||
template <>
|
||||
struct scaled_native_unit_abbrev<dim::mass, std::ratio<1, 1000>> {
|
||||
|
|
@ -248,10 +249,10 @@ namespace xo {
|
|||
|
||||
using gram = wrap_unit< std::ratio<1>,
|
||||
bpu_node< bpu<dim::mass,
|
||||
std::ratio<1>> > >;
|
||||
std::ratio<1>> > >;
|
||||
using kilogram = wrap_unit< std::ratio<1>,
|
||||
bpu_node< bpu<dim::mass,
|
||||
std::ratio<1000>> > >;
|
||||
std::ratio<1000>> > >;
|
||||
|
||||
template <>
|
||||
struct scaled_native_unit_abbrev<dim::mass, std::ratio<1000>> {
|
||||
|
|
@ -385,10 +386,8 @@ namespace xo {
|
|||
using price = wrap_unit< std::ratio<1>,
|
||||
bpu_node< bpu<dim::price,
|
||||
std::ratio<1>> > >;
|
||||
}
|
||||
|
||||
} /*namespace obs*/
|
||||
} /*namespace units*/
|
||||
} /*namespace unit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end dimension.hpp */
|
||||
/* end unit.hpp */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue