OGLplus  (0.59.0) a C++ wrapper for rendering APIs

base_dim.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_UNITS_BASE_DIM_HPP
10 #define EAGINE_UNITS_BASE_DIM_HPP
11 
12 #include "fwd.hpp"
13 #include <utility>
14 
15 namespace eagine::units {
16 namespace base {
17 
18 // dimension
19 template <typename Derived>
20 struct dimension {
21  using type = Derived;
22 };
23 
24 struct angle : dimension<angle> {};
25 struct solid_angle : dimension<solid_angle> {};
26 
27 struct length : dimension<length> {};
28 struct mass : dimension<mass> {};
29 struct time : dimension<time> {};
30 
31 struct temperature : dimension<temperature> {};
32 struct electric_current : dimension<electric_current> {};
33 struct number_of_cycles : dimension<number_of_cycles> {};
34 struct number_of_decays : dimension<number_of_decays> {};
35 struct luminous_intensity : dimension<luminous_intensity> {};
36 struct amount_of_substance : dimension<amount_of_substance> {};
37 struct amount_of_information : dimension<amount_of_information> {};
38 
39 template <typename Func>
40 auto for_each_dim(Func func) -> Func {
41  func(angle());
42  func(solid_angle());
43  func(length());
44  func(mass());
45  func(time());
46  func(temperature());
47  func(electric_current());
48  func(number_of_cycles());
49  func(number_of_decays());
50  func(luminous_intensity());
51  func(amount_of_substance());
52  func(amount_of_information());
53 
54  return std::move(func);
55 }
56 
57 // dim_num
58 template <typename Dimension>
59 struct dim_num;
60 
61 template <typename Dim>
62 struct dim_num<dimension<Dim>> : dim_num<Dim> {};
63 
64 template <typename Dimension>
65 const int dim_num_v = dim_num<Dimension>::value;
66 
67 template <>
68 struct dim_num<nothing_t> : int_constant<0> {};
69 
70 template <>
71 struct dim_num<angle> : int_constant<1> {};
72 template <>
73 struct dim_num<solid_angle> : int_constant<2> {};
74 template <>
75 struct dim_num<mass> : int_constant<3> {};
76 template <>
77 struct dim_num<length> : int_constant<4> {};
78 template <>
79 struct dim_num<time> : int_constant<5> {};
80 
81 template <>
82 struct dim_num<temperature> : int_constant<6> {};
83 template <>
84 struct dim_num<electric_current> : int_constant<7> {};
85 template <>
86 struct dim_num<number_of_cycles> : int_constant<8> {};
87 template <>
88 struct dim_num<number_of_decays> : int_constant<9> {};
89 template <>
90 struct dim_num<luminous_intensity> : int_constant<10> {};
91 template <>
92 struct dim_num<amount_of_substance> : int_constant<11> {};
93 template <>
94 struct dim_num<amount_of_information> : int_constant<12> {};
95 
96 // get_number
97 template <typename Derived>
98 static constexpr auto get_number(dimension<Derived>) noexcept -> int {
99  return dim_num_v<Derived>;
100 }
101 
102 } // namespace base
103 
104 template <>
105 struct name_of<base::angle> {
106  static constexpr const char mp_str[] = "angle";
107 };
108 
109 template <>
110 struct name_of<base::solid_angle> {
111  static constexpr const char mp_str[] = "solid angle";
112 };
113 
114 template <>
115 struct name_of<base::mass> {
116  static constexpr const char mp_str[] = "mass";
117 };
118 
119 template <>
120 struct name_of<base::length> {
121  static constexpr const char mp_str[] = "length";
122 };
123 
124 template <>
125 struct name_of<base::time> {
126  static constexpr const char mp_str[] = "time";
127 };
128 
129 template <>
130 struct name_of<base::temperature> {
131  static constexpr const char mp_str[] = "temperature";
132 };
133 
134 template <>
135 struct name_of<base::electric_current> {
136  static constexpr const char mp_str[] = "electric current";
137 };
138 
139 template <>
140 struct name_of<base::number_of_cycles> {
141  static constexpr const char mp_str[] = "number of cycles";
142 };
143 
144 template <>
145 struct name_of<base::number_of_decays> {
146  static constexpr const char mp_str[] = "number of decays";
147 };
148 
149 template <>
150 struct name_of<base::luminous_intensity> {
151  static constexpr const char mp_str[] = "luminous intensity";
152 };
153 
154 template <>
155 struct name_of<base::amount_of_substance> {
156  static constexpr const char mp_str[] = "amount of substance";
157 };
158 
159 template <>
160 struct name_of<base::amount_of_information> {
161  static constexpr const char mp_str[] = "amount of information";
162 };
163 
164 } // namespace eagine::units
165 
166 #endif // EAGINE_UNITS_BASE_DIM_HPP
std::integral_constant< int, I > int_constant
Alias for signed int constant type.
Definition: int_constant.hpp:25

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).