Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/units/dim.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_DIM_HPP
0012 #define BOOST_UNITS_DIM_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/config.hpp>
0021 #include <boost/units/static_rational.hpp>
0022 #include <boost/units/detail/dim_impl.hpp>
0023 
0024 /// \file dim.hpp
0025 /// \brief Handling of fundamental dimension/exponent pairs.
0026 
0027 namespace boost {
0028 
0029 namespace units {
0030 
0031 namespace detail {
0032 
0033 struct dim_tag { };
0034 
0035 }
0036 
0037 /// \brief Dimension tag/exponent pair for a single fundamental dimension.
0038 ///
0039 /// \details 
0040 /// The dim class represents a single dimension tag/dimension exponent pair.
0041 /// That is, @c dim<tag_type,value_type> is a pair where @c tag_type represents the
0042 /// fundamental dimension being represented and @c value_type represents the 
0043 /// exponent of that fundamental dimension as a @c static_rational. @c tag_type must 
0044 /// be a derived from a specialization of @c base_dimension.
0045 /// Specialization of the following Boost.MPL metafunctions are provided
0046 ///
0047 ///     - @c mpl::plus for two @c dims
0048 ///     - @c mpl::minus for two @c dims
0049 ///     - @c mpl::negate for a @c dim
0050 ///
0051 /// These metafunctions all operate on the exponent, and require
0052 /// that the @c dim operands have the same base dimension tag.
0053 /// In addition, multiplication and division by @c static_rational
0054 /// is supported.
0055 ///
0056 ///     - @c mpl::times for a @c static_rational and a @c dim in either order
0057 ///     - @c mpl::divides for a @c static_rational and a @c dim in either order
0058 ///
0059 /// These metafunctions likewise operate on the exponent only.
0060 template<typename T,typename V> 
0061 struct dim
0062 {
0063     typedef dim             type;
0064     typedef detail::dim_tag tag;
0065     typedef T               tag_type;
0066     typedef V               value_type;
0067 };
0068 
0069 } // namespace units
0070 
0071 } // namespace boost
0072 
0073 #if BOOST_UNITS_HAS_BOOST_TYPEOF
0074 
0075 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
0076 
0077 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::dim, 2)
0078 
0079 #endif
0080 
0081 #ifndef BOOST_UNITS_DOXYGEN
0082 
0083 namespace boost {
0084 
0085 namespace mpl {
0086 
0087 // define MPL operators acting on dim<T,V>
0088 
0089 template<>
0090 struct plus_impl<boost::units::detail::dim_tag,boost::units::detail::dim_tag>
0091 {
0092     template<class T0, class T1>
0093     struct apply
0094     {
0095         BOOST_STATIC_ASSERT((boost::is_same<typename T0::tag_type,typename T1::tag_type>::value == true));
0096         typedef boost::units::dim<typename T0::tag_type, typename mpl::plus<typename T0::value_type, typename T1::value_type>::type> type;
0097     };
0098 };
0099 
0100 template<>
0101 struct minus_impl<boost::units::detail::dim_tag,boost::units::detail::dim_tag>
0102 {
0103     template<class T0, class T1>
0104     struct apply
0105     {
0106         BOOST_STATIC_ASSERT((boost::is_same<typename T0::tag_type,typename T1::tag_type>::value == true));
0107         typedef boost::units::dim<typename T0::tag_type, typename mpl::minus<typename T0::value_type, typename T1::value_type>::type> type;
0108     };
0109 };
0110 
0111 template<>
0112 struct times_impl<boost::units::detail::dim_tag,boost::units::detail::static_rational_tag>
0113 {
0114     template<class T0, class T1>
0115     struct apply
0116     {
0117         typedef boost::units::dim<typename T0::tag_type, typename mpl::times<typename T0::value_type, T1>::type> type;
0118     };
0119 };
0120 
0121 template<>
0122 struct times_impl<boost::units::detail::static_rational_tag,boost::units::detail::dim_tag>
0123 {
0124     template<class T0, class T1>
0125     struct apply
0126     {
0127         typedef boost::units::dim<typename T1::tag_type, typename mpl::times<T0, typename T1::value_type>::type> type;
0128     };
0129 };
0130 
0131 template<>
0132 struct divides_impl<boost::units::detail::dim_tag,boost::units::detail::static_rational_tag>
0133 {
0134     template<class T0, class T1>
0135     struct apply
0136     {
0137         typedef boost::units::dim<typename T0::tag_type, typename mpl::divides<typename T0::value_type, T1>::type> type;
0138     };
0139 };
0140 
0141 template<>
0142 struct divides_impl<boost::units::detail::static_rational_tag,boost::units::detail::dim_tag>
0143 {
0144     template<class T0, class T1>
0145     struct apply
0146     {
0147         typedef boost::units::dim<typename T1::tag_type, typename mpl::divides<T0, typename T1::value_type>::type> type;
0148     };
0149 };
0150 
0151 template<>
0152 struct negate_impl<boost::units::detail::dim_tag>
0153 {
0154     template<class T0>
0155     struct apply
0156     {
0157         typedef boost::units::dim<typename T0::tag_type,typename mpl::negate<typename T0::value_type>::type> type;
0158     };
0159 };
0160 
0161 } // namespace mpl
0162 
0163 } // namespace boost
0164 
0165 #endif
0166 
0167 #endif // BOOST_UNITS_DIM_HPP