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) 2007-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_DIM_HPP Chris@16: #define BOOST_UNITS_DIM_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: /// \file dim.hpp Chris@16: /// \brief Handling of fundamental dimension/exponent pairs. Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: namespace units { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: struct dim_tag { }; Chris@16: Chris@16: } Chris@16: Chris@16: /// \brief Dimension tag/exponent pair for a single fundamental dimension. Chris@16: /// Chris@16: /// \details Chris@16: /// The dim class represents a single dimension tag/dimension exponent pair. Chris@16: /// That is, @c dim is a pair where @c tag_type represents the Chris@16: /// fundamental dimension being represented and @c value_type represents the Chris@16: /// exponent of that fundamental dimension as a @c static_rational. @c tag_type must Chris@16: /// be a derived from a specialization of @c base_dimension. Chris@16: /// Specialization of the following Boost.MPL metafunctions are provided Chris@16: /// Chris@16: /// - @c mpl::plus for two @c dims Chris@16: /// - @c mpl::minus for two @c dims Chris@16: /// - @c mpl::negate for a @c dim Chris@16: /// Chris@16: /// These metafunctions all operate on the exponent, and require Chris@16: /// that the @c dim operands have the same base dimension tag. Chris@16: /// In addition, multiplication and division by @c static_rational Chris@16: /// is supported. Chris@16: /// Chris@16: /// - @c mpl::times for a @c static_rational and a @c dim in either order Chris@16: /// - @c mpl::divides for a @c static_rational and a @c dim in either order Chris@16: /// Chris@16: /// These metafunctions likewise operate on the exponent only. Chris@16: template Chris@16: struct dim Chris@16: { Chris@16: typedef dim type; Chris@16: typedef detail::dim_tag tag; Chris@16: typedef T tag_type; Chris@16: typedef V value_type; Chris@16: }; Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #if BOOST_UNITS_HAS_BOOST_TYPEOF Chris@16: Chris@16: #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() Chris@16: Chris@16: BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::dim, 2) Chris@16: Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_UNITS_DOXYGEN Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: namespace mpl { Chris@16: Chris@16: // define MPL operators acting on dim Chris@16: Chris@16: template<> Chris@16: struct plus_impl Chris@16: { Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: BOOST_STATIC_ASSERT((boost::is_same::value == true)); Chris@16: typedef boost::units::dim::type> type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct minus_impl Chris@16: { Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: BOOST_STATIC_ASSERT((boost::is_same::value == true)); Chris@16: typedef boost::units::dim::type> type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct times_impl Chris@16: { Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: typedef boost::units::dim::type> type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct times_impl Chris@16: { Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: typedef boost::units::dim::type> type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct divides_impl Chris@16: { Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: typedef boost::units::dim::type> type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct divides_impl Chris@16: { Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: typedef boost::units::dim::type> type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct negate_impl Chris@16: { Chris@16: template Chris@16: struct apply Chris@16: { Chris@16: typedef boost::units::dim::type> type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: } // namespace mpl Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif Chris@16: Chris@16: #endif // BOOST_UNITS_DIM_HPP