Boost logo

Boost-Commit :

From: boost_at_[hidden]
Date: 2008-05-25 23:34:45


Author: matthiasschabel
Date: 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
New Revision: 45761
URL: http://svn.boost.org/trac/boost/changeset/45761

Log:
rework I/O to use name_string and symbol_string free functions to create string representation of unit.

almost everything works, except a minor problem with scaled quantities
Added:
   sandbox/units/boost/units/systems/si/io.hpp (contents, props changed)
Text files modified:
   sandbox/units/boost/units/io.hpp | 270 +++++++++++++++++++++++++--------------
   sandbox/units/boost/units/systems/si.hpp | 1
   sandbox/units/boost/units/systems/si/absorbed_dose.hpp | 9 -
   sandbox/units/boost/units/systems/si/activity.hpp | 9 -
   sandbox/units/boost/units/systems/si/angular_velocity.hpp | 8 -
   sandbox/units/boost/units/systems/si/capacitance.hpp | 8 -
   sandbox/units/boost/units/systems/si/catalytic_activity.hpp | 8 -
   sandbox/units/boost/units/systems/si/conductance.hpp | 8 -
   sandbox/units/boost/units/systems/si/dose_equivalent.hpp | 9 -
   sandbox/units/boost/units/systems/si/dynamic_viscosity.hpp | 8 -
   sandbox/units/boost/units/systems/si/electric_charge.hpp | 8 -
   sandbox/units/boost/units/systems/si/electric_potential.hpp | 8 -
   sandbox/units/boost/units/systems/si/energy.hpp | 8 -
   sandbox/units/boost/units/systems/si/force.hpp | 8 -
   sandbox/units/boost/units/systems/si/frequency.hpp | 8 -
   sandbox/units/boost/units/systems/si/illuminance.hpp | 8 -
   sandbox/units/boost/units/systems/si/inductance.hpp | 8 -
   sandbox/units/boost/units/systems/si/luminous_flux.hpp | 8 -
   sandbox/units/boost/units/systems/si/magnetic_flux.hpp | 8 -
   sandbox/units/boost/units/systems/si/magnetic_flux_density.hpp | 8 -
   sandbox/units/boost/units/systems/si/permeability.hpp | 8 -
   sandbox/units/boost/units/systems/si/permittivity.hpp | 8 -
   sandbox/units/boost/units/systems/si/power.hpp | 8 -
   sandbox/units/boost/units/systems/si/pressure.hpp | 8 -
   sandbox/units/boost/units/systems/si/resistance.hpp | 8 -
   sandbox/units/boost/units/systems/si/surface_tension.hpp | 8 -
   sandbox/units/boost/units/systems/si/torque.hpp | 8 -
   sandbox/units/boost/units/units_fwd.hpp | 2
   sandbox/units/libs/units/example/composite_output.cpp | 26 ++-
   29 files changed, 195 insertions(+), 307 deletions(-)

Modified: sandbox/units/boost/units/io.hpp
==============================================================================
--- sandbox/units/boost/units/io.hpp (original)
+++ sandbox/units/boost/units/io.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -49,20 +49,34 @@
 
 namespace units {
 
-/// Write integral-valued @c static_rational to @c std::basic_ostream.
-template<class Char, class Traits, integer_type N>
-inline std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,const static_rational<N>&)
+// get string representation of arbitrary type
+template<class T> std::string to_string(const T& t)
 {
- os << N;
- return os;
+ std::stringstream sstr;
+
+ sstr << t;
+
+ return sstr.str();
+}
+
+// get string representation of integral-valued @c static_rational
+template<integer_type N> std::string to_string(const static_rational<N>& r)
+{
+ return to_string(r.numerator());
+}
+
+// get string representation of @c static_rational
+template<integer_type N, integer_type D> std::string to_string(const static_rational<N,D>& r)
+{
+ return '(' + to_string(r.numerator()) + '/' + to_string(r.denominator()) + ')';
 }
 
 /// Write @c static_rational to @c std::basic_ostream.
 template<class Char, class Traits, integer_type N, integer_type D>
-inline std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,const static_rational<N, D>&)
+inline std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,const static_rational<N,D>& r)
 {
- os << '(' << N << '/' << D << ')';
- return os;
+ os << to_string(r);
+ return os;
 }
 
 /// traits template for unit names
@@ -161,160 +175,224 @@
 
 namespace detail {
 
-// This is needed so that std::string can be returned from
-// the base unit functions and will allow the operators
-// to work for any std::basic_ostream
 template<class T>
-const T& adapt_for_print(const T& t)
+std::string base_unit_symbol_string(const T&)
 {
- return(t);
+ return base_unit_info<typename T::tag_type>::symbol() + '^' + to_string(typename T::value_type());
 }
 
-template<class Char, class Traits, class Allocator>
-const Char* adapt_for_print(const std::basic_string<Char, Traits, Allocator>& s)
+template<class T>
+std::string base_unit_name_string(const T&)
 {
- return(s.c_str());
+ return base_unit_info<typename T::tag_type>::name() + '^' + to_string(typename T::value_type());
 }
 
-template<class T, class Os>
-void print_base_unit(Os& os, const T&)
+// stringify with symbols
+template<int N>
+struct symbol_string_impl
 {
- if(units::get_format(os) == symbol) {
- os << (adapt_for_print)(base_unit_info<typename T::tag_type>::symbol()) << '^' << typename T::value_type();
- } else if(units::get_format(os) == name) {
- os << (adapt_for_print)(base_unit_info<typename T::tag_type>::name()) << '^' << typename T::value_type();
- } else {
- assert(!"The format mode must be either name or symbol");
- }
-}
+ template<class Begin>
+ struct apply
+ {
+ typedef typename symbol_string_impl<N-1>::template apply<typename mpl::next<Begin>::type> next;
+ static void value(std::string& str)
+ {
+ str += base_unit_symbol_string(typename mpl::deref<Begin>::type()) + ' ';
+ next::value(str);
+ }
+ };
+};
 
-template<class Unit, class Os>
-void print_base_unit(Os& os, const heterogeneous_system_dim<Unit, static_rational<1> >&)
+template<>
+struct symbol_string_impl<1>
 {
- if(units::get_format(os) == symbol) {
- os << (adapt_for_print)(base_unit_info<Unit>::symbol());
- } else if(units::get_format(os) == name) {
- os << (adapt_for_print)(base_unit_info<Unit>::name());
- } else {
- assert(!"The format mode must be either name or symbol");
- }
-}
+ template<class Begin>
+ struct apply
+ {
+ static void value(std::string& str)
+ {
+ str += base_unit_symbol_string(typename mpl::deref<Begin>::type());
+ };
+ };
+};
+
+template<>
+struct symbol_string_impl<0>
+{
+ template<class Begin>
+ struct apply
+ {
+ static void value(std::string& str)
+ {
+ // better shorthand for dimensionless?
+ str += "dimensionless";
+ }
+ };
+};
 
 template<int N>
-struct print_impl
+struct scale_symbol_string_impl
 {
- template<class Begin, class Os>
+ template<class Begin>
+ struct apply
+ {
+ static void value(std::string& str)
+ {
+ str += mpl::deref<Begin>::type::base::symbol() + ' ';
+ scale_symbol_string_impl<N - 1>::template apply<typename mpl::next<Begin>::type>::value(str);
+ }
+ };
+};
+
+template<>
+struct scale_symbol_string_impl<0>
+{
+ template<class Begin>
+ struct apply
+ {
+ static void value(std::string&) { }
+ };
+};
+
+// stringify with names
+template<int N>
+struct name_string_impl
+{
+ template<class Begin>
     struct apply
     {
- typedef typename print_impl<N-1>::template apply<typename mpl::next<Begin>::type, Os> next;
- static void value(Os& os)
+ typedef typename name_string_impl<N-1>::template apply<typename mpl::next<Begin>::type> next;
+ static void value(std::string& str)
         {
- (print_base_unit)(os, typename mpl::deref<Begin>::type());
- os << ' ';
- next::value(os);
+ str += base_unit_name_string(typename mpl::deref<Begin>::type()) + ' ';
+ next::value(str);
         }
     };
 };
 
 template<>
-struct print_impl<1>
+struct name_string_impl<1>
 {
- template<class Begin, class Os>
+ template<class Begin>
     struct apply
     {
- static void value(Os& os)
+ static void value(std::string& str)
         {
- (print_base_unit)(os, typename mpl::deref<Begin>::type());
+ str += base_unit_name_string(typename mpl::deref<Begin>::type());
         };
     };
 };
 
 template<>
