Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:13

0001 // Boost.Units - A C++ library for zero-overhead dimensional analysis and 
0002 // unit/quantity manipulation and conversion
0003 //
0004 // Copyright (C) 2003-2008 Matthias Christian Schabel
0005 // Copyright (C) 2008 Steven Watanabe
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See
0008 // accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_UNITS_ABSOLUTE_IMPL_HPP
0012 #define BOOST_UNITS_ABSOLUTE_IMPL_HPP
0013 
0014 #include <iosfwd>
0015 
0016 #include <boost/units/config.hpp>
0017 #include <boost/units/conversion.hpp>
0018 #include <boost/units/heterogeneous_system.hpp>
0019 #include <boost/units/units_fwd.hpp>
0020 
0021 namespace boost {
0022 
0023 namespace units {
0024 
0025 /// INTERNAL ONLY
0026 template<class D, class S>
0027 struct reduce_unit<absolute<unit<D, S> > >
0028 {
0029     typedef absolute<typename reduce_unit<unit<D, S> >::type> type;
0030 };
0031 
0032 namespace detail {
0033 
0034 struct undefined_affine_conversion_base {
0035     BOOST_STATIC_CONSTEXPR bool is_defined = false;
0036 };
0037 
0038 } // namespace detail
0039 
0040 /// INTERNAL ONLY
0041 template<class From, class To>
0042 struct affine_conversion_helper : detail::undefined_affine_conversion_base { };
0043 
0044 namespace detail {
0045 
0046 template<bool IsDefined, bool ReverseIsDefined>
0047 struct affine_conversion_impl;
0048 
0049 template<bool ReverseIsDefined>
0050 struct affine_conversion_impl<true, ReverseIsDefined>
0051 {
0052     template<class Unit1, class Unit2, class T0, class T1>
0053     struct apply {
0054         static BOOST_CONSTEXPR T1 value(const T0& t0)
0055         {
0056             return(
0057                 t0 * 
0058                 conversion_factor(Unit1(), Unit2()) +
0059                 affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::value());
0060         }
0061     };
0062 };
0063 
0064 template<>
0065 struct affine_conversion_impl<false, true>
0066 {
0067     template<class Unit1, class Unit2, class T0, class T1>
0068     struct apply
0069     {
0070         static BOOST_CONSTEXPR T1 value(const T0& t0)
0071         {
0072             return(
0073                 (t0 - affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::value()) * 
0074                 conversion_factor(Unit1(), Unit2()));
0075         }
0076     };
0077 };
0078 
0079 } // namespace detail
0080 
0081 /// INTERNAL ONLY
0082 template<class Unit1, class T1, class Unit2, class T2>
0083 struct conversion_helper<quantity<absolute<Unit1>, T1>, quantity<absolute<Unit2>, T2> >
0084 {
0085     typedef quantity<absolute<Unit1>, T1> from_quantity_type;
0086     typedef quantity<absolute<Unit2>, T2> to_quantity_type;
0087     static BOOST_CONSTEXPR to_quantity_type convert(const from_quantity_type& source)
0088     {
0089         return(
0090             to_quantity_type::from_value(
0091                 detail::affine_conversion_impl<
0092                     affine_conversion_helper<typename reduce_unit<Unit1>::type, typename reduce_unit<Unit2>::type>::is_defined,
0093                     affine_conversion_helper<typename reduce_unit<Unit2>::type, typename reduce_unit<Unit1>::type>::is_defined
0094                 >::template apply<Unit1, Unit2, T1, T2>::value(source.value())
0095             )
0096         );
0097     }
0098 };
0099 
0100 } // namespace units
0101 
0102 } // namespace boost
0103 
0104 #endif // BOOST_UNITS_ABSOLUTE_IMPL_HPP