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) 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_ABSOLUTE_IMPL_HPP
12 #define BOOST_UNITS_ABSOLUTE_IMPL_HPP
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>
26 template<class D, class S>
27 struct reduce_unit<absolute<unit<D, S> > >
29 typedef absolute<typename reduce_unit<unit<D, S> >::type> type;
34 struct undefined_affine_conversion_base {
35 static const bool is_defined = false;
41 template<class From, class To>
42 struct affine_conversion_helper : detail::undefined_affine_conversion_base { };
46 template<bool IsDefined, bool ReverseIsDefined>
47 struct affine_conversion_impl;
49 template<bool ReverseIsDefined>
50 struct affine_conversion_impl<true, ReverseIsDefined>
52 template<class Unit1, class Unit2, class T0, class T1>
54 static T1 value(const T0& t0)
58 conversion_factor(Unit1(), Unit2()) +
59 affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::value());
65 struct affine_conversion_impl<false, true>
67 template<class Unit1, class Unit2, class T0, class T1>
70 static T1 value(const T0& t0)
73 (t0 - affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::value()) *
74 conversion_factor(Unit1(), Unit2()));
82 template<class Unit1, class T1, class Unit2, class T2>
83 struct conversion_helper<quantity<absolute<Unit1>, T1>, quantity<absolute<Unit2>, T2> >
85 typedef quantity<absolute<Unit1>, T1> from_quantity_type;
86 typedef quantity<absolute<Unit2>, T2> to_quantity_type;
87 static to_quantity_type convert(const from_quantity_type& source)
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())
104 #endif // BOOST_UNITS_ABSOLUTE_IMPL_HPP