Line data Source code
1 : /** @file native_unit.hpp 2 : * 3 : * Author: Roland Conybeare 4 : **/ 5 : 6 : #pragma once 7 : 8 : #include "dimension.hpp" 9 : #include "xo/flatstring/flatstring.hpp" 10 : 11 : namespace xo { 12 : namespace qty { 13 : using native_unit2_abbrev_type = flatstring<8>; 14 : 15 : /** @class native_unit 16 : * 17 : * @brief Represent a native (built-in) unit. 18 : * 19 : * A basis_unit is expressed as a multiple of a native_unit 20 : * 21 : **/ 22 : struct native_unit { 23 : public: 24 : constexpr native_unit(dim native_dim, 25 : const native_unit2_abbrev_type & abbrev_str) 26 : : native_dim_{native_dim}, 27 : abbrev_str_{abbrev_str} 28 : {} 29 : 30 : constexpr dim native_dim() const { return native_dim_; } 31 0 : constexpr const native_unit2_abbrev_type & abbrev_str() const { return abbrev_str_; } 32 : 33 : private: 34 : dim native_dim_; 35 : native_unit2_abbrev_type abbrev_str_; 36 : }; 37 : 38 : static constexpr native_unit native_unit2_v[n_dim] = { 39 : native_unit(dim::mass, native_unit2_abbrev_type::from_chars("g")), 40 : native_unit(dim::distance, native_unit2_abbrev_type::from_chars("m")), 41 : native_unit(dim::time, native_unit2_abbrev_type::from_chars("s")), 42 : native_unit(dim::currency, native_unit2_abbrev_type::from_chars("ccy")), 43 : native_unit(dim::price, native_unit2_abbrev_type::from_chars("px")), 44 : }; 45 : 46 : } /*namespace qty*/ 47 : } /*namespace xo*/ 48 : 49 : /** end native_unit.hpp **/