-struct print_impl<0>
+struct name_string_impl<0>
 {
- template<class Begin, class Os>
+ template<class Begin>
     struct apply
     {
- static void value(Os& os)
+ static void value(std::string& str)
         {
- os << "dimensionless";
+ // better shorthand for dimensionless?
+ str += "dimensionless";
         }
     };
 };
 
 template<int N>
-struct print_scale_impl {
- template<class Begin, class Os>
- struct apply {
- static void value(Os& os) {
- os << mpl::deref<Begin>::type::base << '^' << typename mpl::deref<Begin>::type::exponent() << ' ';
- print_scale_impl<N - 1>::template apply<typename mpl::next<Begin>::type, Os>::value(os);
+struct scale_name_string_impl
+{
+ template<class Begin>
+ struct apply
+ {
+ static void value(std::string& str)
+ {
+ str += mpl::deref<Begin>::type::base::name() + ' ';
+ scale_name_string_impl<N - 1>::template apply<typename mpl::next<Begin>::type>::value(str);
         }
     };
 };
 
 template<>
-struct print_scale_impl<0> {
- template<class Begin, class Os>
- struct apply {
- static void value(Os&) { }
+struct scale_name_string_impl<0>
+{
+ template<class Begin>
+ struct apply
+ {
+ static void value(std::string&) { }
     };
 };
 
 } // namespace detail
 
-/// Print an @c unit as a list of base units and exponents e.g "m s^-1"
-template<class Char, class Traits, class Dimension, class System>
-std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const unit<Dimension, System>&)
-{
- os << typename reduce_unit<unit<Dimension, System> >::type();
- return(os);
-}
-
-/// INTERNAL ONLY
-template<class Char, class Traits, class Dimension, class System>
-std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const unit<Dimension, heterogeneous_system<System> >&)
+template<class Dimension,class System>
+inline std::string
+symbol_string(const unit<Dimension,System>&)
 {
- detail::print_scale_impl<mpl::size<typename System::scale>::value>::template apply<
- typename mpl::begin<typename System::scale>::type,
- std::basic_ostream<Char, Traits>
- >::value(os);
- detail::print_impl<mpl::size<typename System::type>::value>::template apply<
- typename mpl::begin<typename System::type>::type,
- std::basic_ostream<Char, Traits> >::value(os);
- return(os);
+ return symbol_string(typename reduce_unit<unit<Dimension, System> >::type());
 }
 
-/// Print a @c quantity. Prints the value followed by the unit
-template<class Char, class Traits, class Unit, class T>
-std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const quantity<Unit, T>& q)
+template<class Dimension,class System>
+inline std::string
+name_string(const unit<Dimension,System>&)
 {
- os << q.value() << ' ' << Unit();
- return(os);
+ return name_string(typename reduce_unit<unit<Dimension, System> >::type());
 }
 
-// quick and dirty solution - should replace guts with implementation in operator<< above to directly create string
+/// INTERNAL ONLY
 template<class Dimension,class System>
 inline std::string
-symbol_string(const unit<Dimension,System>& u)
+symbol_string(const unit<Dimension, heterogeneous_system<System> >&)
 {
- std::stringstream sstr;
+ std::string str;
         
- sstr << u;
-
- return sstr.str();
+ detail::scale_symbol_string_impl<mpl::size<typename System::scale>::value>::template apply<
+ typename mpl::begin<typename System::scale>::type>::value(str);
+ detail::symbol_string_impl<mpl::size<typename System::type>::value>::template apply<
+ typename mpl::begin<typename System::type>::type>::value(str);
+ return(str);
 }
 
-// quick and dirty solution - should replace guts with implementation in operator<< above to directly create string
 template<class Dimension,class System>
 inline std::string
-name_string(const unit<Dimension,System>& u)
+name_string(const unit<Dimension, heterogeneous_system<System> >&)
 {
- std::stringstream sstr;
+ std::string str;
         
- sstr << name_format << u;
+ detail::scale_name_string_impl<mpl::size<typename System::scale>::value>::template apply<
+ typename mpl::begin<typename System::scale>::type>::value(str);
+ detail::name_string_impl<mpl::size<typename System::type>::value>::template apply<
+ typename mpl::begin<typename System::type>::type>::value(str);
+ return(str);
+}
+
+/// Print an @c unit as a list of base units and exponents e.g "m s^-1"
+template<class Char, class Traits, class Dimension, class System>
+std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const unit<Dimension, System>& u)
+{
+// os << typename reduce_unit<unit<Dimension, System> >::type();
+// return(os);
+ if(units::get_format(os) == symbol)
+ {
+ os << symbol_string(u);
+ }
+ else if(units::get_format(os) == name)
+ {
+ os << name_string(u);
+ }
+ else
+ {
+ assert(!"The format mode must be either name or symbol");
+ }
         
- return sstr.str();
+ return(os);
+}
+
+/// INTERNAL ONLY
+/// Print a @c quantity. Prints the value followed by the unit
+template<class Char, class Traits, class Unit, class T>
+std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const quantity<Unit, T>& q)
+{
+ os << q.value() << ' ' << Unit();
+ return(os);
 }
 
 } // namespace units

