Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55698 - in trunk: boost/units libs/units/test
From: steven_at_[hidden]
Date: 2009-08-21 09:19:37


Author: steven_watanabe
Date: 2009-08-21 09:19:36 EDT (Fri, 21 Aug 2009)
New Revision: 55698
URL: http://svn.boost.org/trac/boost/changeset/55698

Log:
Use base_unit_info when computing the name of a scaled base_unit. Fixes #3360.
Text files modified:
   trunk/boost/units/scale.hpp | 6 ++++--
   trunk/boost/units/scaled_base_unit.hpp | 7 +++++--
   trunk/libs/units/test/test_output.cpp | 19 +++++++++++++++++++
   3 files changed, 28 insertions(+), 4 deletions(-)

Modified: trunk/boost/units/scale.hpp
==============================================================================
--- trunk/boost/units/scale.hpp (original)
+++ trunk/boost/units/scale.hpp 2009-08-21 09:19:36 EDT (Fri, 21 Aug 2009)
@@ -35,8 +35,10 @@
     typedef Exponent exponent;
     typedef double value_type;
     static value_type value() { return(detail::static_rational_power<Exponent>(static_cast<double>(base))); }
- static std::string name() { return ""; };
- static std::string symbol() { return ""; };
+ // These need to be defined in specializations for
+ // printing to work.
+ // static std::string name();
+ // static std::string symbol();
 };
 
 template<long Base, class Exponent>

Modified: trunk/boost/units/scaled_base_unit.hpp
==============================================================================
--- trunk/boost/units/scaled_base_unit.hpp (original)
+++ trunk/boost/units/scaled_base_unit.hpp 2009-08-21 09:19:36 EDT (Fri, 21 Aug 2009)
@@ -37,6 +37,9 @@
 template<class T, class E>
 struct heterogeneous_system_dim;
 
+template<class T>
+struct base_unit_info;
+
 /// INTERNAL ONLY
 struct scaled_base_unit_tag {};
 
@@ -75,11 +78,11 @@
 
     static std::string symbol()
     {
- return(Scale::symbol() + S::symbol());
+ return(Scale::symbol() + base_unit_info<S>::symbol());
     }
     static std::string name()
     {
- return(Scale::name() + S::name());
+ return(Scale::name() + base_unit_info<S>::name());
     }
 };
 

Modified: trunk/libs/units/test/test_output.cpp
==============================================================================
--- trunk/libs/units/test/test_output.cpp (original)
+++ trunk/libs/units/test/test_output.cpp 2009-08-21 09:19:36 EDT (Fri, 21 Aug 2009)
@@ -69,6 +69,19 @@
 
 typedef boost::units::make_scaled_unit<scaled_length, boost::units::scale<2, boost::units::static_rational<10> > >::type double_scaled_length;
 
+typedef boost::units::scaled_base_unit<meter_base_unit, boost::units::scale<100, boost::units::static_rational<1> > > scaled_length_base_unit;
+namespace boost {
+namespace units {
+template<>
+struct base_unit_info<scaled_length_base_unit> {
+ static const char* symbol() { return("scm"); }
+ static const char* name() { return("scaled_meter"); }
+};
+}
+}
+typedef boost::units::scaled_base_unit<scaled_length_base_unit, boost::units::scale<10, boost::units::static_rational<3> > > double_scaled_length_base_unit;
+typedef double_scaled_length_base_unit::unit_type double_scaled_length2;
+
 typedef boost::units::reduce_unit<boost::units::unit<boost::units::volume_dimension, my_system> >::type custom1;
 
 std::string name_string(const custom1&) { return("custom1"); }
@@ -119,6 +132,7 @@
     BOOST_UNITS_TEST_OUTPUT(area(), "m^2");
     BOOST_UNITS_TEST_OUTPUT(scaled_area(), "k(m^2)");
     BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "Kikm");
+ BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kscm");
     BOOST_UNITS_TEST_OUTPUT(custom1(), "c1");
     BOOST_UNITS_TEST_OUTPUT(custom2(), "c2");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kc1");
@@ -139,6 +153,7 @@
     BOOST_UNITS_TEST_OUTPUT(area(), "m^2");
     BOOST_UNITS_TEST_OUTPUT(scaled_area(), "k(m^2)");
     BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "Kikm");
+ BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kscm");
     // when using raw format, we ignore the user defined overloads
     BOOST_UNITS_TEST_OUTPUT(custom1(), "m^3");
     BOOST_UNITS_TEST_OUTPUT(custom2(), "m s^-2");
@@ -160,6 +175,7 @@
     BOOST_UNITS_TEST_OUTPUT(area(), "meter^2");
     BOOST_UNITS_TEST_OUTPUT(scaled_area(), "kilo(meter^2)");
     BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "kibikilometer");
+ BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kiloscaled_meter");
     BOOST_UNITS_TEST_OUTPUT(custom1(), "custom1");
     BOOST_UNITS_TEST_OUTPUT(custom2(), "custom2");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kilocustom1");
@@ -181,6 +197,7 @@
     BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)");
     BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 Kikm");
+ BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm");
     BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 c1");
     BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 c2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kc1");
@@ -201,6 +218,7 @@
     BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)");
     BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 Kikm");
+ BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm");
     // when using raw format, we ignore the user defined overloads
     BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 m^3");
     BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 m s^-2");
@@ -222,6 +240,7 @@
     BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 meter^2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 kilo(meter^2)");
     BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 kibikilometer");
+ BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kiloscaled_meter");
     BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 custom1");
     BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 custom2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kilocustom1");


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