Back to home page

EIC code displayed by LXR

 
 

    


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

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) 2007-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_DETAIL_UNSCALE_HPP_INCLUDED
0012 #define BOOST_UNITS_DETAIL_UNSCALE_HPP_INCLUDED
0013 
0014 #include <string>
0015 
0016 #include <boost/mpl/bool.hpp>
0017 #include <boost/mpl/size.hpp>
0018 #include <boost/mpl/begin.hpp>
0019 #include <boost/mpl/next.hpp>
0020 #include <boost/mpl/deref.hpp>
0021 #include <boost/mpl/plus.hpp>
0022 #include <boost/mpl/times.hpp>
0023 #include <boost/mpl/negate.hpp>
0024 #include <boost/mpl/less.hpp>
0025 
0026 #include <boost/units/config.hpp>
0027 #include <boost/units/dimension.hpp>
0028 #include <boost/units/scale.hpp>
0029 #include <boost/units/static_rational.hpp>
0030 #include <boost/units/units_fwd.hpp>
0031 #include <boost/units/detail/one.hpp>
0032 
0033 namespace boost {
0034 
0035 namespace units {
0036 
0037 template<class T>
0038 struct heterogeneous_system;
0039 
0040 template<class T, class D, class Scale>
0041 struct heterogeneous_system_impl;
0042 
0043 template<class T, class E>
0044 struct heterogeneous_system_dim;
0045 
0046 template<class S, class Scale>
0047 struct scaled_base_unit;
0048 
0049 /// removes all scaling from a unit or a base unit.
0050 template<class T>
0051 struct unscale
0052 {
0053 #ifndef BOOST_UNITS_DOXYGEN
0054     typedef T type;
0055 #else
0056     typedef detail::unspecified type;
0057 #endif
0058 };
0059 
0060 /// INTERNAL ONLY
0061 template<class S, class Scale>
0062 struct unscale<scaled_base_unit<S, Scale> >
0063 {
0064     typedef typename unscale<S>::type type;
0065 };
0066 
0067 /// INTERNAL ONLY
0068 template<class D, class S>
0069 struct unscale<unit<D, S> >
0070 {
0071     typedef unit<D, typename unscale<S>::type> type;
0072 };
0073 
0074 /// INTERNAL ONLY
0075 template<class Scale>
0076 struct scale_list_dim;
0077 
0078 /// INTERNAL ONLY
0079 template<class T>
0080 struct get_scale_list
0081 {
0082     typedef dimensionless_type type;
0083 };
0084 
0085 /// INTERNAL ONLY
0086 template<class S, class Scale>
0087 struct get_scale_list<scaled_base_unit<S, Scale> >
0088 {
0089     typedef typename mpl::times<list<scale_list_dim<Scale>, dimensionless_type>, typename get_scale_list<S>::type>::type type;
0090 };
0091 
0092 /// INTERNAL ONLY
0093 template<class D, class S>
0094 struct get_scale_list<unit<D, S> >
0095 {
0096     typedef typename get_scale_list<S>::type type;
0097 };
0098 
0099 /// INTERNAL ONLY
0100 struct scale_dim_tag {};
0101 
0102 /// INTERNAL ONLY
0103 template<class Scale>
0104 struct scale_list_dim : Scale
0105 {
0106     typedef scale_dim_tag tag;
0107     typedef scale_list_dim type;
0108 };
0109 
0110 } // namespace units
0111 
0112 #ifndef BOOST_UNITS_DOXYGEN
0113 
0114 namespace mpl {
0115 
0116 /// INTERNAL ONLY
0117 template<>
0118 struct less_impl<boost::units::scale_dim_tag, boost::units::scale_dim_tag>
0119 {
0120     template<class T0, class T1>
0121     struct apply : mpl::bool_<((T0::base) < (T1::base))> {};
0122 };
0123 
0124 }
0125 
0126 #endif
0127 
0128 namespace units {
0129 
0130 namespace detail {
0131 
0132 template<class Scale>
0133 struct is_empty_dim<scale_list_dim<Scale> > : mpl::false_ {};
0134 
0135 template<long N>
0136 struct is_empty_dim<scale_list_dim<scale<N, static_rational<0, 1> > > > : mpl::true_ {};
0137 
0138 template<int N>
0139 struct eval_scale_list_impl
0140 {
0141     template<class Begin>
0142     struct apply
0143     {
0144         typedef typename eval_scale_list_impl<N-1>::template apply<typename Begin::next> next_iteration;
0145         typedef typename multiply_typeof_helper<typename next_iteration::type, typename Begin::item::value_type>::type type;
0146         static BOOST_CONSTEXPR type value()
0147         {
0148             return(next_iteration::value() * Begin::item::value());
0149         }
0150     };
0151 };
0152 
0153 template<>
0154 struct eval_scale_list_impl<0>
0155 {
0156     template<class Begin>
0157     struct apply
0158     {
0159         typedef one type;
0160         static BOOST_CONSTEXPR one value()
0161         {
0162             return(one());
0163         }
0164     };
0165 };
0166 
0167 }
0168 
0169 /// INTERNAL ONLY
0170 template<class T>
0171 struct eval_scale_list : detail::eval_scale_list_impl<T::size::value>::template apply<T> {};
0172 
0173 } // namespace units
0174 
0175 #ifndef BOOST_UNITS_DOXYGEN
0176 
0177 namespace mpl {
0178 
0179 /// INTERNAL ONLY
0180 template<>
0181 struct plus_impl<boost::units::scale_dim_tag, boost::units::scale_dim_tag>
0182 {
0183     template<class T0, class T1>
0184     struct apply
0185     {
0186         typedef boost::units::scale_list_dim<
0187             boost::units::scale<
0188                 (T0::base),
0189                 typename mpl::plus<typename T0::exponent, typename T1::exponent>::type
0190             >
0191         > type;
0192     };
0193 };
0194 
0195 /// INTERNAL ONLY
0196 template<>
0197 struct negate_impl<boost::units::scale_dim_tag>
0198 {
0199     template<class T0>
0200     struct apply
0201     {
0202         typedef boost::units::scale_list_dim<
0203             boost::units::scale<
0204                 (T0::base),
0205                 typename mpl::negate<typename T0::exponent>::type
0206             >
0207         > type;
0208     };
0209 };
0210 
0211 /// INTERNAL ONLY
0212 template<>
0213 struct times_impl<boost::units::scale_dim_tag, boost::units::detail::static_rational_tag>
0214 {
0215     template<class T0, class T1>
0216     struct apply
0217     {
0218         typedef boost::units::scale_list_dim<
0219             boost::units::scale<
0220                 (T0::base),
0221                 typename mpl::times<typename T0::exponent, T1>::type
0222             >
0223         > type;
0224     };
0225 };
0226 
0227 /// INTERNAL ONLY
0228 template<>
0229 struct divides_impl<boost::units::scale_dim_tag, boost::units::detail::static_rational_tag>
0230 {
0231     template<class T0, class T1>
0232     struct apply
0233     {
0234         typedef boost::units::scale_list_dim<
0235             boost::units::scale<
0236                 (T0::base),
0237                 typename mpl::divides<typename T0::exponent, T1>::type
0238             >
0239         > type;
0240     };
0241 };
0242 
0243 } // namespace mpl
0244 
0245 #endif
0246 
0247 } // namespace boost
0248 
0249 #endif