Boost logo

Boost-Commit :

From: steven_at_[hidden]
Date: 2008-05-26 19:10:28


Author: steven_watanabe
Date: 2008-05-26 19:10:28 EDT (Mon, 26 May 2008)
New Revision: 45800
URL: http://svn.boost.org/trac/boost/changeset/45800

Log:
io fixes
Text files modified:
   sandbox/units/boost/units/io.hpp | 188 +++++++++++++++++++++++++++++++++++++--
   sandbox/units/libs/units/example/composite_output.cpp | 2
   2 files changed, 176 insertions(+), 14 deletions(-)

Modified: sandbox/units/boost/units/io.hpp
==============================================================================
--- sandbox/units/boost/units/io.hpp (original)
+++ sandbox/units/boost/units/io.hpp 2008-05-26 19:10:28 EDT (Mon, 26 May 2008)
@@ -321,6 +321,8 @@
 
 } // namespace detail
 
+namespace io_impl {
+
 template<class Dimension,class System>
 inline std::string
 symbol_string(const unit<Dimension,System>&)
@@ -336,17 +338,175 @@
 }
 
 /// INTERNAL ONLY
-template<class Dimension,class System>
+template<class Dimension,class Units>
 inline std::string
-symbol_string(const unit<Dimension, heterogeneous_system<System> >&)
+symbol_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, dimensionless_type> > >&)
 {
     std::string 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);
-
+ detail::symbol_string_impl<mpl::size<Units>::value>::template apply<
+ typename mpl::begin<Units>::type>::value(str);
+
+ return(str);
+}
+
+/// INTERNAL ONLY
+inline std::string
+symbol_string(const unit<dimensionless_type, heterogeneous_system<heterogeneous_system_impl<dimensionless_type, dimensionless_type, dimensionless_type> > >&)
+{
+ return("dimensionless");
+}
+
+/// INTERNAL ONLY
+template<class Scale>
+inline std::string
+symbol_string(const unit<dimensionless_type, heterogeneous_system<heterogeneous_system_impl<dimensionless_type, dimensionless_type, Scale> > >&)
+{
+ std::string str;
+
+ detail::scale_symbol_string_impl<mpl::size<Scale>::value>::template apply<
+ typename mpl::begin<Scale>::type>::value(str);
+
+ return(str);
+}
+
+/// INTERNAL ONLY
+template<class Dimension,class Units,class Scale>
+inline std::string
+symbol_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, Scale> > >&)
+{
+ std::string str;
+
+ detail::scale_symbol_string_impl<mpl::size<Scale>::value>::template apply<
+ typename mpl::begin<Scale>::type>::value(str);
+
+ std::string without_scale = symbol_string(unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, dimensionless_type> > >());
+ if(without_scale == boost::units::io_impl::symbol_string(unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, dimensionless_type> > >())) {
+ str += "(";
+ str += without_scale;
+ str += ")";
+ } else {
+ str += without_scale;
+ }
+
+ return(str);
+}
+
+/// INTERNAL ONLY
+template<class Dimension,class Unit,class UnitScale, class Scale>
+inline std::string
+symbol_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type>, Dimension, Scale> > >&)
+{
+ return(symbol_string(
+ unit<
+ Dimension,
+ heterogeneous_system<
+ heterogeneous_system_impl<
+ list<dim<Unit, static_rational<1> >, dimensionless_type>,
+ Dimension,
+ typename mpl::times<Scale, list<UnitScale, dimensionless_type> >::type
+ >
+ >
+ >()));
+}
+
+/// INTERNAL ONLY
+// disambiguate
+template<class Dimension,class Unit,class UnitScale>
+inline std::string
+symbol_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type>, Dimension, dimensionless_type> > >&)
+{
+ std::string str;
+
+ detail::symbol_string_impl<mpl::size<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type> >::value>::template apply<
+ typename mpl::begin<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type> >::type>::value(str);
+
+ return(str);
+}
+
+/// INTERNAL ONLY
+template<class Dimension,class Units>
+inline std::string
+name_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, dimensionless_type> > >&)
+{
+ std::string str;
+
+ detail::name_string_impl<mpl::size<Units>::value>::template apply<
+ typename mpl::begin<Units>::type>::value(str);
+
+ return(str);
+}
+
+/// INTERNAL ONLY
+inline std::string
+name_string(const unit<dimensionless_type, heterogeneous_system<heterogeneous_system_impl<dimensionless_type, dimensionless_type, dimensionless_type> > >&)
+{
+ return("dimensionless");
+}
+
+/// INTERNAL ONLY
+template<class Scale>
+inline std::string
+name_string(const unit<dimensionless_type, heterogeneous_system<heterogeneous_system_impl<dimensionless_type, dimensionless_type, Scale> > >&)
+{
+ std::string str;
+
+ detail::scale_name_string_impl<mpl::size<Scale>::value>::template apply<
+ typename mpl::begin<Scale>::type>::value(str);
+
+ return(str);
+}
+
+/// INTERNAL ONLY
+template<class Dimension,class Units,class Scale>
+inline std::string
+name_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, Scale> > >&)
+{
+ std::string str;
+
+ detail::scale_name_string_impl<mpl::size<Scale>::value>::template apply<
+ typename mpl::begin<Scale>::type>::value(str);
+
+ std::string without_scale = name_string(unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, dimensionless_type> > >());
+ if(without_scale == boost::units::io_impl::name_string(unit<Dimension, heterogeneous_system<heterogeneous_system_impl<Units, Dimension, dimensionless_type> > >())) {
+ str += "(";
+ str += without_scale;
+ str += ")";
+ } else {
+ str += without_scale;
+ }
+
+ return(str);
+}
+
+/// INTERNAL ONLY
+template<class Dimension,class Unit,class UnitScale, class Scale>
+inline std::string
+name_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type>, Dimension, Scale> > >&)
+{
+ return(name_string(
+ unit<
+ Dimension,
+ heterogeneous_system<
+ heterogeneous_system_impl<
+ list<dim<Unit, static_rational<1> >, dimensionless_type>,
+ Dimension,
+ typename mpl::times<Scale, list<UnitScale, dimensionless_type> >::type
+ >
+ >
+ >()));
+}
+
+/// INTERNAL ONLY
+// disambiguate
+template<class Dimension,class Unit,class UnitScale>
+inline std::string
+name_string(const unit<Dimension, heterogeneous_system<heterogeneous_system_impl<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type>, Dimension, dimensionless_type> > >&)
+{
+ std::string str;
+
+ detail::name_string_impl<mpl::size<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type> >::value>::template apply<
+ typename mpl::begin<list<dim<scaled_base_unit<Unit, UnitScale>, static_rational<1> >, dimensionless_type> >::type>::value(str);
     return(str);
 }
 
@@ -360,20 +520,24 @@
         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);
 }
 
+}
+
+using io_impl::symbol_string;
+using io_impl::name_string;
+
 /// 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>
-inline
-std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const unit<Dimension, System>& u)
+inline std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os, const unit<Dimension, System>& u)
 {
- if (units::get_format(os) == symbol)
+ if(units::get_format(os) == symbol)
     {
         os << symbol_string(u);
     }
- else if (units::get_format(os) == name)
+ else if(units::get_format(os) == name)
     {
         os << name_string(u);
     }

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-26 19:10:28 EDT (Mon, 26 May 2008)
@@ -28,13 +28,11 @@
 
 //[composite_output_snippet_1
 
-template<>
 std::string name_string(const cgs::force&)
 {
         return "dyne";
 }
 
-template<>
 std::string symbol_string(const cgs::force&)
 {
         return "dyn";


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