// Boost.Units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion // // Copyright (C) 2003-2008 Matthias Christian Schabel // Copyright (C) 2008 Steven Watanabe // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_UNITS_ABSOLUTE_IMPL_HPP #define BOOST_UNITS_ABSOLUTE_IMPL_HPP #include #include #include #include #include namespace boost { namespace units { /// INTERNAL ONLY template struct reduce_unit > > { typedef absolute >::type> type; }; namespace detail { struct undefined_affine_conversion_base { static const bool is_defined = false; }; } // namespace detail /// INTERNAL ONLY template struct affine_conversion_helper : detail::undefined_affine_conversion_base { }; namespace detail { template struct affine_conversion_impl; template struct affine_conversion_impl { template struct apply { static T1 value(const T0& t0) { return( t0 * conversion_factor(Unit1(), Unit2()) + affine_conversion_helper::type, typename reduce_unit::type>::value()); } }; }; template<> struct affine_conversion_impl { template struct apply { static T1 value(const T0& t0) { return( (t0 - affine_conversion_helper::type, typename reduce_unit::type>::value()) * conversion_factor(Unit1(), Unit2())); } }; }; } // namespace detail /// INTERNAL ONLY template struct conversion_helper, T1>, quantity, T2> > { typedef quantity, T1> from_quantity_type; typedef quantity, T2> to_quantity_type; static to_quantity_type convert(const from_quantity_type& source) { return( to_quantity_type::from_value( detail::affine_conversion_impl< affine_conversion_helper::type, typename reduce_unit::type>::is_defined, affine_conversion_helper::type, typename reduce_unit::type>::is_defined >::template apply::value(source.value()) ) ); } }; } // namespace units } // namespace boost #endif // BOOST_UNITS_ABSOLUTE_IMPL_HPP