]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) 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_ABSOLUTE_IMPL_HPP | |
12 | #define BOOST_UNITS_ABSOLUTE_IMPL_HPP | |
13 | ||
14 | #include <iosfwd> | |
15 | ||
16 | #include <boost/units/config.hpp> | |
17 | #include <boost/units/conversion.hpp> | |
18 | #include <boost/units/heterogeneous_system.hpp> | |
19 | #include <boost/units/units_fwd.hpp> | |
20 | ||
21 | namespace boost { | |
22 | ||
23 | namespace units { | |
24 | ||
25 | /// INTERNAL ONLY | |
26 | template<class D, class S> | |
27 | struct reduce_unit<absolute<unit<D, S> > > | |
28 | { | |
29 | typedef absolute<typename reduce_unit<unit<D, S> >::type> type; | |
30 | }; | |
31 | ||
32 | namespace detail { | |
33 | ||
34 | struct undefined_affine_conversion_base { | |
11fdf7f2 | 35 | BOOST_STATIC_CONSTEXPR bool is_defined = false; |
7c673cae FG |
36 | }; |
37 | ||
38 | } // namespace detail | |
39 | ||
40 | /// INTERNAL ONLY | |
41 | template<class From, class To> | |
42 | struct affine_conversion_helper : detail::undefined_affine_conversion_base { }; | |
43 | ||
44 | namespace detail { | |
45 | ||
46 | template<bool IsDefined, bool ReverseIsDefined> | |
47 | struct affine_conversion_impl; | |
48 | ||
49 | template<bool ReverseIsDefined> | |
50 | struct affine_conversion_impl<true, ReverseIsDefined> | |
51 | { | |
52 | template<class Unit1, class Unit2, class T0, class T1> | |
53 | struct apply { | |
11fdf7f2 | 54 | static BOOST_CONSTEXPR T1 value(const T0& t0) |
7c673cae FG |
55 | { |
56 | return( | |
57 | t0 * | |
58 | conversion_factor(Unit1(), Unit2()) + | |
59 | affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::value()); | |
60 | } | |
61 | }; | |
62 | }; | |
63 | ||
64 | template<> | |
65 | struct affine_conversion_impl<false, true> | |
66 | { | |
67 | template<class Unit1, class Unit2, class T0, class T1> | |
68 | struct apply | |
69 | { | |
11fdf7f2 | 70 | static BOOST_CONSTEXPR T1 value(const T0& t0) |
7c673cae FG |
71 | { |
72 | return( | |
73 | (t0 - affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::value()) * | |
74 | conversion_factor(Unit1(), Unit2())); | |
75 | } | |
76 | }; | |
77 | }; | |
78 | ||
79 | } // namespace detail | |
80 | ||
81 | /// INTERNAL ONLY | |
82 | template<class Unit1, class T1, class Unit2, class T2> | |
83 | struct conversion_helper<quantity<absolute<Unit1>, T1>, quantity<absolute<Unit2>, T2> > | |
84 | { | |
85 | typedef quantity<absolute<Unit1>, T1> from_quantity_type; | |
86 | typedef quantity<absolute<Unit2>, T2> to_quantity_type; | |
11fdf7f2 | 87 | static BOOST_CONSTEXPR to_quantity_type convert(const from_quantity_type& source) |
7c673cae FG |
88 | { |
89 | return( | |
90 | to_quantity_type::from_value( | |
91 | detail::affine_conversion_impl< | |
92 | affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::is_defined, | |
93 | affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::is_defined | |
94 | >::template apply<Unit1, Unit2, T1, T2>::value(source.value()) | |
95 | ) | |
96 | ); | |
97 | } | |
98 | }; | |
99 | ||
100 | } // namespace units | |
101 | ||
102 | } // namespace boost | |
103 | ||
104 | #endif // BOOST_UNITS_ABSOLUTE_IMPL_HPP |