Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/units/dimension.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_DIMENSION_HPP
0012 #define BOOST_UNITS_DIMENSION_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/type_traits/is_same.hpp>
0017 
0018 #include <boost/mpl/arithmetic.hpp>
0019 
0020 #include <boost/units/static_rational.hpp>
0021 #include <boost/units/detail/dimension_list.hpp>
0022 #include <boost/units/detail/dimension_impl.hpp>
0023 
0024 /// \file 
0025 /// \brief Core metaprogramming utilities for compile-time dimensional analysis.
0026 
0027 namespace boost {
0028 
0029 namespace units {
0030 
0031 /// Reduce dimension list to cardinal form. This algorithm collapses duplicate
0032 /// base dimension tags and sorts the resulting list by the tag ordinal value.
0033 /// Dimension lists that resolve to the same dimension are guaranteed to be  
0034 /// represented by an identical type.
0035 ///
0036 /// The argument should be an MPL forward sequence containing instances
0037 /// of the @c dim template.
0038 ///
0039 /// The result is also an MPL forward sequence.  It also supports the
0040 /// following metafunctions to allow use as a dimension.
0041 ///
0042 ///    - @c mpl::plus is defined only on two equal dimensions and returns the argument unchanged.
0043 ///    - @c mpl::minus is defined only for two equal dimensions and returns the argument unchanged.
0044 ///    - @c mpl::negate will return its argument unchanged.
0045 ///    - @c mpl::times is defined for any dimensions and adds corresponding exponents.
0046 ///    - @c mpl::divides is defined for any dimensions and subtracts the exponents of the
0047 ///         right had argument from the corresponding exponents of the left had argument.
0048 ///         Missing base dimension tags are assumed to have an exponent of zero.
0049 ///    - @c static_power takes a dimension and a static_rational and multiplies all
0050 ///         the exponents of the dimension by the static_rational.
0051 ///    - @c static_root takes a dimension and a static_rational and divides all
0052 ///         the exponents of the dimension by the static_rational.
0053 template<typename Seq>
0054 struct make_dimension_list
0055 {
0056     typedef typename detail::sort_dims<Seq>::type type;
0057 };
0058 
0059 /// Raise a dimension list to a scalar power.
0060 template<typename DL,typename Ex> 
0061 struct static_power
0062 {
0063     typedef typename detail::static_power_impl<DL::size::value>::template apply<
0064         DL,
0065         Ex
0066     >::type type;    
0067 };
0068 
0069 /// Take a scalar root of a dimension list.
0070 template<typename DL,typename Rt> 
0071 struct static_root
0072 {
0073     typedef typename detail::static_root_impl<DL::size::value>::template apply<
0074         DL,
0075         Rt
0076     >::type type;    
0077 };
0078 
0079 } // namespace units
0080 
0081 #ifndef BOOST_UNITS_DOXYGEN
0082 
0083 namespace mpl {
0084 
0085 template<>
0086 struct plus_impl<boost::units::detail::dimension_list_tag,boost::units::detail::dimension_list_tag>
0087 {
0088     template<class T0, class T1>
0089     struct apply
0090     {
0091         BOOST_STATIC_ASSERT((boost::is_same<T0,T1>::value == true));
0092         typedef T0 type;
0093     };
0094 };
0095 
0096 template<>
0097 struct minus_impl<boost::units::detail::dimension_list_tag,boost::units::detail::dimension_list_tag>
0098 {
0099     template<class T0, class T1>
0100     struct apply
0101     {
0102         BOOST_STATIC_ASSERT((boost::is_same<T0,T1>::value == true));
0103         typedef T0 type;
0104     };
0105 };
0106 
0107 template<>
0108 struct times_impl<boost::units::detail::dimension_list_tag,boost::units::detail::dimension_list_tag>
0109 {
0110     template<class T0, class T1>
0111     struct apply
0112     {
0113         typedef typename boost::units::detail::merge_dimensions<T0,T1>::type type;
0114     };
0115 };
0116 
0117 template<>
0118 struct divides_impl<boost::units::detail::dimension_list_tag,boost::units::detail::dimension_list_tag>
0119 {
0120     template<class T0, class T1>
0121     struct apply
0122     {
0123         typedef typename boost::units::detail::merge_dimensions<
0124             T0,
0125             typename boost::units::detail::static_inverse_impl<
0126                 T1::size::value
0127             >::template apply<
0128                 T1
0129             >::type
0130         >::type type;
0131     };
0132 };
0133 
0134 template<>
0135 struct negate_impl<boost::units::detail::dimension_list_tag>
0136 {
0137     template<class T0>
0138     struct apply
0139     {
0140         typedef T0 type;
0141     };
0142 };
0143 
0144 } // namespace mpl
0145 
0146 #endif
0147 
0148 } // namespace boost
0149 
0150 #endif // BOOST_UNITS_DIMENSION_HPP