]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/units/include/boost/units/detail/unscale.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / units / include / boost / units / detail / unscale.hpp
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
3 //
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2007-2008 Steven Watanabe
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_UNITS_DETAIL_UNSCALE_HPP_INCLUDED
12 #define BOOST_UNITS_DETAIL_UNSCALE_HPP_INCLUDED
13
14 #include <string>
15
16 #include <boost/mpl/bool.hpp>
17 #include <boost/mpl/size.hpp>
18 #include <boost/mpl/begin.hpp>
19 #include <boost/mpl/next.hpp>
20 #include <boost/mpl/deref.hpp>
21 #include <boost/mpl/plus.hpp>
22 #include <boost/mpl/times.hpp>
23 #include <boost/mpl/negate.hpp>
24 #include <boost/mpl/less.hpp>
25
26 #include <boost/units/config.hpp>
27 #include <boost/units/dimension.hpp>
28 #include <boost/units/scale.hpp>
29 #include <boost/units/static_rational.hpp>
30 #include <boost/units/units_fwd.hpp>
31 #include <boost/units/detail/one.hpp>
32
33 namespace boost {
34
35 namespace units {
36
37 template<class T>
38 struct heterogeneous_system;
39
40 template<class T, class D, class Scale>
41 struct heterogeneous_system_impl;
42
43 template<class T, class E>
44 struct heterogeneous_system_dim;
45
46 template<class S, class Scale>
47 struct scaled_base_unit;
48
49 /// removes all scaling from a unit or a base unit.
50 template<class T>
51 struct unscale
52 {
53 #ifndef BOOST_UNITS_DOXYGEN
54 typedef T type;
55 #else
56 typedef detail::unspecified type;
57 #endif
58 };
59
60 /// INTERNAL ONLY
61 template<class S, class Scale>
62 struct unscale<scaled_base_unit<S, Scale> >
63 {
64 typedef typename unscale<S>::type type;
65 };
66
67 /// INTERNAL ONLY
68 template<class D, class S>
69 struct unscale<unit<D, S> >
70 {
71 typedef unit<D, typename unscale<S>::type> type;
72 };
73
74 /// INTERNAL ONLY
75 template<class Scale>
76 struct scale_list_dim;
77
78 /// INTERNAL ONLY
79 template<class T>
80 struct get_scale_list
81 {
82 typedef dimensionless_type type;
83 };
84
85 /// INTERNAL ONLY
86 template<class S, class Scale>
87 struct get_scale_list<scaled_base_unit<S, Scale> >
88 {
89 typedef typename mpl::times<list<scale_list_dim<Scale>, dimensionless_type>, typename get_scale_list<S>::type>::type type;
90 };
91
92 /// INTERNAL ONLY
93 template<class D, class S>
94 struct get_scale_list<unit<D, S> >
95 {
96 typedef typename get_scale_list<S>::type type;
97 };
98
99 /// INTERNAL ONLY
100 struct scale_dim_tag {};
101
102 /// INTERNAL ONLY
103 template<class Scale>
104 struct scale_list_dim : Scale
105 {
106 typedef scale_dim_tag tag;
107 typedef scale_list_dim type;
108 };
109
110 } // namespace units
111
112 #ifndef BOOST_UNITS_DOXYGEN
113
114 namespace mpl {
115
116 /// INTERNAL ONLY
117 template<>
118 struct less_impl<boost::units::scale_dim_tag, boost::units::scale_dim_tag>
119 {
120 template<class T0, class T1>
121 struct apply : mpl::bool_<((T0::base) < (T1::base))> {};
122 };
123
124 }
125
126 #endif
127
128 namespace units {
129
130 namespace detail {
131
132 template<class Scale>
133 struct is_empty_dim<scale_list_dim<Scale> > : mpl::false_ {};
134
135 template<long N>
136 struct is_empty_dim<scale_list_dim<scale<N, static_rational<0, 1> > > > : mpl::true_ {};
137
138 template<int N>
139 struct eval_scale_list_impl
140 {
141 template<class Begin>
142 struct apply
143 {
144 typedef typename eval_scale_list_impl<N-1>::template apply<typename Begin::next> next_iteration;
145 typedef typename multiply_typeof_helper<typename next_iteration::type, typename Begin::item::value_type>::type type;
146 static type value()
147 {
148 return(next_iteration::value() * Begin::item::value());
149 }
150 };
151 };
152
153 template<>
154 struct eval_scale_list_impl<0>
155 {
156 template<class Begin>
157 struct apply
158 {
159 typedef one type;
160 static one value()
161 {
162 one result;
163 return(result);
164 }
165 };
166 };
167
168 }
169
170 /// INTERNAL ONLY
171 template<class T>
172 struct eval_scale_list : detail::eval_scale_list_impl<T::size::value>::template apply<T> {};
173
174 } // namespace units
175
176 #ifndef BOOST_UNITS_DOXYGEN
177
178 namespace mpl {
179
180 /// INTERNAL ONLY
181 template<>
182 struct plus_impl<boost::units::scale_dim_tag, boost::units::scale_dim_tag>
183 {
184 template<class T0, class T1>
185 struct apply
186 {
187 typedef boost::units::scale_list_dim<
188 boost::units::scale<
189 (T0::base),
190 typename mpl::plus<typename T0::exponent, typename T1::exponent>::type
191 >
192 > type;
193 };
194 };
195
196 /// INTERNAL ONLY
197 template<>
198 struct negate_impl<boost::units::scale_dim_tag>
199 {
200 template<class T0>
201 struct apply
202 {
203 typedef boost::units::scale_list_dim<
204 boost::units::scale<
205 (T0::base),
206 typename mpl::negate<typename T0::exponent>::type
207 >
208 > type;
209 };
210 };
211
212 /// INTERNAL ONLY
213 template<>
214 struct times_impl<boost::units::scale_dim_tag, boost::units::detail::static_rational_tag>
215 {
216 template<class T0, class T1>
217 struct apply
218 {
219 typedef boost::units::scale_list_dim<
220 boost::units::scale<
221 (T0::base),
222 typename mpl::times<typename T0::exponent, T1>::type
223 >
224 > type;
225 };
226 };
227
228 } // namespace mpl
229
230 #endif
231
232 } // namespace boost
233
234 #endif