Boost logo

Boost-Commit :

From: steven_watanabe_at_[hidden]
Date: 2007-06-07 15:58:13


Author: steven_watanabe
Date: 2007-06-07 15:58:12 EDT (Thu, 07 Jun 2007)
New Revision: 4490
URL: http://svn.boost.org/trac/boost/changeset/4490

Log:
Added macros for conversion partial specialization and direct use on base_units

Text files modified:
   sandbox/units/boost/units/conversion.hpp | 99 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 99 insertions(+), 0 deletions(-)

Modified: sandbox/units/boost/units/conversion.hpp
==============================================================================
--- sandbox/units/boost/units/conversion.hpp (original)
+++ sandbox/units/boost/units/conversion.hpp 2007-06-07 15:58:12 EDT (Thu, 07 Jun 2007)
@@ -17,6 +17,7 @@
 #include <boost/mpl/next.hpp>
 #include <boost/mpl/deref.hpp>
 #include <boost/mpl/divides.hpp>
+#include <boost/preprocessor/seq/enum.hpp>
 #include <boost/type_traits/is_same.hpp>
 
 #include <boost/units/dimension_list.hpp>
@@ -174,6 +175,86 @@
>::template apply<Source, Dest>
 {};
 
+/// Defines the conversion factor from a base unit to any other base
+/// unit with the same dimensions. Must appear at global scope.
+/// If the destination unit is a unit that contains only one
+/// base unit which is raised to the first power (e.g. feet->meters)
+/// the reverse need not be defined.
+#define BOOST_UNITS_DEFINE_BASE_CONVERSION(Source, Destination, type_, value_) \
+namespace boost { \
+namespace units { \
+ template<> \
+ struct select_base_unit_converter< \
+ unscale<Source>::type, \
+ unit< \
+ Source::dimension_type, \
+ heterogeneous_system< \
+ heterogeneous_system_pair< \
+ unscale<Destination>::type, \
+ Source::dimension_type \
+ > \
+ > \
+ > \
+ > \
+ { \
+ typedef Source source_type; \
+ typedef unit< \
+ Source::dimension_type, \
+ heterogeneous_system< \
+ heterogeneous_system_pair< \
+ Destination, \
+ Source::dimension_type> > > destination_type; \
+ }; \
+ template<> \
+ struct base_unit_converter< \
+ Source, \
+ unit< \
+ Source::dimension_type, \
+ heterogeneous_system< \
+ heterogeneous_system_pair< \
+ unscale<Destination>::type, \
+ Source::dimension_type \
+ > \
+ > \
+ > \
+ > \
+ { \
+ typedef type_ type; \
+ static type value() { return(value_); } \
+ }; \
+} \
+} \
+void boost_units_require_semicolon()
+
+/// Defines the conversion factor from a base unit to any other base
+/// unit with the same dimensions. Must appear at global scope.
+/// If the destination unit is a unit that contains only one
+/// base unit which is raised to the first power (e.g. feet->meters)
+/// the reverse need not be defined. Does not work with scaling. Sigh.
+#define BOOST_UNITS_DEFINE_BASE_CONVERSION_TEMPLATE(Params, Source, Destination, type_, value_) \
+namespace boost { \
+namespace units { \
+ template<BOOST_PP_SEQ_ENUM(Params)> \
+ struct base_unit_converter< \
+ Source, \
+ unit< \
+ Source::dimension_type, \
+ heterogeneous_system< \
+ heterogeneous_system_pair< \
+ unscale<Destination>::type, \
+ Source::dimension_type \
+ > \
+ > \
+ > \
+ > \
+ { \
+ typedef type_ type; \
+ static type value() { return(value_); } \
+ }; \
+} \
+} \
+void boost_units_require_semicolon()
+
 /// Defines the conversion factor from a base unit to any unit
 /// with the correct dimensions. Must appear at global scope.
 /// If the destination unit is a unit that contains only one
@@ -201,6 +282,24 @@
 } \
 void boost_units_require_semicolon()
 
+/// Defines the conversion factor from a base unit to any unit
+/// with the correct dimensions. Must appear at global scope.
+/// If the destination unit is a unit that contains only one
+/// base unit which is raised to the first power (e.g. feet->meters)
+/// the reverse need not be defined. Does not work with scaling. Sigh.
+#define BOOST_UNITS_DEFINE_CONVERSION_TEMPLATE(Params, Source, Destination, type_, value_) \
+namespace boost { \
+namespace units { \
+ template<BOOST_PP_SEQ_ENUM(Params)> \
+ struct base_unit_converter<Source, reduce_unit<Destination>::type> \
+ { \
+ typedef type_ type; \
+ static type value() { return(value_); } \
+ }; \
+} \
+} \
+void boost_units_require_semicolon()
+
 namespace detail {
 
 template<int N>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk