Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53908 - in branches/release: boost/units boost/units/detail libs/units/doc libs/units/example libs/units/test
From: steven_at_[hidden]
Date: 2009-06-14 15:32:28


Author: steven_watanabe
Date: 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
New Revision: 53908
URL: http://svn.boost.org/trac/boost/changeset/53908

Log:
Full merge of units from the trunk. Revisions [51031], [51066], [51189], [52773], [53125], [53293], and [53577]
Added:
   branches/release/libs/units/test/test_output.cpp
      - copied, changed from r53293, /trunk/libs/units/test/test_output.cpp
Text files modified:
   branches/release/boost/units/absolute.hpp | 7 +++----
   branches/release/boost/units/conversion.hpp | 10 +++++++---
   branches/release/boost/units/detail/utility.hpp | 12 ------------
   branches/release/boost/units/io.hpp | 30 ++++++++++++++++++++++--------
   branches/release/libs/units/doc/units.qbk | 13 ++++++++-----
   branches/release/libs/units/example/dimension.cpp | 7 ++-----
   branches/release/libs/units/example/kitchen_sink.cpp | 4 ----
   branches/release/libs/units/test/Jamfile.v2 | 3 ++-
   branches/release/libs/units/test/test_conversion.cpp | 5 +++++
   branches/release/libs/units/test/test_output.cpp | 7 +++++++
   branches/release/libs/units/test/test_unscale.cpp | 6 ++++++
   11 files changed, 62 insertions(+), 42 deletions(-)

Modified: branches/release/boost/units/absolute.hpp
==============================================================================
--- branches/release/boost/units/absolute.hpp (original)
+++ branches/release/boost/units/absolute.hpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -11,8 +11,7 @@
 #ifndef BOOST_UNITS_ABSOLUTE_HPP
 #define BOOST_UNITS_ABSOLUTE_HPP
 
-// necessary because the expression os << "absolute " is not dependent.
-#include <ostream>
+#include <iosfwd>
 
 #include <boost/units/detail/absolute_impl.hpp>
 
@@ -90,8 +89,8 @@
 }
 
 /// Print an absolute unit
-template<class Y>
-std::ostream& operator<<(std::ostream& os,const absolute<Y>& aval)
+template<class Char, class Traits, class Y>
+std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,const absolute<Y>& aval)
 {
 
     os << "absolute " << aval.value();

Modified: branches/release/boost/units/conversion.hpp
==============================================================================
--- branches/release/boost/units/conversion.hpp (original)
+++ branches/release/boost/units/conversion.hpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -41,6 +41,10 @@
 /// }
 /// }
 /// @endcode
+///
+/// In most cases, the predefined specializations for @c unit
+/// and @c absolute should be sufficient, so users should rarely
+/// need to use this.
 template<class From, class To>
 struct conversion_helper
 {
@@ -54,7 +58,7 @@
 /// of this macro must appear at global scope.
 /// If the destination unit is a base unit or a unit that contains
 /// only one base unit which is raised to the first power (e.g. feet->meters)
-/// the reverse (meters->feet in this example) need not be defined.
+/// the reverse (meters->feet in this example) need not be defined explicitly.
 #define BOOST_UNITS_DEFINE_CONVERSION_FACTOR(Source, Destination, type_, value_) \
     namespace boost { \
     namespace units { \
@@ -115,7 +119,7 @@
     struct unscaled_get_default_conversion<unscale<Source>::type> \
     { \
         static const bool is_defined = true; \
- typedef Dest type; \
+ typedef Dest::unit_type type; \
     }; \
     } \
     } \
@@ -134,7 +138,7 @@
     struct unscaled_get_default_conversion<Source> \
     { \
         static const bool is_defined = true; \
- typedef Dest type; \
+ typedef typename Dest::unit_type type; \
     }; \
     } \
     } \

Modified: branches/release/boost/units/detail/utility.hpp
==============================================================================
--- branches/release/boost/units/detail/utility.hpp (original)
+++ branches/release/boost/units/detail/utility.hpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -12,15 +12,9 @@
 #define BOOST_UNITS_UTILITY_HPP
 
 #include <cstdlib>
-#include <complex>
-#include <iostream>
 #include <typeinfo>
 #include <string>
 
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/limits.hpp>
-
 #if defined(__GLIBCXX__) || defined(__GLIBCPP__)
 #define BOOST_UNITS_USE_DEMANGLING
 #include <cxxabi.h>
@@ -53,13 +47,7 @@
         
         std::free(realname);
         
- //boost::replace_all(out," ","");
         boost::replace_all(out,"boost::units::","");
- //boost::replace_all(out,"static_rational","R");
- //boost::replace_all(out,"dimensionless_type","dl");
- //boost::replace_all(out,"_base_dimension","_bd");
- //boost::replace_all(out,"_base_unit","_bu");
- //boost::replace_all(out,"heterogeneous_system","hts");
         
         return out;
     }

Modified: branches/release/boost/units/io.hpp
==============================================================================
--- branches/release/boost/units/io.hpp (original)
+++ branches/release/boost/units/io.hpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -533,6 +533,20 @@
     }
 };
 
+template<class Char, class Traits>
+inline void do_print(std::basic_ostream<Char, Traits>& os, const std::string& s) {
+ os << s.c_str();
+}
+
+inline void do_print(std::ostream& os, const std::string& s) {
+ os << s;
+}
+
+template<class Char, class Traits>
+inline void do_print(std::basic_ostream<Char, Traits>& os, const char* s) {
+ os << s;
+}
+
 } // namespace detail
 
 template<class Dimension,class System>