Modified: sandbox/units/boost/units/systems/si.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si.hpp (original)
+++ sandbox/units/boost/units/systems/si.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -62,6 +62,7 @@
 #include <boost/units/systems/si/resistivity.hpp>
 #include <boost/units/systems/si/solid_angle.hpp>
 #include <boost/units/systems/si/surface_density.hpp>
+#include <boost/units/systems/si/surface_tension.hpp>
 #include <boost/units/systems/si/temperature.hpp>
 #include <boost/units/systems/si/time.hpp>
 #include <boost/units/systems/si/torque.hpp>

Modified: sandbox/units/boost/units/systems/si/absorbed_dose.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/absorbed_dose.hpp (original)
+++ sandbox/units/boost/units/systems/si/absorbed_dose.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_ABSORBED_DOSE_HPP
 #define BOOST_UNITS_SI_ABSORBED_DOSE_HPP
 
-//#include <ostream>
-//#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/absorbed_dose.hpp>
 
@@ -30,12 +27,6 @@
 
 } // namespace si
 
-// Gy and Sv are dimensionally indistinguishable
-//inline std::ostream& operator<<(std::ostream& os, const boost::units::si::absorbed_dose&)
-//{
-// return(os << "Gy");
-//}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/activity.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/activity.hpp (original)
+++ sandbox/units/boost/units/systems/si/activity.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_ACTIVITY_HPP
 #define BOOST_UNITS_SI_ACTIVITY_HPP
 
-//#include <ostream>
-//#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/activity.hpp>
 
@@ -30,12 +27,6 @@
 
 } // namespace si
 
-// activity is dimensionally indistinguishable from frequency
-//inline std::ostream& operator<<(std::ostream& os, const boost::units::si::activity&)
-//{
-// return(os << "Bq");
-//}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/angular_velocity.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/angular_velocity.hpp (original)
+++ sandbox/units/boost/units/systems/si/angular_velocity.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_ANGULAR_VELOCITY_HPP
 #define BOOST_UNITS_SI_ANGULAR_VELOCITY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/angular_velocity.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::angular_velocity&)
