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.
energy.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "detail/number_parser.h"
16 #include "detail/unit.h"
17 #include "detail/unit_symbol.h"
18 #include "force.h"
19 #include "length.h"
20 #include "pressure.h"
21 
22 namespace SI {
23 template <typename _type, class _ratio = std::ratio<1>>
25 
27 template <typename _type> using atto_joule_t = energy_t<_type, std::atto>;
28 template <typename _type> using femto_joule_t = energy_t<_type, std::femto>;
29 template <typename _type> using pico_joule_t = energy_t<_type, std::pico>;
30 template <typename _type> using nano_joule_t = energy_t<_type, std::nano>;
31 template <typename _type> using micro_joule_t = energy_t<_type, std::micro>;
32 template <typename _type> using milli_joule_t = energy_t<_type, std::milli>;
33 template <typename _type> using joule_t = energy_t<_type, std::ratio<1>>;
34 template <typename _type> using kilo_joule_t = energy_t<_type, std::kilo>;
35 template <typename _type> using mega_joule_t = energy_t<_type, std::mega>;
36 template <typename _type> using giga_joule_t = energy_t<_type, std::giga>;
37 template <typename _type> using tera_joule_t = energy_t<_type, std::tera>;
38 template <typename _type> using peta_joule_t = energy_t<_type, std::peta>;
39 template <typename _type> using exa_joule_t = energy_t<_type, std::exa>;
40 
41 // specialize unit_symbol for usage with stream operators
42 template <>
43 struct unit_symbol<'E', std::ratio<1>> : SI::detail::unit_symbol_impl<'J'> {};
44 
45 template <typename _ratio>
46 struct unit_symbol<'E', _ratio>
47  : SI::detail::unit_symbol_impl<SI::detail::ratio_prefix<_ratio>::value,
48  'J'> {};
49 
50 namespace detail {
53 } // namespace detail
54 
55 inline namespace literals {
56 template <char... _digits> constexpr atto_joule_t<int64_t> operator""_aJ() {
57  return atto_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
58 }
59 
60 template <char... _digits> constexpr femto_joule_t<int64_t> operator""_fJ() {
61  return femto_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
62 }
63 
64 template <char... _digits> constexpr pico_joule_t<int64_t> operator""_pJ() {
65  return pico_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
66 }
67 
68 template <char... _digits> constexpr nano_joule_t<int64_t> operator""_nJ() {
69  return nano_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
70 }
71 
72 template <char... _digits> constexpr micro_joule_t<int64_t> operator""_uJ() {
73  return micro_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
74 }
75 
76 template <char... _digits> constexpr milli_joule_t<int64_t> operator""_mJ() {
77  return milli_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
78 }
79 
80 template <char... _digits> constexpr joule_t<int64_t> operator""_J() {
81  return joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
82 }
83 
84 template <char... _digits> constexpr kilo_joule_t<int64_t> operator""_kJ() {
85  return kilo_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
86 }
87 
88 template <char... _digits> constexpr mega_joule_t<int64_t> operator""_MJ() {
89  return mega_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
90 }
91 
92 template <char... _digits> constexpr giga_joule_t<int64_t> operator""_GJ() {
93  return giga_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
94 }
95 
96 template <char... _digits> constexpr tera_joule_t<int64_t> operator""_TJ() {
97  return tera_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
98 }
99 
100 template <char... _digits> constexpr peta_joule_t<int64_t> operator""_PJ() {
101  return peta_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
102 }
103 
104 template <char... _digits> constexpr exa_joule_t<int64_t> operator""_EJ() {
105  return exa_joule_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
106 }
107 
108 constexpr atto_joule_t<long double> operator""_aJ(long double value) {
109  return atto_joule_t<long double>{value};
110 }
111 
112 constexpr femto_joule_t<long double> operator""_fJ(long double value) {
113  return femto_joule_t<long double>{value};
114 }
115 
116 constexpr pico_joule_t<long double> operator""_pJ(long double value) {
117  return pico_joule_t<long double>{value};
118 }
119 
120 constexpr nano_joule_t<long double> operator""_nJ(long double value) {
121  return nano_joule_t<long double>{value};
122 }
123 
124 constexpr micro_joule_t<long double> operator""_uJ(long double value) {
125  return micro_joule_t<long double>{value};
126 }
127 
128 constexpr milli_joule_t<long double> operator""_mJ(long double value) {
129  return milli_joule_t<long double>{value};
130 }
131 
132 constexpr joule_t<long double> operator""_J(long double value) {
133  return joule_t<long double>{value};
134 }
135 
136 constexpr kilo_joule_t<long double> operator""_kJ(long double value) {
137  return kilo_joule_t<long double>{value};
138 }
139 
140 constexpr mega_joule_t<long double> operator""_MJ(long double value) {
141  return mega_joule_t<long double>{value};
142 }
143 
144 constexpr giga_joule_t<long double> operator""_GJ(long double value) {
145  return giga_joule_t<long double>{value};
146 }
147 
148 constexpr tera_joule_t<long double> operator""_TJ(long double value) {
149  return tera_joule_t<long double>{value};
150 }
151 
152 constexpr peta_joule_t<long double> operator""_PJ(long double value) {
153  return peta_joule_t<long double>{value};
154 }
155 
156 constexpr exa_joule_t<long double> operator""_EJ(long double value) {
157  return exa_joule_t<long double>{value};
158 }
159 
160 } // namespace literals
161 } // namespace SI
Definition: absorbed_dose.h:18
#define BUILD_UNIT_FROM_MULTIPLICATION(RESULTING_UNIT, UNIT_LHS, UNIT_RHS)
Definition: operator_helpers.h:54
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