@@ -567,20 +581,20 @@
 {
     if (units::get_format(os) == typename_fmt)
     {
- os << typename_string(u);
- }
+ detail::do_print(os , typename_string(u));
+ }
     else if (units::get_format(os) == raw_fmt)
     {
- os << detail::to_string_impl(u, detail::format_raw_symbol_impl());
- }
+ detail::do_print(os, detail::to_string_impl(u, detail::format_raw_symbol_impl()));
+ }
     else if (units::get_format(os) == symbol_fmt)
     {
- os << symbol_string(u);
- }
+ detail::do_print(os, symbol_string(u));
+ }
     else if (units::get_format(os) == name_fmt)
     {
- os << name_string(u);
- }
+ detail::do_print(os, name_string(u));
+ }
     else
     {
         assert(!"The format mode must be one of: typename_format, raw_format, name_format, symbol_format");

Modified: branches/release/libs/units/doc/units.qbk
==============================================================================
--- branches/release/libs/units/doc/units.qbk (original)
+++ branches/release/libs/units/doc/units.qbk 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -89,7 +89,9 @@
 # Intel CC 9.1, 10.0, and 10.1 on Mac OSX 10.4
 # g++ 3.4.4, 4.2.3, and 4.3.0 on Windows XP
 # Microsoft Visual C++ 7.1, 8.0, and 9.0 on Windows XP
+# Comeau 4.3.10.1 beta2 on Windows XP
 # Metrowerks CodeWarrior 9.2 on Windows XP.
+# Sun CC 5.9 on Solaris and Linux
 
 The following compilers/platforms are known *not* to work :
 
@@ -97,6 +99,7 @@
 # Microsoft Visual C++ 6.0 on Windows XP
 # Microsoft Visual C++ 7.0 on Windows XP
 # Metrowerks CodeWarrior 8.0 on Windows XP.
+# All versions of Borland.
 
 [endsect]
 
@@ -249,11 +252,11 @@
 
 [section:Units Units]
 
-We define a *unit* as a linear combination of base units. Thus, the SI unit corresponding
-to the dimension of force is kg m s^-2, where kg, m, and s are base units. We use the
-notion of a *unit system* such as SI to specify the mapping from a dimension to a
-particular unit so that instead of specifying the base units explicitly, we can just
-ask for the representation of a dimension in a particular system.
+We define a *unit* as a set of base units each of which can be raised to an arbitrary rational
+exponent. Thus, the SI unit corresponding to the dimension of force is kg m s^-2, where kg, m,
+and s are base units. We use the notion of a *unit system* such as SI to specify the mapping
+from a dimension to a particular unit so that instead of specifying the base units explicitly,
+we can just ask for the representation of a dimension in a particular system.
 
 Units are, like dimensions, purely compile-time variables with no associated value.
 Units obey the same algebra as dimensions do; the presence of the unit system serves to ensure that units having identical

Modified: branches/release/libs/units/example/dimension.cpp
==============================================================================
--- branches/release/libs/units/example/dimension.cpp (original)
+++ branches/release/libs/units/example/dimension.cpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -32,14 +32,11 @@
 @endverbatim
 **/
 
-// undefine this if you don't want to demangle symbols
-// need to link with libboost_regex to get demangling functionality
-#define MCS_USE_DEMANGLING
-
 #include <boost/type_traits/is_same.hpp>
-
 #include <boost/mpl/assert.hpp>
 
+#include <iostream>
+
 #include <boost/units/detail/utility.hpp>
 
 #include "test_system.hpp"

Modified: branches/release/libs/units/example/kitchen_sink.cpp
==============================================================================
--- branches/release/libs/units/example/kitchen_sink.cpp (original)
+++ branches/release/libs/units/example/kitchen_sink.cpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -218,12 +218,8 @@
 {
     using namespace boost::units::si;
     
- #if BOOST_UNITS_HAS_TYPEOF
     using namespace constants::codata;
     return (P*V/(R*T));
- #else
- return P*V/(8.314472*(joules/(kelvin*mole))*T);
- #endif // BOOST_UNITS_HAS_TYPEOF
 }
 //]
 

Modified: branches/release/libs/units/test/Jamfile.v2
==============================================================================
--- branches/release/libs/units/test/Jamfile.v2 (original)
+++ branches/release/libs/units/test/Jamfile.v2 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -1,6 +1,6 @@
 # Jamfile.v2
 #
-# Copyright (c) 2007-2008
+# Copyright (c) 2007-2009
 # Steven Watanabe
 #
 # Distributed under the Boost Software License, Version 1.0. (See
@@ -39,6 +39,7 @@
 run test_scaled_conversion.cpp ;
 run test_lambda.cpp ;
 run test_scaled_unit.cpp test_framework ;
+run test_output.cpp test_framework ;
 
 compile-fail fail_implicit_conversion.cpp ;
 compile-fail fail_quantity_construct.cpp ;

Modified: branches/release/libs/units/test/test_conversion.cpp
==============================================================================
--- branches/release/libs/units/test/test_conversion.cpp (original)
+++ branches/release/libs/units/test/test_conversion.cpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -85,6 +85,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(test_dimensionless_conversions) {
+ typedef bu::divide_typeof_helper<bu::cgs::force, bu::si::force>::type mixed_dimensionless;
 
     bu::quantity<bu::si::dimensionless> dimensionless_test1(1.0*bu::cgs::dyne/bu::si::newton);
     BOOST_CHECK(dimensionless_test1 == 1e-5);
@@ -96,6 +97,10 @@
     bu::quantity<bu::divide_typeof_helper<bu::cgs::force, bu::si::force>::type> dimensionless_test3(dimensionless_test2);
     BOOST_UNITS_CHECK_CLOSE(dimensionless_test3.value(), 1.0);
 
+ BOOST_UNITS_CHECK_CLOSE(boost::units::conversion_factor(mixed_dimensionless(), heterogeneous_dimensionless()), 1e-5);
+ BOOST_UNITS_CHECK_CLOSE(boost::units::conversion_factor(heterogeneous_dimensionless(), mixed_dimensionless()), 1e5);
+
+
     //m/cm -> g/kg
     bu::quantity<bu::divide_typeof_helper<bu::si::length, bu::cgs::length>::type> dimensionless_test4(2.0 * bu::si::meters / bu::cgs::centimeters);
     bu::quantity<bu::divide_typeof_helper<bu::cgs::mass, bu::si::mass>::type> dimensionless_test5(dimensionless_test4);

Copied: branches/release/libs/units/test/test_output.cpp (from r53293, /trunk/libs/units/test/test_output.cpp)
==============================================================================
--- /trunk/libs/units/test/test_output.cpp (original)
+++ branches/release/libs/units/test/test_output.cpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -25,6 +25,7 @@
 #include <boost/units/make_scaled_unit.hpp>
 #include <boost/units/base_unit.hpp>
 #include <boost/units/make_system.hpp>
+#include <boost/units/absolute.hpp>
 #include <boost/units/physical_dimensions/length.hpp>
 #include <boost/units/physical_dimensions/time.hpp>
 #include <boost/units/physical_dimensions/velocity.hpp>
@@ -122,6 +123,7 @@
     BOOST_UNITS_TEST_OUTPUT(custom2(), "c2");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kc1");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "kc2");
+ BOOST_UNITS_TEST_OUTPUT(boost::units::absolute<meter_base_unit::unit_type>(), "absolute m");
 #undef FORMATTERS
 }
 
@@ -142,6 +144,7 @@
     BOOST_UNITS_TEST_OUTPUT(custom2(), "m s^-2");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "k(m^3)");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "k(m s^-2)");