-{
- return(os << "rad/s");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/capacitance.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/capacitance.hpp (original)
+++ sandbox/units/boost/units/systems/si/capacitance.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_CAPACITANCE_HPP
 #define BOOST_UNITS_SI_CAPACITANCE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/capacitance.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::capacitance&)
-{
- return(os << "F");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/catalytic_activity.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/catalytic_activity.hpp (original)
+++ sandbox/units/boost/units/systems/si/catalytic_activity.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_CATALYTIC_ACTIVITY_HPP
 #define BOOST_UNITS_SI_CATALYTIC_ACTIVITY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/derived_dimension.hpp>
 #include <boost/units/systems/si/base.hpp>
 
@@ -33,11 +30,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::catalytic_activity&)
-{
- return(os << "kat");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/conductance.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/conductance.hpp (original)
+++ sandbox/units/boost/units/systems/si/conductance.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_CONDUCTANCE_HPP
 #define BOOST_UNITS_SI_CONDUCTANCE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/conductance.hpp>
 
@@ -32,11 +29,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::conductance&)
-{
- return(os << "S");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/dose_equivalent.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/dose_equivalent.hpp (original)
+++ sandbox/units/boost/units/systems/si/dose_equivalent.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_DOSE_EQUIVALENT_HPP
 #define BOOST_UNITS_SI_DOSE_EQUIVALENT_HPP
 
-//#include <ostream>
-//#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/dose_equivalent.hpp>
 
@@ -30,12 +27,6 @@
 
 } // namespace si
 
-// Gy and Sv are dimensionally indistinguishable
-//inline std::ostream& operator<<(std::ostream& os, const boost::units::si::dose_equivalent&)
-//{
-// return(os << "Sv");
-//}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/dynamic_viscosity.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/dynamic_viscosity.hpp (original)
+++ sandbox/units/boost/units/systems/si/dynamic_viscosity.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_DYNAMIC_VISCOSITY_HPP
 #define BOOST_UNITS_SI_DYNAMIC_VISCOSITY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/dynamic_viscosity.hpp>
 
@@ -27,11 +24,6 @@
     
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::dynamic_viscosity&)
-{
- return(os << "Pa s");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/electric_charge.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/electric_charge.hpp (original)
+++ sandbox/units/boost/units/systems/si/electric_charge.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_ELECTRIC_CHARGE_HPP
 #define BOOST_UNITS_SI_ELECTRIC_CHARGE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/electric_charge.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::electric_charge&)
-{
- return(os << "C");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/electric_potential.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/electric_potential.hpp (original)
+++ sandbox/units/boost/units/systems/si/electric_potential.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_ELECTRIC_POTENTIAL_HPP
 #define BOOST_UNITS_SI_ELECTRIC_POTENTIAL_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/electric_potential.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::electric_potential&)
-{
- return(os << "V");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/energy.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/energy.hpp (original)
+++ sandbox/units/boost/units/systems/si/energy.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_ENERGY_HPP
 #define BOOST_UNITS_SI_ENERGY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/energy.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::energy&)
-{
- return(os << "J");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/force.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/force.hpp (original)
+++ sandbox/units/boost/units/systems/si/force.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_FORCE_HPP
 #define BOOST_UNITS_SI_FORCE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/force.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::force&)
-{
- return(os << "N");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/frequency.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/frequency.hpp (original)
+++ sandbox/units/boost/units/systems/si/frequency.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_FREQUENCY_HPP
 #define BOOST_UNITS_SI_FREQUENCY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/frequency.hpp>
 
@@ -29,11 +26,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::frequency&)
-{
- return(os << "Hz");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/illuminance.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/illuminance.hpp (original)
+++ sandbox/units/boost/units/systems/si/illuminance.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_ILLUMINANCE_HPP
 #define BOOST_UNITS_SI_ILLUMINANCE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/illuminance.hpp>
 
@@ -29,11 +26,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::illuminance&)
-{
- return(os << "lx");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/inductance.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/inductance.hpp (original)
+++ sandbox/units/boost/units/systems/si/inductance.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_INDUCTANCE_HPP
 #define BOOST_UNITS_SI_INDUCTANCE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/inductance.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::inductance&)
-{
- return(os << "H");
-}
-
 } // namespace units
 
 } // namespace boost

Added: sandbox/units/boost/units/systems/si/io.hpp
==============================================================================
--- (empty file)
+++ sandbox/units/boost/units/systems/si/io.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -0,0 +1,87 @@
+// Boost.Units - A C++ library for zero-overhead dimensional analysis and
+// unit/quantity manipulation and conversion
+//
+// Copyright (C) 2003-2008 Matthias Christian Schabel
+// Copyright (C) 2008 Steven Watanabe
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_UNITS_SI_IO_HPP
+#define BOOST_UNITS_SI_IO_HPP
+
+#include <boost/units/io.hpp>
+
+#include <boost/units/systems/si.hpp>
+
+namespace boost {
+
+namespace units {
+
+// gray and sievert are indistinguishable
+//inline std::string name_string(const si::absorbed_dose&) { return "gray"; }
+//inline std::string symbol_string(const si::absorbed_dose&) { return "Gy"; }
+
+// activity and frequency are indistinguishable
+//inline std::string name_string(const si::activity&) { return "becquerel"; }
+//inline std::string symbol_string(const si::activity&) { return "Bq"; }
+
+inline std::string name_string(const si::capacitance&) { return "farad"; }
+inline std::string symbol_string(const si::capacitance&) { return "F"; }
+
+inline std::string name_string(const si::catalytic_activity&) { return "katal"; }
+inline std::string symbol_string(const si::catalytic_activity&) { return "kat"; }
+
+inline std::string name_string(const si::conductance&) { return "siemen"; }
+inline std::string symbol_string(const si::conductance&) { return "S"; }
+
+// gray and sievert are indistinguishable
+//inline std::string name_string(const si::dose_equivalent&) { return "sievert"; }
+//inline std::string symbol_string(const si::dose_equivalent&) { return "Sv"; }
+
+inline std::string name_string(const si::electric_charge&) { return "coulomb"; }
+inline std::string symbol_string(const si::electric_charge&) { return "C"; }
+
+inline std::string name_string(const si::electric_potential&) { return "volt"; }
+inline std::string symbol_string(const si::electric_potential&) { return "V"; }
+
+inline std::string name_string(const si::energy&) { return "joule"; }
+inline std::string symbol_string(const si::energy&) { return "J"; }
+
+inline std::string name_string(const si::force&) { return "newton"; }
+inline std::string symbol_string(const si::force&) { return "N"; }
+
+inline std::string name_string(const si::frequency&) { return "hertz"; }
+inline std::string symbol_string(const si::frequency&) { return "Hz"; }
+
+inline std::string name_string(const si::illuminance&) { return "lux"; }
+inline std::string symbol_string(const si::illuminance&) { return "lx"; }
+
+inline std::string name_string(const si::inductance&) { return "henry"; }
+inline std::string symbol_string(const si::inductance&) { return "H"; }
+
+inline std::string name_string(const si::luminous_flux&) { return "lumen"; }
+inline std::string symbol_string(const si::luminous_flux&) { return "lm"; }
+
+inline std::string name_string(const si::magnetic_flux&) { return "weber"; }
+inline std::string symbol_string(const si::magnetic_flux&) { return "Wb"; }
+
+inline std::string name_string(const si::magnetic_flux_density&) { return "tesla"; }
+inline std::string symbol_string(const si::magnetic_flux_density&) { return "T"; }
+
+inline std::string name_string(const si::power&) { return "watt"; }
+inline std::string symbol_string(const si::power&) { return "W"; }
+
+inline std::string name_string(const si::pressure&) { return "pascal"; }
+inline std::string symbol_string(const si::pressure&) { return "Pa"; }
+
+inline std::string name_string(const si::resistance&) { return "ohm"; }
+inline std::string symbol_string(const si::resistance&) { return "Ω"; }
+
+
+} // namespace units
+
+} // namespace boost
+
+#endif // BOOST_UNITS_SI_IO_HPP

Modified: sandbox/units/boost/units/systems/si/luminous_flux.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/luminous_flux.hpp (original)
+++ sandbox/units/boost/units/systems/si/luminous_flux.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_LUMINOUS_FLUX_HPP
 #define BOOST_UNITS_SI_LUMINOUS_FLUX_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/luminous_flux.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::luminous_flux&)
-{
- return(os << "lm");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/magnetic_flux.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/magnetic_flux.hpp (original)
+++ sandbox/units/boost/units/systems/si/magnetic_flux.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_MAGNETIC_FLUX_HPP
 #define BOOST_UNITS_SI_MAGNETIC_FLUX_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/magnetic_flux.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::magnetic_flux&)
-{
- return(os << "Wb");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/magnetic_flux_density.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/magnetic_flux_density.hpp (original)
+++ sandbox/units/boost/units/systems/si/magnetic_flux_density.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_MAGNETIC_FLUX_DENSITY_HPP
 #define BOOST_UNITS_SI_MAGNETIC_FLUX_DENSITY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/magnetic_flux_density.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::magnetic_flux_density&)
-{
- return(os << "T");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/permeability.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/permeability.hpp (original)
+++ sandbox/units/boost/units/systems/si/permeability.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_PERMEABILITY_HPP
 #define BOOST_UNITS_SI_PERMEABILITY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/permeability.hpp>
 
@@ -27,11 +24,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::permeability&)
-{
- return(os << "H/m");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/permittivity.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/permittivity.hpp (original)
+++ sandbox/units/boost/units/systems/si/permittivity.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_PERMITTIVITY_HPP
 #define BOOST_UNITS_SI_PERMITTIVITY_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/permittivity.hpp>
 
@@ -27,11 +24,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::permittivity&)
-{
- return(os << "F/m");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/power.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/power.hpp (original)
+++ sandbox/units/boost/units/systems/si/power.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_POWER_HPP
 #define BOOST_UNITS_SI_POWER_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/power.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::power&)
-{
- return(os << "W");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/pressure.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/pressure.hpp (original)
+++ sandbox/units/boost/units/systems/si/pressure.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_PRESSURE_HPP
 #define BOOST_UNITS_SI_PRESSURE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/pressure.hpp>
 
@@ -45,11 +42,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::pressure&)
-{
- return(os << "Pa");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/resistance.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/resistance.hpp (original)
+++ sandbox/units/boost/units/systems/si/resistance.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_RESISTANCE_HPP
 #define BOOST_UNITS_SI_RESISTANCE_HPP
 
-#include <ostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/resistance.hpp>
 
@@ -30,11 +27,6 @@
                                             
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::resistance&)
-{
- return(os << "ohm");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/surface_tension.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/surface_tension.hpp (original)
+++ sandbox/units/boost/units/systems/si/surface_tension.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_SURFACE_TENSION_HPP
 #define BOOST_UNITS_SI_SURFACE_TENSION_HPP
 
-#include <iostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/surface_tension.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::surface_tension&)
-{
- return(os << "N/m");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/systems/si/torque.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/torque.hpp (original)
+++ sandbox/units/boost/units/systems/si/torque.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -11,9 +11,6 @@
 #ifndef BOOST_UNITS_SI_TORQUE_HPP
 #define BOOST_UNITS_SI_TORQUE_HPP
 
-#include <iostream>
-#include <boost/units/io.hpp>
-
 #include <boost/units/systems/si/base.hpp>
 #include <boost/units/physical_dimensions/torque.hpp>
 
@@ -30,11 +27,6 @@
 
 } // namespace si
 
-inline std::ostream& operator<<(std::ostream& os, const boost::units::si::torque&)
-{
- return(os << "N m");
-}
-
 } // namespace units
 
 } // namespace boost

Modified: sandbox/units/boost/units/units_fwd.hpp
==============================================================================
--- sandbox/units/boost/units/units_fwd.hpp (original)
+++ sandbox/units/boost/units/units_fwd.hpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -53,7 +53,7 @@
 
 template<class From,class To> struct conversion_helper;
 
-// generate string representation of unit using base_unit names or symbols, respectively
+template<class T> std::string to_string(const T&);
 template<class T> std::string name_string(const T&);
 template<class T> std::string symbol_string(const T&);
 

Modified: sandbox/units/libs/units/example/composite_output.cpp
==============================================================================
--- sandbox/units/libs/units/example/composite_output.cpp (original)
+++ sandbox/units/libs/units/example/composite_output.cpp 2008-05-25 23:34:42 EDT (Sun, 25 May 2008)
@@ -13,6 +13,9 @@
 #include <boost/units/io.hpp>
 #include <boost/units/scale.hpp>
 
+#include <boost/units/systems/si/capacitance.hpp>
+#include <boost/units/systems/si/io.hpp>
+
 #include <iostream>
 #include <sstream>
 
@@ -22,12 +25,6 @@
 
 //[composite_output_snippet_1
 
-std::ostream& operator<<(std::ostream& os, const boost::units::cgs::force&) {
- return(os << "dyn");
-}
-
-//]
-
 template<>
 std::string name_string(const cgs::force&)
 {
@@ -37,9 +34,11 @@
 template<>
 std::string symbol_string(const cgs::force&)
 {
- return "goombah";
+ return "dyn";
 }
 
+//]
+
 }
 
 }
@@ -60,9 +59,22 @@
         std::cout << symbol_string(dyne) << std::endl;
         std::cout << name_string(dyne) << std::endl;
         
+ std::cout << symbol_string(gram*centimeter/second) << std::endl;
+ std::cout << name_string(gram*centimeter/second) << std::endl;
+
         std::cout << symbol_string(gram*centimeter/(second*second)) << std::endl;
         std::cout << name_string(gram*centimeter/(second*second)) << std::endl;
         
         std::cout << symbol_string(scale<10,static_rational<-9> >()) << std::endl;
         std::cout << name_string(scale<10,static_rational<-9> >()) << std::endl;
+
+ // should work...
+// std::cout << symbol_string(scale<10,static_rational<-9> >()*si::farad) << std::endl;
+// std::cout << name_string(scale<10,static_rational<-9> >()*si::farad) << std::endl;
+
+ std::cout << name_format << si::farad << std::endl;
+ std::cout << symbol_format << si::farad << std::endl;
+
+ std::cout << name_format << 1.0*si::farad << std::endl;
+ std::cout << symbol_format << 1.0*si::farad << std::endl;
 }


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