Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75171 - in trunk: boost/chrono boost/chrono/detail boost/chrono/io libs/chrono/test/io
From: vicente.botet_at_[hidden]
Date: 2011-10-29 16:36:48


Author: viboes
Date: 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
New Revision: 75171
URL: http://svn.boost.org/trac/boost/changeset/75171

Log:
Chrono: Replaced symbol m by min to conform with standards + Added unit_strings facet that would replace the duration_punct facet + extract duratio_style.hpp + try to fix strdup bug on sunstudio + Ratio: Added prefix and symbol functions
Added:
   trunk/boost/chrono/io/duration_style.hpp (contents, props changed)
   trunk/boost/chrono/io/unit_strings.hpp (contents, props changed)
Text files modified:
   trunk/boost/chrono/config.hpp | 1
   trunk/boost/chrono/detail/is_evenly_divisible_by.hpp | 17 +++
   trunk/boost/chrono/io/duration_io.hpp | 163 ++++++++++++++++++++++-----------------
   trunk/boost/chrono/io/duration_unit_string.hpp | 104 +++++++++++++++++++++++--
   trunk/boost/chrono/io/time_point_io.hpp | 1
   trunk/boost/chrono/io/translate.hpp | 13 +++
   trunk/libs/chrono/test/io/duration_input.cpp | 3
   trunk/libs/chrono/test/io/duration_output.cpp | 4
   trunk/libs/chrono/test/io/time_point_input.cpp | 2
   trunk/libs/chrono/test/io/time_point_output.cpp | 2
   10 files changed, 219 insertions(+), 91 deletions(-)

Modified: trunk/boost/chrono/config.hpp
==============================================================================
--- trunk/boost/chrono/config.hpp (original)
+++ trunk/boost/chrono/config.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -91,6 +91,7 @@
 // deprecated i/o
 #define BOOST_CHRONO_IO_V1_DONT_PROVIDE_DEPRECATED
 #define BOOST_CHRONO_IO_USE_XALLOC
+//#define BOOST_CHRONO_IS_LOCALIZABLE
 
 // unicode support ------------------------------//
 

Modified: trunk/boost/chrono/detail/is_evenly_divisible_by.hpp
==============================================================================
--- trunk/boost/chrono/detail/is_evenly_divisible_by.hpp (original)
+++ trunk/boost/chrono/detail/is_evenly_divisible_by.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -18,10 +18,21 @@
 namespace chrono {
 namespace chrono_detail {
 
+#if 1
   template <class R1, class R2>
- struct is_evenly_divisible_by : public boost::mpl::bool_ < ratio_divide<R1, R2>::type::den == 1 >
- {};
-
+ struct is_evenly_divisible_by : public boost::mpl::bool_ < ratio_divide<R1, R2>::type::den == 1 >
+ {};
+#else
+ template <class R1, class R2, bool C1>
+ struct is_evenly_divisible_by2 : public boost::mpl::bool_ < ratio_divide<R1, R2>::type::den == 1 >
+ {};
+ template <class R1, class R2>
+ struct is_evenly_divisible_by2<R1,R2,true> : public boost::mpl::bool_ < false >
+ {};
+ template <class R1, class R2>
+ struct is_evenly_divisible_by : public is_evenly_divisible_by2<R1, R2, (R1::num < R1::den && R2::den < R2::num) || (R1::den < R1::num && R2::num < R2::den)>
+ {};
+#endif
 } // namespace chrono_detail
 } // namespace detail
 } // namespace chrono

Modified: trunk/boost/chrono/io/duration_io.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_io.hpp (original)
+++ trunk/boost/chrono/io/duration_io.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -20,25 +20,16 @@
 #include <boost/mpl/if.hpp>
 #include <boost/math/common_factor_rt.hpp>
 #include <boost/chrono/detail/scan_keyword.hpp>
+#include <boost/chrono/io/duration_style.hpp>
 #include <boost/chrono/io/duration_unit_string.hpp>
