xo-unit: docs extension
This commit is contained in:
parent
74f36ad374
commit
d767675dd9
11 changed files with 130 additions and 39 deletions
|
|
@ -8,37 +8,46 @@
|
|||
|
||||
namespace xo {
|
||||
namespace qty {
|
||||
/** @class basis_unit2
|
||||
/** @class basis_unit
|
||||
* @brief A dimensionless multiple of a single natively-specified basis dimension
|
||||
*
|
||||
* For example "3600 minutes" or "1e-6 grams"
|
||||
**/
|
||||
struct basis_unit {
|
||||
public:
|
||||
/** @defgroup basis-unit-constructors basis_unit constructors **/
|
||||
///@{
|
||||
constexpr basis_unit() = default;
|
||||
constexpr basis_unit(dimension native_dim,
|
||||
const scalefactor_ratio_type & scalefactor)
|
||||
: native_dim_{native_dim},
|
||||
scalefactor_{scalefactor}
|
||||
{}
|
||||
///@}
|
||||
|
||||
/** @defgroup basis-unit-access-methods basis_unit access methods **/
|
||||
///@{
|
||||
constexpr dimension native_dim() const { return native_dim_; }
|
||||
constexpr const scalefactor_ratio_type & scalefactor() const { return scalefactor_; }
|
||||
///@}
|
||||
|
||||
constexpr basis_unit2_abbrev_type abbrev() const {
|
||||
return abbrev::basis_unit2_abbrev(native_dim_,
|
||||
scalefactor_);
|
||||
}
|
||||
|
||||
constexpr basis_unit & operator=(const basis_unit & x) = default;
|
||||
|
||||
public: /* need public members so that a basis_unit 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) **/
|
||||
dimension native_dim_ = dimension::invalid;
|
||||
/** @brief this unit defined as multiple scalefactor times native unit **/
|
||||
scalefactor_ratio_type scalefactor_;
|
||||
///@}
|
||||
};
|
||||
|
||||
/** @defgroup basis-unit-comparison-support basis_unit comparisons **/
|
||||
///@{
|
||||
inline constexpr bool
|
||||
operator==(const basis_unit & x, const basis_unit & y)
|
||||
{
|
||||
|
|
@ -52,10 +61,13 @@ namespace xo {
|
|||
return ((x.native_dim_ != y.native_dim_)
|
||||
|| (x.scalefactor_ != y.scalefactor_));
|
||||
}
|
||||
///@}
|
||||
|
||||
namespace bu {
|
||||
// ----- mass -----
|
||||
|
||||
/** @defgroup basis-unit-mass-units **/
|
||||
///@{
|
||||
constexpr basis_unit picogram = basis_unit(dim::mass, scalefactor_ratio_type( 1, 1000000000000));
|
||||
constexpr basis_unit nanogram = basis_unit(dim::mass, scalefactor_ratio_type( 1, 1000000000));
|
||||
constexpr basis_unit microgram = basis_unit(dim::mass, scalefactor_ratio_type( 1, 1000000));
|
||||
|
|
@ -66,9 +78,12 @@ namespace xo {
|
|||
constexpr basis_unit kilotonne = basis_unit(dim::mass, scalefactor_ratio_type( 1000000000, 1));
|
||||
constexpr basis_unit megatonne = basis_unit(dim::mass, scalefactor_ratio_type( 1000000000000, 1));
|
||||
constexpr basis_unit gigatonne = basis_unit(dim::mass, scalefactor_ratio_type(1000000000000000, 1));
|
||||
///@}
|
||||
|
||||
// ----- distance -----
|
||||
|
||||
/** @defgroup basis-unit-distance-units **/
|
||||
///@{
|
||||
/* International spelling */
|
||||
constexpr basis_unit picometre = basis_unit(dim::distance, scalefactor_ratio_type( 1, 1000000000000));
|
||||
constexpr basis_unit nanometre = basis_unit(dim::distance, scalefactor_ratio_type( 1, 1000000000));
|
||||
|
|
@ -100,9 +115,12 @@ namespace xo {
|
|||
constexpr basis_unit yard = basis_unit(dim::distance, scalefactor_ratio_type( 3*3048, 10000));
|
||||
/** @brief basis-unit representing 1 mile; defined as exactly 1760 yards = 5280 feet **/
|
||||
constexpr basis_unit mile = basis_unit(dim::distance, scalefactor_ratio_type( 5280*3048, 10000));
|
||||
///@}
|
||||
|
||||
// ----- time -----
|
||||
|
||||
/** @defgroup basis-unit-time-units **/
|
||||
///@{
|
||||
constexpr basis_unit picosecond = basis_unit(dim::time, scalefactor_ratio_type( 1, 1000000000000));
|
||||
constexpr basis_unit nanosecond = basis_unit(dim::time, scalefactor_ratio_type( 1, 1000000000));
|
||||
constexpr basis_unit microsecond = basis_unit(dim::time, scalefactor_ratio_type( 1, 1000000));
|
||||
|
|
@ -120,9 +138,13 @@ namespace xo {
|
|||
constexpr basis_unit year360 = basis_unit(dim::time, scalefactor_ratio_type( 360*24*3600, 1));
|
||||
/* 250 = approx number of trading days in a calendar year */
|
||||
constexpr basis_unit year250 = basis_unit(dim::time, scalefactor_ratio_type( 250*24*3600, 1));
|
||||
///@}
|
||||
|
||||
// ----- currency -----
|
||||
|
||||
/** @defgroup basis-unit-misc-units **/
|
||||
///@{
|
||||
|
||||
/* pseudounit -- placeholder for any actual currency amount */
|
||||
constexpr basis_unit currency = basis_unit(dim::currency, scalefactor_ratio_type( 1, 1));
|
||||
|
||||
|
|
@ -130,6 +152,7 @@ namespace xo {
|
|||
|
||||
/* psuedounit -- context-dependent interpretation */
|
||||
constexpr basis_unit price = basis_unit(dim::price, scalefactor_ratio_type( 1, 1));
|
||||
///@}
|
||||
}
|
||||
|
||||
namespace units {
|
||||
|
|
@ -145,10 +168,7 @@ namespace xo {
|
|||
|
||||
// ----- scaled_native_unit_abbrev_helper -----
|
||||
|
||||
/* Require: InnerScale is ratio type; InnerScale >= 1
|
||||
*
|
||||
* NOTE: clang 18 doesn't accept that scalefactor_ratio_type is a 'structural type'
|
||||
*/
|
||||
/* Require: InnerScale is ratio type; InnerScale >= 1 */
|
||||
template <dim BasisDim, std::int64_t InnerScaleNum = 1, std::int64_t InnerScaleDen = 1>
|
||||
struct scaled_native_unit2_abbrev;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue