|
From: Matthias S. <mat...@us...> - 2007-04-11 21:25:11
|
Update of /cvsroot/boost-sandbox/boost-sandbox/boost/units In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4655 Modified Files: dimension.hpp quantity.hpp Log Message: added BOOST_UNITS_REGISTER_BASE_DIMENSION macro Index: dimension.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/dimension.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- dimension.hpp 4 Apr 2007 23:42:25 -0000 1.3 +++ dimension.hpp 11 Apr 2007 21:25:10 -0000 1.4 @@ -161,23 +161,22 @@ >::type type; }; -/// A utility class for defining fundamental dimensions. -//template<class DT> -//struct fundamental_dimension -//{ -// typedef typename make_dimension_list< boost::mpl::list< dim< DT,static_rational<1> > > >::type type; -//}; +/// A utility class for defining base dimensions. +template<long N> struct base_dimension; -/// replacement for fundamental_dimension -template<long N> -struct base_dimension : - public mpl::int_<N> -{ - typedef base_dimension<N> this_type; - typedef mpl::int_<N> value; - - typedef typename make_dimension_list< boost::mpl::list< dim< this_type,static_rational<1> > > >::type type; -}; +/// each specialization must be separately instantiated in boost::units namespace to prevent duplication of tag values +#define BOOST_UNITS_REGISTER_BASE_DIMENSION(name, N) \ +template<> \ +struct base_dimension<N> : \ + public mpl::int_<N> \ +{ \ + typedef base_dimension<N> this_type; \ + typedef mpl::int_<N> value; \ + \ + typedef make_dimension_list< mpl::list< dim< this_type,static_rational<1> > > >::type type; \ +}; \ + \ +typedef base_dimension<N> name; \ /// A utility class for defining composite dimensions with integer powers. template<class DT1 = dimensionless_type,int E1 = 0, Index: quantity.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/quantity.hpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- quantity.hpp 10 Apr 2007 22:57:24 -0000 1.16 +++ quantity.hpp 11 Apr 2007 21:25:10 -0000 1.17 @@ -70,7 +70,7 @@ return *this; } -#ifndef BOOST_NO_SFINAE + #ifndef BOOST_NO_SFINAE /// explicit conversion between different unit systems is allowed if implicit conversion is disallowed template<class System2,class Dim2,class YY> @@ -91,7 +91,7 @@ BOOST_STATIC_ASSERT((boost::is_convertible<YY,Y>::value == true)); } -#else + #else /// without SFINAE we can't distinguish between explicit and implicit conversions so /// the conversion is always explicit @@ -102,7 +102,7 @@ BOOST_STATIC_ASSERT((boost::is_convertible<YY,Y>::value == true)); } -#endif + #endif /// implicit assignment between different unit systems is allowed if each fundamental dimension is implicitly convertible template<class System2,class Dim2,class YY> @@ -121,14 +121,17 @@ const value_type& value() const { return val_; } ///< constant accessor to value - // need to check that add_typeof_helper<value_type,value_type>==value_type - this_type& operator+=(const this_type& source) { val_ += source.val_; return *this; } ///< can add quantity of same type + ///< can add a quantity of the same type if add_typeof_helper<value_type,value_type>::type is convertible to value_type + this_type& operator+=(const this_type& source) { val_ += source.val_; return *this; } - // need to check that subtract_typeof_helper<value_type,value_type>==value_type - this_type& operator-=(const this_type& source) { val_ -= source.val_; return *this; } ///< can subtract quantity of same type + ///< can subtract a quantity of the same type if subtract_typeof_helper<value_type,value_type>::type is convertible to value_type + this_type& operator-=(const this_type& source) { val_ -= source.val_; return *this; } - this_type& operator*=(const value_type& val) { val_ *= val; return *this; } ///< can multiply quantity by scalar - this_type& operator/=(const value_type& val) { val_ /= val; return *this; } ///< can divide quantity by scalar + ///< can multiply a quantity by a scalar value_type if multiply_typeof_helper<value_type,value_type>::type is convertible to value_type + this_type& operator*=(const value_type& val) { val_ *= val; return *this; } + + ///< can divide a quantity by a scalar value_type if divide_typeof_helper<value_type,value_type>::type is convertible to value_type + this_type& operator/=(const value_type& val) { val_ /= val; return *this; } /// Construct quantity directly from @c value_type (potentially dangerous). static this_type from_value(const value_type& val) { return this_type(val); } @@ -217,12 +220,10 @@ // can add or subtract same quantity type this_type& operator+=(const this_type& source) { val_ += source.val_; return *this; } ///< can add quantity of same type this_type& operator-=(const this_type& source) { val_ -= source.val_; return *this; } ///< can subtract quantity of same type - // consider adding *=,/= for dimensionless_type // can multiply or divide by value_type this_type& operator*=(const value_type& val) { val_ *= val; return *this; } ///< can multiply quantity by scalar this_type& operator/=(const value_type& val) { val_ /= val; return *this; } ///< can divide quantity by scalar - // consider adding +=,-= for dimensionless_type /// Construct quantity directly from @c value_type. static this_type from_value(const value_type& val) { return this_type(val); } |