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