SI  2.5.4
A header only c++ library that provides type safety and user defined literals for handling physical values defined in the International System of Units.
mass.h
Go to the documentation of this file.
1 
12 #pragma once
13 #include "detail/number_parser.h"
14 #include "detail/unit.h"
15 #include "detail/unit_symbol.h"
16 
17 namespace SI {
18 
19 template <typename _type, typename _ratio>
20 using mass_t = detail::unit_t<'M', std::ratio<1>, _type, _ratio>;
21 
22 template <typename _type> using femto_gram_t = mass_t<_type, std::atto>;
23 template <typename _type> using pico_gram_t = mass_t<_type, std::femto>;
24 template <typename _type> using nano_gram_t = mass_t<_type, std::pico>;
25 template <typename _type> using micro_gram_t = mass_t<_type, std::nano>;
26 template <typename _type> using milli_gram_t = mass_t<_type, std::micro>;
27 template <typename _type> using gram_t = mass_t<_type, std::milli>;
28 template <typename _type> using kilo_gram_t = mass_t<_type, std::ratio<1>>;
29 template <typename _type> using ton_t = mass_t<_type, std::kilo>;
30 template <typename _type> using mega_gram_t = ton_t<_type>;
31 template <typename _type> using kilo_ton_t = mass_t<_type, std::mega>;
32 template <typename _type> using giga_gram_t = kilo_ton_t<_type>;
33 template <typename _type> using mega_ton_t = mass_t<_type, std::giga>;
34 template <typename _type> using tera_gram_t = mega_ton_t<_type>;
35 template <typename _type> using giga_ton_t = mass_t<_type, std::tera>;
36 template <typename _type> using peta_gram_t = giga_ton_t<_type>;
37 template <typename _type> using tera_ton_t = mass_t<_type, std::peta>;
38 template <typename _type> using exa_gram_t = tera_ton_t<_type>;
39 template <typename _type> using peta_ton_t = mass_t<_type, std::exa>;
40 template <typename _type> using zetta_gram_t = peta_ton_t<_type>;
41 
42 // specialize unit_symbol for usage with stream operators
43 // due to the standard SI unit being 'kg' instead of 'g'
44 // ratios has to be multiplied by 1000/1 and explicit template
45 // specialization is needed for the 'ton' and 'gram'
46 // @todo figure out how to handle duplicates between tonne and mega_gram
47 template <>
48 struct unit_symbol<'M', std::ratio<1>>
49  : SI::detail::unit_symbol_impl<'k', 'g'> {};
50 
51 template <>
52 struct unit_symbol<'M', std::milli> : SI::detail::unit_symbol_impl<'g'> {};
53 
54 template <>
55 struct unit_symbol<'M', std::kilo> : SI::detail::unit_symbol_impl<'t'> {};
56 
57 template <>
58 struct unit_symbol<'M', std::exa> : SI::detail::unit_symbol_impl<'Z', 'g'> {};
59 
60 template <typename _ratio>
61 struct unit_symbol<'M', _ratio>
62  : SI::detail::unit_symbol_impl<SI::detail::ratio_prefix<std::ratio_multiply<
63  _ratio, std::kilo>>::value,
64  'g'> {};
65 
66 inline namespace literals {
67 
68 template <char... _digits> constexpr femto_gram_t<int64_t> operator""_fg() {
69  return femto_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
70 }
71 
72 template <char... _digits> constexpr pico_gram_t<int64_t> operator""_pg() {
73  return pico_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
74 }
75 
76 template <char... _digits> constexpr nano_gram_t<int64_t> operator""_ng() {
77  return nano_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
78 }
79 
80 template <char... _digits> constexpr micro_gram_t<int64_t> operator""_ug() {
81  return micro_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
82 }
83 
84 template <char... _digits> constexpr milli_gram_t<int64_t> operator""_mg() {
85  return milli_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
86 }
87 
88 template <char... _digits> constexpr gram_t<int64_t> operator""_g() {
89  return gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
90 }
91 
92 template <char... _digits> constexpr kilo_gram_t<int64_t> operator""_kg() {
93  return kilo_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
94 }
95 
96 template <char... _digits> constexpr ton_t<int64_t> operator""_t() {
97  return ton_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
98 }
99 
100 template <char... _digits> constexpr kilo_ton_t<int64_t> operator""_kt() {
101  return kilo_ton_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
102 }
103 
104 template <char... _digits> constexpr mega_ton_t<int64_t> operator""_Mt() {
105  return mega_ton_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
106 }
107 
108 template <char... _digits> constexpr giga_ton_t<int64_t> operator""_Gt() {
109  return giga_ton_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
110 }
111 
112 template <char... _digits> constexpr tera_ton_t<int64_t> operator""_Tt() {
113  return tera_ton_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
114 }
115 
116 template <char... _digits> constexpr peta_ton_t<int64_t> operator""_Pt() {
117  return peta_ton_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
118 }
119 
120 template <char... _digits> constexpr mega_gram_t<int64_t> operator""_Mg() {
121  return mega_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
122 }
123 
124 template <char... _digits> constexpr giga_gram_t<int64_t> operator""_Gg() {
125  return giga_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
126 }
127 
128 template <char... _digits> constexpr tera_gram_t<int64_t> operator""_Tg() {
129  return tera_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
130 }
131 
132 template <char... _digits> constexpr peta_gram_t<int64_t> operator""_Pg() {
133  return peta_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
134 }
135 
136 template <char... _digits> constexpr exa_gram_t<int64_t> operator""_Eg() {
137  return exa_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
138 }
139 
140 template <char... _digits> constexpr zetta_gram_t<int64_t> operator""_Zg() {
141  return zetta_gram_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
142 }
143 
144 constexpr femto_gram_t<long double> operator""_fg(long double value) {
145  return femto_gram_t<long double>{value};
146 }
147 
148 constexpr pico_gram_t<long double> operator""_pg(long double value) {
149  return pico_gram_t<long double>{value};
150 }
151 
152 constexpr nano_gram_t<long double> operator""_ng(long double value) {
153  return nano_gram_t<long double>{value};
154 }
155 
156 constexpr micro_gram_t<long double> operator""_ug(long double value) {
157  return micro_gram_t<long double>{value};
158 }
159 
160 constexpr milli_gram_t<long double> operator"" _mg(long double mg) {
161  return milli_gram_t<long double>(mg);
162 }
163 
164 constexpr gram_t<long double> operator"" _g(long double g) {
165  return gram_t<long double>(g);
166 }
167 
168 constexpr kilo_gram_t<long double> operator"" _kg(long double kg) {
169  return kilo_gram_t<long double>(kg);
170 }
171 
172 constexpr ton_t<long double> operator"" _t(long double t) {
173  return ton_t<long double>(t);
174 }
175 
176 constexpr kilo_ton_t<long double> operator"" _kt(long double t) {
177  return kilo_ton_t<long double>(t);
178 }
179 
180 constexpr mega_ton_t<long double> operator"" _Mt(long double t) {
181  return mega_ton_t<long double>(t);
182 }
183 
184 constexpr giga_ton_t<long double> operator"" _Gt(long double t) {
185  return giga_ton_t<long double>(t);
186 }
187 
188 constexpr tera_ton_t<long double> operator"" _Tt(long double t) {
189  return tera_ton_t<long double>(t);
190 }
191 
192 constexpr peta_ton_t<long double> operator"" _Pt(long double t) {
193  return peta_ton_t<long double>(t);
194 }
195 
196 constexpr mega_gram_t<long double> operator""_Mg(long double value) {
197  return mega_gram_t<long double>{value};
198 }
199 
200 constexpr giga_gram_t<long double> operator""_Gg(long double value) {
201  return giga_gram_t<long double>{value};
202 }
203 
204 constexpr tera_gram_t<long double> operator""_Tg(long double value) {
205  return tera_gram_t<long double>{value};
206 }
207 
208 constexpr peta_gram_t<long double> operator""_Pg(long double value) {
209  return peta_gram_t<long double>{value};
210 }
211 
212 constexpr exa_gram_t<long double> operator""_Eg(long double value) {
213  return exa_gram_t<long double>{value};
214 }
215 
216 constexpr zetta_gram_t<long double> operator""_Zg(long double value) {
217  return zetta_gram_t<long double>{value};
218 }
219 
220 } // namespace literals
221 } // namespace SI
Definition: absorbed_dose.h:18
interface class for number
Definition: number_parser.h:111
Compile time string provider for conversion of unit types to strings.
Definition: unit_symbol.h:21
base template class for holding values of type _type to be multiplied with a ratio _ratio
Definition: unit.h:51
Base struct. Unusable needs template overloading.
Definition: unit_symbol.h:64