+//#include <boost/format.hpp>
 #include <locale>
 
 namespace boost
 {
   namespace chrono
   {
- /**
- * Scoped enumeration emulation stating whether the duration I/O style is long or short.
- * prefix_text means duration::rep with whatever stream/locale settings are set for it followed by a long name representing the unit
- * symbol means duration::rep with whatever stream/locale settings are set for it followed by a SI unit abbreviation
- */
- struct duration_style
- {
- enum type
- {
- prefix, symbol
- };
- };
+
     namespace detail {
 
       enum chrono_fmt_masks
@@ -508,7 +499,33 @@
           const Facet& f = std::use_facet<Facet>(os.getloc());
           return os << d.count() << ' ' << f.template name<Rep,Period>(d);
 #else
- return os << d.count() << ' ' << duration_unit<CharT>(detail::get_duration_style(os)==duration_style::prefix, d);
+#if defined BOOST_CHRONO_IS_LOCALIZABLE
+ duration_style::type style = detail::get_duration_style(os);
+// if (ratio_string_is_localizable<Period>())
+// {
+// std::cout << __FILE__ << ":"<< __LINE__ << ": " << std::endl;
+ return os << to_basic_string<CharT>(detail::get_duration_style(os), d, os.getloc());
+
+// return os << basic_format<CharT>(
+// translated_duration_unit<CharT, Rep, Period>(os.getloc(), style==duration_style::prefix, d),
+// os.getloc()
+// )
+// % d.count();
+// }
+// else
+// {
+ std::cout << __FILE__ << ":"<< __LINE__ << ": " << std::endl;
+ return os << to_basic_string<CharT>(detail::get_duration_style(os), d, os.getloc());
+// return os << basic_format<CharT>(
+// translated_duration_unit<CharT, ratio<1> >(os.getloc(), style==duration_style::prefix),
+// os.getloc()
+// )
+// % d.count()
+// % ratio_string<Period, CharT>::symbol();
+// }
+#else
+ return os << d.count() << ' ' << duration_unit<CharT>(os.getloc(), detail::get_duration_style(os)==duration_style::prefix, d);
+#endif
 #endif
 #else
           std::locale loc = os.getloc();
@@ -520,7 +537,7 @@
 #if !defined BOOST_CHRONO_IO_V1_DONT_PROVIDE_DEPRECATED
           return os << d.count() << ' ' << f.template name<Rep,Period>(d);
 #else
- return os << d.count() << ' ' << duration_unit<CharT>(f.is_prefix(), d);
+ return os << d.count() << ' ' << duration_unit<CharT>(os.getloc(), f.is_prefix(), d);
 #endif
 #endif
         }
@@ -616,8 +633,8 @@
                 f.template long_name<ratio<1> >(),
                 f.template short_name<ratio<1> >()
 #else
- duration_unit<CharT>(true, seconds(2)),
- duration_unit<CharT>(false, seconds(1))
+ duration_unit<CharT>(is.getloc(), true, seconds(2)),
+ duration_unit<CharT>(is.getloc(), false, seconds(1))
 #endif
               };
               std::ios_base::iostate err = std::ios_base::goodbit;
@@ -680,63 +697,63 @@
                 f.template long_name<ratio<3600> >(),
                 f.template short_name<ratio<3600> >()
 #else
- duration_unit<CharT>(true, duration<Rep, atto>(2)),
- duration_unit<CharT>(true, duration<Rep, atto>(1)),
- duration_unit<CharT>(false, duration<Rep, atto>(1)),
- duration_unit<CharT>(true, duration<Rep, femto>(2)),
- duration_unit<CharT>(true, duration<Rep, femto>(1)),
- duration_unit<CharT>(false, duration<Rep, femto>(1)),
- duration_unit<CharT>(true, duration<Rep, pico>(2)),
- duration_unit<CharT>(true, duration<Rep, pico>(1)),
- duration_unit<CharT>(false, duration<Rep, pico>(1)),
- duration_unit<CharT>(true, duration<Rep, nano>(2)),
- duration_unit<CharT>(true, duration<Rep, nano>(1)),
- duration_unit<CharT>(false, duration<Rep, nano>(1)),
- duration_unit<CharT>(true, duration<Rep, micro>(2)),
- duration_unit<CharT>(true, duration<Rep, micro>(1)),
- duration_unit<CharT>(false, duration<Rep, micro>(1)),
- duration_unit<CharT>(true, duration<Rep, milli>(2)),
- duration_unit<CharT>(true, duration<Rep, milli>(1)),
- duration_unit<CharT>(false, duration<Rep, milli>(1)),
- duration_unit<CharT>(true, duration<Rep, centi>(2)),
- duration_unit<CharT>(true, duration<Rep, centi>(1)),
- duration_unit<CharT>(false, duration<Rep, centi>(1)),
- duration_unit<CharT>(true, duration<Rep, deci>(2)),
- duration_unit<CharT>(true, duration<Rep, deci>(1)),
- duration_unit<CharT>(false, duration<Rep, deci>(1)),
- duration_unit<CharT>(true, duration<Rep, deca>(2)),
- duration_unit<CharT>(true, duration<Rep, deca>(1)),
- duration_unit<CharT>(false, duration<Rep, deca>(1)),
- duration_unit<CharT>(true, duration<Rep, hecto>(2)),
- duration_unit<CharT>(true, duration<Rep, hecto>(1)),
- duration_unit<CharT>(false, duration<Rep, hecto>(1)),
- duration_unit<CharT>(true, duration<Rep, kilo>(2)),
- duration_unit<CharT>(true, duration<Rep, kilo>(1)),
- duration_unit<CharT>(false, duration<Rep, kilo>(1)),
- duration_unit<CharT>(true, duration<Rep, mega>(2)),
- duration_unit<CharT>(true, duration<Rep, mega>(1)),
- duration_unit<CharT>(false, duration<Rep, mega>(1)),
- duration_unit<CharT>(true, duration<Rep, giga>(2)),
- duration_unit<CharT>(true, duration<Rep, giga>(1)),
- duration_unit<CharT>(false, duration<Rep, giga>(1)),
- duration_unit<CharT>(true, duration<Rep, giga>(2)),
- duration_unit<CharT>(true, duration<Rep, tera>(1)),
- duration_unit<CharT>(false, duration<Rep, giga>(1)),
- duration_unit<CharT>(true, duration<Rep, peta>(2)),
- duration_unit<CharT>(true, duration<Rep, peta>(1)),
- duration_unit<CharT>(false, duration<Rep, peta>(1)),
- duration_unit<CharT>(true, duration<Rep, exa>(2)),
- duration_unit<CharT>(true, duration<Rep, exa>(1)),
- duration_unit<CharT>(false, duration<Rep, exa>(1)),
- duration_unit<CharT>(true, duration<Rep, ratio<1> >(2)),
- duration_unit<CharT>(true, duration<Rep, ratio<1> >(1)),
- duration_unit<CharT>(false, duration<Rep, ratio<1> >(1)),
- duration_unit<CharT>(true, duration<Rep, ratio<60> >(2)),
- duration_unit<CharT>(true, duration<Rep, ratio<60> >(1)),
- duration_unit<CharT>(false, duration<Rep, ratio<60> >(1)),
- duration_unit<CharT>(true, duration<Rep, ratio<3600> >(2)),
- duration_unit<CharT>(true, duration<Rep, ratio<3600> >(1)),
- duration_unit<CharT>(false, duration<Rep, ratio<3600> >(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, atto>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, atto>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, atto>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, femto>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, femto>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, femto>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, pico>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, pico>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, pico>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, nano>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, nano>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, nano>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, micro>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, micro>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, micro>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, milli>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, milli>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, milli>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, centi>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, centi>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, centi>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, deci>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, deci>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, deci>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, deca>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, deca>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, deca>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, hecto>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, hecto>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, hecto>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, kilo>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, kilo>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, kilo>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, mega>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, mega>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, mega>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, giga>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, giga>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, giga>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, giga>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, tera>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, giga>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, peta>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, peta>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, peta>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, exa>(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, exa>(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, exa>(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, ratio<1> >(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, ratio<1> >(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, ratio<1> >(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, ratio<60> >(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, ratio<60> >(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, ratio<60> >(1)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, ratio<3600> >(2)),
+ duration_unit<CharT>(is.getloc(), true, duration<Rep, ratio<3600> >(1)),
+ duration_unit<CharT>(is.getloc(), false, duration<Rep, ratio<3600> >(1)),
 #endif
                 };
               std::ios_base::iostate err = std::ios_base::goodbit;

Added: trunk/boost/chrono/io/duration_style.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/chrono/io/duration_style.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -0,0 +1,37 @@
+// chrono_io
+//
+// (C) Copyright Howard Hinnant
+// (C) Copyright 2010-2011 Vicente J. Botet Escriba
+// Use, modification and distribution are subject to 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).
+//
+// This code was adapted by Vicente from Howard Hinnant's experimental work
+// on chrono i/o to Boost
+
+#ifndef BOOST_CHRONO_IO_DURATION_STYLE_HPP
+#define BOOST_CHRONO_IO_DURATION_STYLE_HPP
+#include <iostream>
+
+namespace boost
+{
+ namespace chrono
+ {
+ /**
+ * Scoped enumeration emulation stating whether the duration I/O style is long or short.
+ * prefix means duration::rep with whatever stream/locale settings are set for it followed by a long name representing the unit
+ * symbol means duration::rep with whatever stream/locale settings are set for it followed by a SI unit abbreviation
+ */
+ struct duration_style
+ {
+ enum type
+ {
+ prefix, symbol
+ };
+ };
+
+ } // chrono
+
+}
+
+#endif // BOOST_CHRONO_CHRONO_IO_HPP

Modified: trunk/boost/chrono/io/duration_unit_string.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_unit_string.hpp (original)
+++ trunk/boost/chrono/io/duration_unit_string.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -11,14 +11,57 @@
 #include <boost/chrono/config.hpp>
 #include <boost/chrono/duration.hpp>
 #include <boost/ratio/ratio_io.hpp>
+#include <boost/chrono/io/duration_style.hpp>
 #include <boost/chrono/io/translate.hpp>
+#include <boost/chrono/io/unit_strings.hpp>
+
 #include <string>
+#include <locale>
 
 namespace boost
 {
+ template <>
+ struct ratio_string_is_localizable<ratio<60> > : true_type {};
+
+ template <>
+ struct ratio_string_id<ratio<60> > : integral_constant<int,60> {};
+
+ template <>
+ struct ratio_string_is_localizable<ratio<3600> > : true_type {};
+
+ template <>
+ struct ratio_string_id<ratio<3600> > : integral_constant<int,3600> {};
+
   namespace chrono
   {
 
+ template <class CharT>
+ struct value
+ {
+ static std::basic_string<CharT> name()
+ {
+ static const CharT u[] =
+ { '%', '1', '%', ' '};
+ static const std::basic_string<CharT> str(u, u + sizeof(u)
+ / sizeof(u[0]));
+ return str;
+ }
+ };
+ template <class CharT>
+ struct period
+ {
+ static std::basic_string<CharT> name()
+ {
+ static const CharT u[] =
+ { '%', '2', '%'};
+ static const std::basic_string<CharT> str(u, u + sizeof(u)
+ / sizeof(u[0]));
+ return str;
+ }
+ };
+
+
+
     template <class Period, class CharT>
     struct duration_unit_strings
     {
@@ -28,7 +71,7 @@
         { 's', 'e', 'c', 'o', 'n', 'd', 's' };
         static const std::basic_string<CharT> suffix(u, u + sizeof(u)
             / sizeof(u[0]));
- return ::boost::ratio_string<Period, CharT>::long_name()+suffix;
+ return ::boost::ratio_string<Period, CharT>::prefix()+suffix;
       }
       static std::basic_string<CharT> singular()
       {
@@ -36,12 +79,12 @@
         { 's', 'e', 'c', 'o', 'n', 'd' };
         static const std::basic_string<CharT> suffix(u, u + sizeof(u)
             / sizeof(u[0]));
- return ::boost::ratio_string<Period, CharT>::long_name()+suffix;
+ return ::boost::ratio_string<Period, CharT>::prefix()+suffix;
       }
       static std::basic_string<CharT> symbol()
       {
         static const std::basic_string<CharT> str(1, 's');
- return ::boost::ratio_string<Period, CharT>::short_name()+str;
+ return ::boost::ratio_string<Period, CharT>::symbol()+str;
       }
     };
 
@@ -92,7 +135,10 @@
       }
       static std::basic_string<CharT> symbol()
       {
- static const std::basic_string<CharT> str(1, 'm');
+ static const CharT u[] =
+ { 'm', 'i', 'n' };
+ static const std::basic_string<CharT> str(u, u + sizeof(u)
+ / sizeof(u[0]));
         return str;
       }
     };
@@ -125,22 +171,60 @@
 
 
     template <class CharT, class Rep, class Period>
- std::basic_string<CharT> duration_unit(bool is_prefix, duration<Rep,Period> const& d) {
+ std::basic_string<CharT> duration_unit(std::locale const &loc, bool is_prefix, duration<Rep,Period> const& d) {
       if (is_prefix) {
- return duration_prefix_translate(
- duration_unit_strings<Period, CharT>::singular(),
- duration_unit_strings<Period, CharT>::plural(),
- d.count()
+ return translate(loc,
+ ratio_string_id<Period>(),
+ duration_unit_strings<Period, CharT>::singular(),
+ duration_unit_strings<Period, CharT>::plural(),
+ d.count()
         );
       }
       else
       {
- return duration_symbol_translate(
+ return translate(loc,
+ ratio_string_id<Period>(),
             duration_unit_strings<Period, CharT>::symbol()
         );
       }
     }
 
+ template <class CharT, class Rep, class Period>
+ std::basic_string<CharT> translated_duration_unit(std::locale const &loc, bool is_prefix, duration<Rep,Period> const& d) {
+ if (is_prefix) {
+ return translate(loc,
+ ratio_string_id<Period>(),
+ value<CharT>::name()+duration_unit_strings<Period, CharT>::singular(),
+ value<CharT>::name()+duration_unit_strings<Period, CharT>::plural(),
+ d.count()
+ );
+ }
+ else
+ {
+ return translate(loc,
+ ratio_string_id<Period>(),
+ value<CharT>::name()+duration_unit_strings<Period, CharT>::symbol()
+ );
+ }
+ }
+
+ template <class CharT, class Period>
+ std::basic_string<CharT> translated_duration_unit(std::locale const &loc, bool is_prefix) {
+ if (is_prefix) {
+ return translate(loc,
+ ratio_string_id<Period>(),
+ value<CharT>::name()+period<CharT>::name()+duration_unit_strings<Period, CharT>::plural()
+ );
+ }
+ else
+ {
+ return translate(loc,
+ ratio_string_id<Period>(),
+ value<CharT>::name()+period<CharT>::name()+duration_unit_strings<Period, CharT>::symbol()
+ );
+ }
+ }
+
 
   } // chrono
 

Modified: trunk/boost/chrono/io/time_point_io.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_io.hpp (original)
+++ trunk/boost/chrono/io/time_point_io.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -20,6 +20,7 @@
 #include <boost/chrono/io/translate.hpp>
 #include <boost/chrono/clock_string.hpp>
 #include <cstring>
+#include <string.h>
 
 namespace boost
 {

Modified: trunk/boost/chrono/io/translate.hpp
==============================================================================
--- trunk/boost/chrono/io/translate.hpp (original)
+++ trunk/boost/chrono/io/translate.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -37,6 +37,19 @@
     {
       return epoch;
     }
+ template <class CharT>
+ std::basic_string<CharT> translate(std::locale const &, int , std::basic_string<CharT> const &dfault)
+ {
+ return dfault;
+ }
+
+ template <class CharT>
+ std::basic_string<CharT> translate(std::locale const &, int , std::basic_string<CharT> const &singular, std::basic_string<CharT> const &plural, int v)
+ {
+ if ( v == 1 ) return singular;
+ if ( v == -1 ) return singular;
+ return plural;
+ }
 
 #endif
 

Added: trunk/boost/chrono/io/unit_strings.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/chrono/io/unit_strings.hpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -0,0 +1,616 @@
+//
+// (C) Copyright 2011 Vicente J. Botet Escriba
+// Use, modification and distribution are subject to 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_CHRONO_IO_UNIT_STRINGS_HPP
+#define BOOST_CHRONO_IO_UNIT_STRINGS_HPP
+
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/duration.hpp>
+#include <boost/chrono/io/duration_style.hpp>
+#include <string>
+#include <iostream>
+//#include <locale>
+#include <boost/utility/enable_if.hpp>
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ class rt_duration {
+ public:
+ template <typename Rep, typename Period>
+ rt_duration(duration<Rep, Period> const& d)
+ : num(Period::type::num)
+ , den(Period::type::den)
+ , count(d.count())
+ {}
+
+
+ intmax_t num;
+ intmax_t den;
+ int_least64_t count;
+ };
+
+ template <typename CharT>
+ class chrono_units: public std::locale::facet
+ {
+ public:
+ static std::locale::id id;
+
+ explicit chrono_units(size_t refs = 0) :
+ std::locale::facet(refs)
+ {}
+
+ // used for input and ouput
+ virtual bool swaps_value_unit_order() const = 0;
+
+ // used for ouput
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, atto> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, pico> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, nanoseconds value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, microseconds value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, milliseconds value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, centi> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, deci> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, seconds value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, deca> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, hecto> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, kilo> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, mega> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, tera> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, peta> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, duration<boost::int_least64_t, exa> value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, rt_duration value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, minutes value) const = 0;
+ virtual std::basic_string<CharT>
+ to_string(duration_style::type style, hours value) const = 0;
+
+ // used for input
+ virtual std::size_t plural_forms() const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, atto>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, pico>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, nanoseconds, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, microseconds, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, milliseconds, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, centi>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, deci>, std::size_t pf) const = 0;
+ virtual std::basic_string<CharT> plural_form(duration_style::type style, seconds, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, deca>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, hecto>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, kilo>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, mega>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, giga>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, tera>, std::size_t pf) const = 0;
+// virtual std::basic_string<CharT> plural_form(duration_style::type style, duration<boost::int_least64_t, exa>, std::size_t pf) const = 0;
+ virtual std::basic_string<CharT> plural_form(duration_style::type style, minutes, std::size_t pf) const = 0;
+ virtual std::basic_string<CharT> plural_form(duration_style::type style, hours, std::size_t pf) const = 0;
+
+ virtual std::size_t plural_form(int_least64_t value) const = 0;
+
+ };
+
+
+ template<class CharT>
+ std::locale::id chrono_units<CharT>::id;
+
+ ///////////////////////////
+ // This class is used to define the strings for the default English
+ template <typename CharT>
+ class chrono_units_default : public chrono_units<CharT>
+ {
+ public:
+
+ explicit chrono_units_default(size_t refs = 0) :
+ chrono_units<CharT>(refs)
+ {}
+
+ bool swaps_value_unit_order() const
+ { return false; }
+
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, atto> value) const
+ {
+ return to_string(style, atto())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, pico> value) const
+ {
+ return to_string(style, pico())+to_string(style, seconds(value.count()));
+ }
+
+ std::basic_string<CharT> to_string(duration_style::type style, nanoseconds value) const
+ {
+ return to_string(style, nano())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, microseconds value) const
+ {
+ return to_string(style, micro())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, milliseconds value) const
+ {
+ return to_string(style, milli())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, centi> value) const
+ {
+ return to_string(style, centi())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, deci> value) const
+ {
+ return to_string(style, deci())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, seconds value) const
+ {
+ return plural_form(style, value, plural_form(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, deca> value) const
+ {
+ return to_string(style, deca())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, hecto> value) const
+ {
+ return to_string(style, hecto())+to_string(style, seconds(value.count()));
+ }
+
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, kilo> value) const
+ {
+ return to_string(style, kilo())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, mega> value) const
+ {
+ return to_string(style, mega())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, giga> value) const
+ {
+ return to_string(style, giga())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, tera> value) const
+ {
+ return to_string(style, tera())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, peta> value) const
+ {
+ return to_string(style, peta())+to_string(style, seconds(value.count()));
+ }
+ std::basic_string<CharT> to_string(duration_style::type style, duration<boost::int_least64_t, exa> value) const
+ {
+ return to_string(style, exa())+to_string(style, seconds(value.count()));
+ }
+
+ std::basic_string<CharT> to_string(duration_style::type style, minutes value) const
+ {
+ return plural_form(style, value, plural_form(value.count()));
+ }
+
+ std::basic_string<CharT> to_string(duration_style::type style, hours value) const
+ {
+ return plural_form(style, value, plural_form(value.count()));
+ }
+
+ std::basic_string<CharT> to_string(duration_style::type style, rt_duration value) const
+ {
+ std::basic_ostringstream<CharT> os;
+ os << CharT('[') << value.num << CharT('/')
+ << value.den << CharT(']');
+ return os.str()+to_string(style, seconds(value.count));
+ }
+ std::size_t plural_forms() const
+ {
+ return 2;
+ }
+
+ std::size_t plural_form(int_least64_t value) const
+ {
+ return (value==-1 || value==1) ? 0 : 1;
+ }
+
+ std::basic_string<CharT> plural_form(duration_style::type style, seconds, std::size_t pf) const
+ {
+ static const CharT t[] =
+ { 's' };
+ static const std::basic_string<CharT> symbol(t, t + sizeof(t)
+ / sizeof(t[0]));
+ static const CharT u[] =
+ { 's', 'e', 'c', 'o', 'n', 'd' };
+ static const std::basic_string<CharT> singular(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 's', 'e', 'c', 'o', 'n', 'd', 's' };
+ static const std::basic_string<CharT> plural(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ if (pf ==0) return singular;
+ if (pf ==1) return plural;
+ // assert
+ throw "exception";
+ }
+
+ std::basic_string<CharT> plural_form(duration_style::type style, minutes, std::size_t pf) const
+ {
+ static const CharT t[] =
+ { 'm', 'i', 'n' };
+ static const std::basic_string<CharT> symbol(t, t + sizeof(t)
+ / sizeof(t[0]));
+
+ static const CharT u[] =
+ { 'm', 'i', 'n', 'u', 't', 'e' };
+ static const std::basic_string<CharT> singular(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'm', 'i', 'n', 'u', 't', 'e', 's' };
+ static const std::basic_string<CharT> plural(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ if (pf ==0) return singular;
+ if (pf ==1) return plural;
+ // assert
+ throw "exception";
+ }
+
+ std::basic_string<CharT> plural_form(duration_style::type style, hours, std::size_t pf) const
+ {
+ static const CharT t[] =
+ { 'h' };
+ static const std::basic_string<CharT> symbol(t, t + sizeof(t)
+ / sizeof(t[0])); static const CharT u[] =
+ { 'h', 'o', 'u', 'r' };
+ static const std::basic_string<CharT> singular(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'h', 'o', 'u', 'r', 's' };
+ static const std::basic_string<CharT> plural(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ if (pf ==0) return singular;
+ if (pf ==1) return plural;
+ // assert
+ throw "exception";
+ }
+
+
+ protected:
+
+ virtual std::basic_string<CharT> to_string(duration_style::type style, atto) const
+ {
+ static const CharT u[] =
+ { 'a', 't', 't', 'o' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'a' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, pico) const
+ {
+ static const CharT u[] =
+ { 'p', 'i', 'c', 'o' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'p' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, nano) const
+ {
+ static const CharT u[] =
+ { 'n', 'a', 'n', 'o' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'n' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, micro) const
+ {
+ static const CharT u[] =
+ { 'm', 'i', 'c', 'r', 'o' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'u' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+
+ virtual std::basic_string<CharT> to_string(duration_style::type style, milli) const
+ {
+ static const CharT u[] =
+ { 'm', 'i', 'l', 'l', 'i' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'm' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, centi) const
+ {
+ static const CharT u[] =
+ { 'c', 'e', 'n', 't', 'i' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'c' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, deci) const
+ {
+ static const CharT u[] =
+ { 'd', 'e', 'c', 'i' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'd' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, deca) const
+ {
+ static const CharT u[] =
+ { 'd', 'e', 'c', 'a' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'd', 'a' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, hecto) const
+ {
+ static const CharT u[] =
+ { 'h', 'e', 'c', 't', 'o' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'h' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, kilo) const
+ {
+ static const CharT u[] =
+ { 'k', 'i', 'l', 'o' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'k' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, mega) const
+ {
+ static const CharT u[] =
+ { 'm', 'e', 'g', 'a' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'M' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, giga) const
+ {
+ static const CharT u[] =
+ { 'g', 'i', 'g', 'a' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'G' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, tera) const
+ {
+ static const CharT u[] =
+ { 't', 'e', 'r', 'a' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'T' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, peta) const
+ {
+ static const CharT u[] =
+ { 'p', 'e', 't', 'a' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'P' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+ virtual std::basic_string<CharT> to_string(duration_style::type style, exa) const
+ {
+ static const CharT u[] =
+ { 'e', 'x', 'a' };
+ static const std::basic_string<CharT> prefix(u, u + sizeof(u)
+ / sizeof(u[0]));
+ static const CharT v[] =
+ { 'E' };
+ static const std::basic_string<CharT> symbol(v, v + sizeof(v)
+ / sizeof(v[0]));
+
+ if (style==duration_style::symbol) return symbol;
+ return prefix;
+ }
+
+ };
+
+ template <typename Period>
+ struct is_localizable : false_type {};
+
+ template <>
+ struct is_localizable<atto> : true_type {};
+ template <>
+ struct is_localizable<femto> : true_type {};
+ template <>
+ struct is_localizable<pico> : true_type {};
+ template <>
+ struct is_localizable<nano> : true_type {};
+ template <>
+ struct is_localizable<micro> : true_type {};
+ template <>
+ struct is_localizable<milli> : true_type {};
+ template <>
+ struct is_localizable<centi> : true_type {};
+ template <>
+ struct is_localizable<deci> : true_type {};
+ template <>
+ struct is_localizable<ratio<1> > : true_type {};
+ template <>
+ struct is_localizable<deca> : true_type {};
+ template <>
+ struct is_localizable<hecto> : true_type {};
+ template <>
+ struct is_localizable<kilo> : true_type {};
+ template <>
+ struct is_localizable<mega> : true_type {};
+ template <>
+ struct is_localizable<tera> : true_type {};
+ template <>
+ struct is_localizable<peta> : true_type {};
+ template <>
+ struct is_localizable<exa> : true_type {};
+ template <>
+ struct is_localizable<ratio<60> > : true_type {};
+ template <>
+ struct is_localizable<ratio<3600> > : true_type {};
+
+
+ template <typename CharT, typename T>
+ std::basic_string<CharT> to_basic_string(T const&v, std::locale const &loc)
+ {
+ std::basic_ostringstream<CharT> os;
+ os.imbue(loc);
+ os << v;
+ return os.str();
+ }
+
+ template <typename CharT, typename Rep, typename Period>
+ typename enable_if<is_localizable<Period>, std::basic_string<CharT> >::type
+ to_basic_string(
+ duration_style::type style,
+ duration<Rep,Period> value,
+ std::locale const &loc
+ )
+ {
+ std::locale nloc;
+ if (!std::has_facet<chrono_units<CharT> >(loc))
+ nloc =std::locale(loc, new chrono_units_default<CharT>());
+ else
+ nloc=loc;
+ chrono_units<CharT> const & f = std::use_facet<chrono_units<CharT> >(nloc);
+
+ if (f.swaps_value_unit_order()) {
+ std::basic_string<CharT> tmp = f.to_string(style, value);
+ tmp += " " + to_basic_string<CharT>(value.count(), nloc);
+ return f.to_string(style, value) + " " + to_basic_string<CharT>(value.count(), nloc);
+ }
+ else {
+ return to_basic_string<CharT>(value.count(), nloc) + " " + f.to_string(style, value) ;
+ }
+ }
+
+ template <typename CharT, typename Rep, typename Period>
+ typename disable_if<is_localizable<Period> , std::basic_string<CharT> >::type
+ to_basic_string(
+ duration_style::type style,
+ duration<Rep,Period> value,
+ std::locale const& loc
+ )
+ {
+ std::locale nloc;
+ if (!std::has_facet<chrono_units<CharT> >(loc))
+ nloc =std::locale(loc, new chrono_units_default<CharT>());
+ else
+ nloc=loc;
+ chrono_units<CharT> const & f = std::use_facet<chrono_units<CharT> >(nloc);
+ if (f.swaps_value_unit_order())
+ return f.to_string(style, rt_duration(value)) + " " + to_basic_string<CharT>(value.count(), nloc);
+ else
+ return to_basic_string<CharT>(value.count(), nloc) + " " + f.to_string(style, rt_duration(value));
+ }
+
+ template <typename CharT, typename Rep, typename Period>
+ std::basic_string<CharT>
+ to_basic_string(duration_style::type style, duration<Rep,Period> value)
+ {
+ return to_basic_string<CharT>(style, value, std::locale());
+ }
+
+
+ } // chrono
+
+} // boost
+
+#endif // header

Modified: trunk/libs/chrono/test/io/duration_input.cpp
==============================================================================
--- trunk/libs/chrono/test/io/duration_input.cpp (original)
+++ trunk/libs/chrono/test/io/duration_input.cpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -3,6 +3,7 @@
 // See http://www.boost.org/LICENSE_1_0.txt
 
 #include <boost/chrono/chrono_io.hpp>
+#include <boost/chrono/io/unit_strings.hpp>
 #include <sstream>
 #include <boost/detail/lightweight_test.hpp>
 
@@ -52,7 +53,7 @@
   test_good("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
 
   test_good("5000 h", hours(5000));
- test_good("5000 m", minutes(5000));
+ test_good("5000 min", minutes(5000));
   test_good("5000 s", seconds(5000));
   test_good("5000 ms", milliseconds(5000));
   test_good("5000 ns", nanoseconds(5000));

Modified: trunk/libs/chrono/test/io/duration_output.cpp
==============================================================================
--- trunk/libs/chrono/test/io/duration_output.cpp (original)
+++ trunk/libs/chrono/test/io/duration_output.cpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -12,6 +12,7 @@
   std::ostringstream out;
   out << d;
   BOOST_TEST(out.good());
+
   BOOST_TEST(out.str() == str);
 }
 
@@ -47,7 +48,6 @@
   out << " " << d;
   BOOST_TEST(out.good());
   BOOST_TEST(out.str() == str2);
- //std::cout << __FILE__ << ":" << __LINE__ << std::endl;
 }
 
 int main()
@@ -76,7 +76,7 @@
   test_good_prefix("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
 
   test_good_symbol("5000 h", hours(5000));
- test_good_symbol("5000 m", minutes(5000));
+ test_good_symbol("5000 min", minutes(5000));
   test_good_symbol("5000 s", seconds(5000));
   test_good_symbol("5000 ms", milliseconds(5000));
   test_good_symbol("5000 ns", nanoseconds(5000));

Modified: trunk/libs/chrono/test/io/time_point_input.cpp
==============================================================================
--- trunk/libs/chrono/test/io/time_point_input.cpp (original)
+++ trunk/libs/chrono/test/io/time_point_input.cpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -67,7 +67,7 @@
   test_good<Clock>("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000));
 
   test_good<Clock>("5000 h", hours(5000));
- test_good<Clock>("5000 m", minutes(5000));
+ test_good<Clock>("5000 min", minutes(5000));
   test_good<Clock>("5000 s", seconds(5000));
   test_good<Clock>("5000 ms", milliseconds(5000));
   test_good<Clock>("5000 ns", nanoseconds(5000));

Modified: trunk/libs/chrono/test/io/time_point_output.cpp
==============================================================================
--- trunk/libs/chrono/test/io/time_point_output.cpp (original)
+++ trunk/libs/chrono/test/io/time_point_output.cpp 2011-10-29 16:36:47 EDT (Sat, 29 Oct 2011)
@@ -66,7 +66,7 @@
   test_good_prefix<Clock>("2 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (2));
 
   test_good_symbol<Clock>("2 h", hours(2));
- test_good_symbol<Clock>("2 m", minutes(2));
+ test_good_symbol<Clock>("2 min", minutes(2));
   test_good_symbol<Clock>("2 s", seconds(2));
   test_good_symbol<Clock>("2 ms", milliseconds(2));
   test_good_symbol<Clock>("2 ns", nanoseconds(2));


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