+ BOOST_UNITS_TEST_OUTPUT(boost::units::absolute<meter_base_unit::unit_type>(), "absolute m");
 #undef FORMATTERS
 }
 
@@ -161,6 +164,7 @@
     BOOST_UNITS_TEST_OUTPUT(custom2(), "custom2");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kilocustom1");
     BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "kilocustom2");
+ BOOST_UNITS_TEST_OUTPUT(boost::units::absolute<meter_base_unit::unit_type>(), "absolute meter");
 #undef FORMATTERS
 }
 
@@ -181,6 +185,7 @@
     BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 c2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kc1");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kc2");
+ BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute m");
 #undef FORMATTERS
 }
 
@@ -201,6 +206,7 @@
     BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 m s^-2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 k(m^3)");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 k(m s^-2)");
+ BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute m");
 #undef FORMATTERS
 }
 
@@ -220,6 +226,7 @@
     BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 custom2");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kilocustom1");
     BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kilocustom2");
+ BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute meter");
 #undef FORMATTERS
 }
 

Modified: branches/release/libs/units/test/test_unscale.cpp
==============================================================================
--- branches/release/libs/units/test/test_unscale.cpp (original)
+++ branches/release/libs/units/test/test_unscale.cpp 2009-06-14 15:32:26 EDT (Sun, 14 Jun 2009)
@@ -28,6 +28,12 @@
 #include <boost/mpl/assert.hpp>
 #include <boost/type_traits/is_same.hpp>
 
+BOOST_MPL_ASSERT((boost::is_same<boost::units::unscale<boost::units::temperature::fahrenheit_base_unit::unit_type::system_type>::type,
+ boost::units::temperature::fahrenheit_base_unit::unit_type::system_type>));
+
+BOOST_MPL_ASSERT((boost::is_same<boost::units::unscale<boost::units::temperature::fahrenheit_base_unit::unit_type>::type,
+ boost::units::temperature::fahrenheit_base_unit::unit_type>));
+
 BOOST_MPL_ASSERT((boost::is_same<boost::units::unscale<boost::units::reduce_unit<boost::units::temperature::fahrenheit_base_unit::unit_type>::type>::type,
                  boost::units::temperature::fahrenheit_base_unit::unit_type>));
 


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