$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r75241 - in trunk: boost/chrono/io libs/chrono/example
From: vicente.botet_at_[hidden]
Date: 2011-11-01 18:40:13
Author: viboes
Date: 2011-11-01 18:40:12 EDT (Tue, 01 Nov 2011)
New Revision: 75241
URL: http://svn.boost.org/trac/boost/changeset/75241
Log:
Chrono: Update french example to use the new facet.
Text files modified: 
   trunk/boost/chrono/io/duration_units.hpp |     6 +-                                      
   trunk/libs/chrono/example/french.cpp     |    88 +++++++++++++++++++++++++++++++++++++++ 
   2 files changed, 89 insertions(+), 5 deletions(-)
Modified: trunk/boost/chrono/io/duration_units.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_units.hpp	(original)
+++ trunk/boost/chrono/io/duration_units.hpp	2011-11-01 18:40:12 EDT (Tue, 01 Nov 2011)
@@ -133,7 +133,7 @@
      * as the number of plural forms, the plural form associated to a duration,
      * the text associated to a plural form and a duration's period,
      */
-    template <typename CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
+    template <typename CharT=char, class OutputIterator = std::ostreambuf_iterator<CharT> >
     class duration_units: public std::locale::facet
     {
     public:
@@ -317,7 +317,7 @@
 
     ///////////////////////////
     // This class is used to define the strings for the default English
-    template <typename CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
+    template <typename CharT=char, class OutputIterator = std::ostreambuf_iterator<CharT> >
     class duration_units_default: public duration_units<CharT, OutputIterator>
     {
     public:
@@ -325,7 +325,7 @@
       typedef OutputIterator iter_type;
 
       explicit duration_units_default(size_t refs = 0) :
-        duration_units<CharT> (refs)
+        duration_units<CharT, OutputIterator> (refs)
       {
       }
       bool swaps_value_unit_order() const
Modified: trunk/libs/chrono/example/french.cpp
==============================================================================
--- trunk/libs/chrono/example/french.cpp	(original)
+++ trunk/libs/chrono/example/french.cpp	2011-11-01 18:40:12 EDT (Tue, 01 Nov 2011)
@@ -9,17 +9,96 @@
 
 
 #include <boost/chrono/config.hpp>
-#if defined BOOST_CHRONO_IO_V1_DONT_PROVIDE_DEPRECATED
+
+#if ! defined BOOST_CHRONO_USES_DURATION_PUT
 #undef BOOST_CHRONO_IO_V1_DONT_PROVIDE_DEPRECATED
 #undef BOOST_CHRONO_IO_USE_XALLOC
-
 #endif
+
 #include <boost/chrono/chrono_io.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/chrono/thread_clock.hpp>
 #include <iostream>
 #include <locale>
 
+#if defined BOOST_CHRONO_USES_DURATION_PUT
+#include <boost/chrono/io/duration_units.hpp>
+
+    using namespace boost;
+    using namespace boost::chrono;
+
+    template <typename CharT=char, class OutputIterator = std::ostreambuf_iterator<CharT> >
+    class duration_units_fr: public duration_units_default<CharT, OutputIterator>
+    {
+    public:
+      typedef CharT char_type;
+      typedef OutputIterator iter_type;
+
+      explicit duration_units_fr(size_t refs = 0) :
+        duration_units_default<CharT, OutputIterator>(refs)
+      {
+      }
+    protected:
+      std::basic_string<CharT> do_get_plural_form(duration_style_type style, ratio<1> , 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', 'e' };
+        static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
+        static const CharT v[] =
+        { 's', 'e', 'c', 'o', 'n', 'd', '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> do_get_plural_form(duration_style_type style, ratio<60> , 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> do_get_plural_form(duration_style_type style, ratio<3600> , 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', 'e', 'u', 'r', 'e' };
+        static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
+        static const CharT v[] =
+        { 'h', 'e', 'u', 'r', '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";
+      }
+    };
+#endif
+
 int main()
 {
     using std::cout;
@@ -27,12 +106,17 @@
     using namespace boost;
     using namespace boost::chrono;
 
+#if defined BOOST_CHRONO_USES_DURATION_PUT
+    cout.imbue(locale(locale(), new duration_units_fr<>()));
+#else
+
     cout.imbue(locale(locale(), new duration_punct<char>
         (
             duration_style::prefix,
             "secondes", "minutes", "heures",
             "s", "m", "h"
         )));
+#endif
     hours h(5);
     minutes m(45);
     seconds s(15);