1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2007-2008 Steven Watanabe
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)
11 #ifndef BOOST_UNITS_DETAIL_UNSCALE_HPP_INCLUDED
12 #define BOOST_UNITS_DETAIL_UNSCALE_HPP_INCLUDED
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>
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>
38 struct heterogeneous_system
;
40 template<class T
, class D
, class Scale
>
41 struct heterogeneous_system_impl
;
43 template<class T
, class E
>
44 struct heterogeneous_system_dim
;
46 template<class S
, class Scale
>
47 struct scaled_base_unit
;
49 /// removes all scaling from a unit or a base unit.
53 #ifndef BOOST_UNITS_DOXYGEN
56 typedef detail::unspecified type
;
61 template<class S
, class Scale
>
62 struct unscale
<scaled_base_unit
<S
, Scale
> >
64 typedef typename unscale
<S
>::type type
;
68 template<class D
, class S
>
69 struct unscale
<unit
<D
, S
> >
71 typedef unit
<D
, typename unscale
<S
>::type
> type
;
76 struct scale_list_dim
;
82 typedef dimensionless_type type
;
86 template<class S
, class Scale
>
87 struct get_scale_list
<scaled_base_unit
<S
, Scale
> >
89 typedef typename
mpl::times
<list
<scale_list_dim
<Scale
>, dimensionless_type
>, typename get_scale_list
<S
>::type
>::type type
;
93 template<class D
, class S
>
94 struct get_scale_list
<unit
<D
, S
> >
96 typedef typename get_scale_list
<S
>::type type
;
100 struct scale_dim_tag
{};
103 template<class Scale
>
104 struct scale_list_dim
: Scale
106 typedef scale_dim_tag tag
;
107 typedef scale_list_dim type
;
112 #ifndef BOOST_UNITS_DOXYGEN
118 struct less_impl
<boost::units::scale_dim_tag
, boost::units::scale_dim_tag
>
120 template<class T0
, class T1
>
121 struct apply
: mpl::bool_
<((T0::base
) < (T1::base
))> {};
132 template<class Scale
>
133 struct is_empty_dim
<scale_list_dim
<Scale
> > : mpl::false_
{};
136 struct is_empty_dim
<scale_list_dim
<scale
<N
, static_rational
<0, 1> > > > : mpl::true_
{};
139 struct eval_scale_list_impl
141 template<class Begin
>
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
;
148 return(next_iteration::value() * Begin::item::value());
154 struct eval_scale_list_impl
<0>
156 template<class Begin
>
172 struct eval_scale_list
: detail::eval_scale_list_impl
<T::size::value
>::template apply
<T
> {};
176 #ifndef BOOST_UNITS_DOXYGEN
182 struct plus_impl
<boost::units::scale_dim_tag
, boost::units::scale_dim_tag
>
184 template<class T0
, class T1
>
187 typedef boost::units::scale_list_dim
<
190 typename
mpl::plus
<typename
T0::exponent
, typename
T1::exponent
>::type
198 struct negate_impl
<boost::units::scale_dim_tag
>
203 typedef boost::units::scale_list_dim
<
206 typename
mpl::negate
<typename
T0::exponent
>::type
214 struct times_impl
<boost::units::scale_dim_tag
, boost::units::detail::static_rational_tag
>
216 template<class T0
, class T1
>
219 typedef boost::units::scale_list_dim
<
222 typename
mpl::times
<typename
T0::exponent
, T1
>::type