Chris@16
|
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
|
Chris@16
|
2 // unit/quantity manipulation and conversion
|
Chris@16
|
3 //
|
Chris@16
|
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
|
Chris@16
|
5 // Copyright (C) 2008 Steven Watanabe
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
8 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_UNITS_ABSOLUTE_IMPL_HPP
|
Chris@16
|
12 #define BOOST_UNITS_ABSOLUTE_IMPL_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #include <iosfwd>
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/units/config.hpp>
|
Chris@16
|
17 #include <boost/units/conversion.hpp>
|
Chris@16
|
18 #include <boost/units/heterogeneous_system.hpp>
|
Chris@16
|
19 #include <boost/units/units_fwd.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost {
|
Chris@16
|
22
|
Chris@16
|
23 namespace units {
|
Chris@16
|
24
|
Chris@16
|
25 /// INTERNAL ONLY
|
Chris@16
|
26 template<class D, class S>
|
Chris@16
|
27 struct reduce_unit<absolute<unit<D, S> > >
|
Chris@16
|
28 {
|
Chris@16
|
29 typedef absolute<typename reduce_unit<unit<D, S> >::type> type;
|
Chris@16
|
30 };
|
Chris@16
|
31
|
Chris@16
|
32 namespace detail {
|
Chris@16
|
33
|
Chris@16
|
34 struct undefined_affine_conversion_base {
|
Chris@16
|
35 static const bool is_defined = false;
|
Chris@16
|
36 };
|
Chris@16
|
37
|
Chris@16
|
38 } // namespace detail
|
Chris@16
|
39
|
Chris@16
|
40 /// INTERNAL ONLY
|
Chris@16
|
41 template<class From, class To>
|
Chris@16
|
42 struct affine_conversion_helper : detail::undefined_affine_conversion_base { };
|
Chris@16
|
43
|
Chris@16
|
44 namespace detail {
|
Chris@16
|
45
|
Chris@16
|
46 template<bool IsDefined, bool ReverseIsDefined>
|
Chris@16
|
47 struct affine_conversion_impl;
|
Chris@16
|
48
|
Chris@16
|
49 template<bool ReverseIsDefined>
|
Chris@16
|
50 struct affine_conversion_impl<true, ReverseIsDefined>
|
Chris@16
|
51 {
|
Chris@16
|
52 template<class Unit1, class Unit2, class T0, class T1>
|
Chris@16
|
53 struct apply {
|
Chris@16
|
54 static T1 value(const T0& t0)
|
Chris@16
|
55 {
|
Chris@16
|
56 return(
|
Chris@16
|
57 t0 *
|
Chris@16
|
58 conversion_factor(Unit1(), Unit2()) +
|
Chris@16
|
59 affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::value());
|
Chris@16
|
60 }
|
Chris@16
|
61 };
|
Chris@16
|
62 };
|
Chris@16
|
63
|
Chris@16
|
64 template<>
|
Chris@16
|
65 struct affine_conversion_impl<false, true>
|
Chris@16
|
66 {
|
Chris@16
|
67 template<class Unit1, class Unit2, class T0, class T1>
|
Chris@16
|
68 struct apply
|
Chris@16
|
69 {
|
Chris@16
|
70 static T1 value(const T0& t0)
|
Chris@16
|
71 {
|
Chris@16
|
72 return(
|
Chris@16
|
73 (t0 - affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::value()) *
|
Chris@16
|
74 conversion_factor(Unit1(), Unit2()));
|
Chris@16
|
75 }
|
Chris@16
|
76 };
|
Chris@16
|
77 };
|
Chris@16
|
78
|
Chris@16
|
79 } // namespace detail
|
Chris@16
|
80
|
Chris@16
|
81 /// INTERNAL ONLY
|
Chris@16
|
82 template<class Unit1, class T1, class Unit2, class T2>
|
Chris@16
|
83 struct conversion_helper<quantity<absolute<Unit1>, T1>, quantity<absolute<Unit2>, T2> >
|
Chris@16
|
84 {
|
Chris@16
|
85 typedef quantity<absolute<Unit1>, T1> from_quantity_type;
|
Chris@16
|
86 typedef quantity<absolute<Unit2>, T2> to_quantity_type;
|
Chris@16
|
87 static to_quantity_type convert(const from_quantity_type& source)
|
Chris@16
|
88 {
|
Chris@16
|
89 return(
|
Chris@16
|
90 to_quantity_type::from_value(
|
Chris@16
|
91 detail::affine_conversion_impl<
|
Chris@16
|
92 affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::is_defined,
|
Chris@16
|
93 affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::is_defined
|
Chris@16
|
94 >::template apply<Unit1, Unit2, T1, T2>::value(source.value())
|
Chris@16
|
95 )
|
Chris@16
|
96 );
|
Chris@16
|
97 }
|
Chris@16
|
98 };
|
Chris@16
|
99
|
Chris@16
|
100 } // namespace units
|
Chris@16
|
101
|
Chris@16
|
102 } // namespace boost
|
Chris@16
|
103
|
Chris@16
|
104 #endif // BOOST_UNITS_ABSOLUTE_IMPL_HPP
|