$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r59105 - in sandbox/chrono/boost/chrono: . detail
From: vicente.botet_at_[hidden]
Date: 2010-01-17 17:08:25
Author: viboes
Date: 2010-01-17 17:08:24 EST (Sun, 17 Jan 2010)
New Revision: 59105
URL: http://svn.boost.org/trac/boost/changeset/59105
Log:
Boost.Chrono: Version 0.3.1, Allow wide characters
* replace ostream by basic_otream
* replace string by basic_string
Added:
   sandbox/chrono/boost/chrono/detail/
   sandbox/chrono/boost/chrono/detail/default_out.hpp   (contents, props changed)
Text files modified: 
   sandbox/chrono/boost/chrono/digital_time_formatter.hpp          |    43 +++++++++++++++++++++++++++++---------- 
   sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp |    42 +++++++++++++++++++++++++++++---------  
   sandbox/chrono/boost/chrono/stopwatch_formatter.hpp             |    43 +++++++++++++++++++++++++++++---------- 
   sandbox/chrono/boost/chrono/stopwatch_reporter.hpp              |    23 ++++++++++++---------                   
   sandbox/chrono/boost/chrono/time_formatter.hpp                  |    43 +++++++++++++++++++++++++++++---------- 
   5 files changed, 141 insertions(+), 53 deletions(-)
Added: sandbox/chrono/boost/chrono/detail/default_out.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/detail/default_out.hpp	2010-01-17 17:08:24 EST (Sun, 17 Jan 2010)
@@ -0,0 +1,42 @@
+//  boost/chrono/stopwatch_formatter.hpp  ------------------------------------------------------------//
+
+//  Copyright 2009-2010 Vicente J. Botet Escriba
+
+//  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)
+
+//  See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_CHRONO_DETAIL_DEFAULT_OUT__HPP
+#define BOOST_CHRONO_DETAIL_DEFAULT_OUT__HPP
+
+#include <boost/chrono/config.hpp>
+#include <iostream>
+
+namespace boost { namespace chrono  {
+
+
+namespace detail {
+    template <typename CharT,typename Traits>
+    struct default_out;
+    template <typename Traits>
+    struct default_out<char,Traits> {
+        static std::basic_ostream<char,Traits>& apply() {
+            return std::cout;
+        }
+    };
+#ifndef BOOST_NO_STD_WSTRING
+    template <typename Traits>
+    struct default_out<wchar_t,Traits> {
+        static std::basic_ostream<wchar_t,Traits>& apply() {
+            return std::wcout;
+        }
+    };
+#endif    
+}
+    
+  } // namespace chrono
+} // namespace boost
+
+
+#endif
Modified: sandbox/chrono/boost/chrono/digital_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/digital_time_formatter.hpp	(original)
+++ sandbox/chrono/boost/chrono/digital_time_formatter.hpp	2010-01-17 17:08:24 EST (Sun, 17 Jan 2010)
@@ -13,6 +13,7 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/digital_time.hpp>
 #include <boost/current_function.hpp>
+#include <boost/chrono/detail/default_out.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
@@ -30,14 +31,27 @@
 //--------------------------------------------------------------------------------------//
 
 
-    class digital_time_formatter {
+    template <
+        typename CharT=char, 
+        typename Traits=std::char_traits<CharT>, 
+        class Alloc=std::allocator<CharT>
+    >
+    class basic_digital_time_formatter {
     public:
-        static std::ostream &  default_os();
+        //~ typedef std::string string_type;
+        //~ typedef string_type::value_type char_type;
+        //~ typedef std::ostream ostream_type;
+    
+        typedef std::basic_string<CharT,Traits,Alloc> string_type;
+        typedef CharT char_type;
+        typedef std::basic_ostream<CharT,Traits> ostream_type;
+
+        static ostream_type &  default_os();
         static const int m_default_places = 3;
-        static const char* m_default_format;
-        static const char* default_format() { return m_default_format; }
-        static std::string format(const char* s) {
-            std::string res(s);
+        static const char_type* m_default_format;
+        static const char_type* default_format() { return m_default_format; }
+        static string_type format(const char_type* s) {
+            string_type res(s);
             res += " tokes %d day(s) %h:%m:%s.%n\n";
             return res;
         }
@@ -45,7 +59,7 @@
 
         template <class Stopwatch >
         static void show_time( Stopwatch & stopwatch_
-            , const char * format, int places, std::ostream & os
+            , const char_type* format, int places, ostream_type & os
             , system::error_code & ec)
         //  NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
         //  be as low as 10, although will be 15 for many common platforms.
@@ -105,10 +119,17 @@
             }
         }
     };
-    const char * digital_time_formatter::m_default_format ="%d day(s) %h:%m:%s.%n\n";
-
-    std::ostream &  digital_time_formatter::default_os()  { return std::cout; }
-
+    template <typename CharT,typename Traits, class Alloc>
+    const typename basic_digital_time_formatter<CharT,Traits,Alloc>::char_type* 
+    basic_digital_time_formatter<CharT,Traits,Alloc>::m_default_format ="%d day(s) %h:%m:%s.%n\n";
+
+    template <typename CharT,typename Traits, class Alloc>
+    typename basic_digital_time_formatter<CharT,Traits,Alloc>::ostream_type &  
+    basic_digital_time_formatter<CharT,Traits,Alloc>::default_os()  { return detail::default_out<CharT,Traits>::apply(); }
+
+    typedef basic_digital_time_formatter<char> digital_time_formatter;
+    typedef basic_digital_time_formatter<wchar_t> wdigital_time_formatter;
+    
   } // namespace chrono
 } // namespace boost
 
Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp	(original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp	2010-01-17 17:08:24 EST (Sun, 17 Jan 2010)
@@ -13,6 +13,7 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/current_function.hpp>
+#include <boost/chrono/detail/default_out.hpp>
 #include <boost/accumulators/accumulators.hpp>
 #include <boost/accumulators/statistics.hpp>
 #include <boost/accumulators/framework/accumulator_set.hpp>
@@ -36,22 +37,34 @@
 //--------------------------------------------------------------------------------------//
 //--------------------------------------------------------------------------------------//
 
-
-    class stopwatch_accumulator_formatter {
+    template <
+        typename CharT=char, 
+        typename Traits=std::char_traits<CharT>, 
+        class Alloc=std::allocator<CharT>
+    >
+    class basic_stopwatch_accumulator_formatter {
     public:
-        static std::ostream &  default_os();
+        //~ typedef std::string string_type;
+        //~ typedef string_type::value_type char_type;
+        //~ typedef std::ostream ostream_type;
+    
+        typedef std::basic_string<CharT,Traits,Alloc> string_type;
+        typedef CharT char_type;
+        typedef std::basic_ostream<CharT,Traits> ostream_type;
+    
+        static ostream_type &  default_os();
         static const int m_default_places = 3;
-        static const char* m_default_format;
-        static const char* default_format() { return m_default_format; }
-        static std::string format(const char* s) {
-            std::string res(s);
+        static const char_type* m_default_format;
+        static const char_type* default_format() { return m_default_format; }
+        static string_type format(const char_type* s) {
+            string_type res(s);
             res += " called %c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
             return res;
         }
         static int default_places() { return m_default_places; }
 
         template <class Stopwatch >
-        static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & os, system::error_code & ec)
+        static void show_time( Stopwatch & stopwatch_, const char_type* format, int places, ostream_type & os, system::error_code & ec)
         //  NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
         //  be as low as 10, although will be 15 for many common platforms.
         {
@@ -101,9 +114,18 @@
             }
         }
     };
-    const char * stopwatch_accumulator_formatter::m_default_format ="%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
-    std::ostream &  stopwatch_accumulator_formatter::default_os()  { return std::cout; }
 
+    template <typename CharT,typename Traits, class Alloc>
+    const typename basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::char_type* 
+    basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::m_default_format ="%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
+
+    template <typename CharT,typename Traits, class Alloc>
+    typename basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::ostream_type &  
+    basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::default_os()  { return detail::default_out<CharT,Traits>::apply(); }
+
+    typedef basic_stopwatch_accumulator_formatter<char> stopwatch_accumulator_formatter;
+    typedef basic_stopwatch_accumulator_formatter<wchar_t> wstopwatch_accumulator_formatter;
+    
 } // namespace chrono
 } // namespace boost
 
Modified: sandbox/chrono/boost/chrono/stopwatch_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_formatter.hpp	(original)
+++ sandbox/chrono/boost/chrono/stopwatch_formatter.hpp	2010-01-17 17:08:24 EST (Sun, 17 Jan 2010)
@@ -13,6 +13,7 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/current_function.hpp>
+#include <boost/chrono/detail/default_out.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
 #include <iostream>
@@ -28,21 +29,34 @@
 //--------------------------------------------------------------------------------------//
 
 
-    class stopwatch_formatter {
+    template <
+        typename CharT=char, 
+        typename Traits=std::char_traits<CharT>, 
+        class Alloc=std::allocator<CharT>
+    >
+    class basic_stopwatch_formatter {
     public:
-        static std::ostream &  default_os();
+        //~ typedef std::string string_type;
+        //~ typedef string_type::value_type char_type;
+        //~ typedef std::ostream ostream_type;
+    
+        typedef std::basic_string<CharT,Traits,Alloc> string_type;
+        typedef CharT char_type;
+        typedef std::basic_ostream<CharT,Traits> ostream_type;
+        
+        static ostream_type &  default_os();
         static const int m_default_places = 3;
-        static const char * m_default_format;
-        static const char* default_format() { return m_default_format; }
-        static std::string format(const char* s) {
-            std::string res(s);
+        static const char_type* m_default_format;
+        static const char_type* default_format() { return m_default_format; }
+        static string_type format(const char_type* s) {
+            string_type res(s);
             res += " tokes %ds\n";
             return res;
         }
         static int default_places() { return m_default_places; }
 
         template <class Stopwatch >
-        static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & os, system::error_code & ec)
+        static void show_time( Stopwatch & stopwatch_, const char_type* format, int places, ostream_type & os, system::error_code & ec)
         //  NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
         //  be as low as 10, although will be 15 for many common platforms.
         {
@@ -76,10 +90,17 @@
             }
         }
     };
-    const char * stopwatch_formatter::m_default_format ="%ds\n";
-
-    std::ostream &  stopwatch_formatter::default_os()  { return std::cout; }
-
+    template <typename CharT,typename Traits, class Alloc>
+    const typename basic_stopwatch_formatter<CharT,Traits,Alloc>::char_type* 
+    basic_stopwatch_formatter<CharT,Traits,Alloc>::m_default_format ="%ds\n";
+
+    template <typename CharT,typename Traits, class Alloc>
+    typename basic_stopwatch_formatter<CharT,Traits,Alloc>::ostream_type &  
+    basic_stopwatch_formatter<CharT,Traits,Alloc>::default_os()  { return detail::default_out<CharT,Traits>::apply(); }
+
+    typedef basic_stopwatch_formatter<char> stopwatch_formatter;
+    typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
+    
   } // namespace chrono
 } // namespace boost
 
Modified: sandbox/chrono/boost/chrono/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_reporter.hpp	(original)
+++ sandbox/chrono/boost/chrono/stopwatch_reporter.hpp	2010-01-17 17:08:24 EST (Sun, 17 Jan 2010)
@@ -85,14 +85,17 @@
         typedef typename Stopwatch::clock clock;
         typedef Stopwatch stopwatch;
         typedef Formatter formatter;
+        typedef typename Formatter::string_type string_type;
+        typedef typename Formatter::char_type char_type;
+        typedef typename Formatter::ostream_type ostream_type;
     
         explicit stopwatch_reporter( system::error_code & ec = system::throws )
         : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) { }
-        explicit stopwatch_reporter( std::ostream & os,
+        explicit stopwatch_reporter( ostream_type & os,
                     system::error_code & ec = system::throws )
         : m_places(Formatter::default_places()), m_os(os), m_format(Formatter::default_format()), m_reported(false) { }
 
-        explicit stopwatch_reporter( const std::string & format,
+        explicit stopwatch_reporter( const string_type & format,
                     system::error_code & ec = system::throws )
         : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(format), m_reported(false) {}
 
@@ -100,27 +103,27 @@
                     system::error_code & ec = system::throws )
         : m_places(places), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) { }
 
-        stopwatch_reporter( std::ostream & os, const std::string & format,
+        stopwatch_reporter( ostream_type & os, const string_type & format,
                     system::error_code & ec = system::throws )
         : m_places(Formatter::default_places()), m_os(os), m_format(format), m_reported(false) { }
 
-        stopwatch_reporter( const std::string & format, int places,
+        stopwatch_reporter( const string_type & format, int places,
                     system::error_code & ec = system::throws )
         : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) { }
 
-        stopwatch_reporter( std::ostream & os, int places,
+        stopwatch_reporter( ostream_type & os, int places,
                     system::error_code & ec = system::throws )
         : m_places(places), m_os(os), m_format(Formatter::default_format()), m_reported(false) { }
 
-        stopwatch_reporter( int places, const std::string & format,
+        stopwatch_reporter( int places, const string_type & format,
                     system::error_code & ec = system::throws )
         : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) { }
 
-        stopwatch_reporter( std::ostream & os, const std::string & format, int places,
+        stopwatch_reporter( ostream_type & os, const string_type & format, int places,
                     system::error_code & ec = system::throws )
         : m_places(places), m_os(os), m_format(format), m_reported(false) { }
 
-        stopwatch_reporter( std::ostream & os, int places, const std::string & format,
+        stopwatch_reporter( ostream_type & os, int places, const string_type & format,
                     system::error_code & ec = system::throws )
         : m_places(places), m_os(os), m_format(format), m_reported(false) { }
 
@@ -143,8 +146,8 @@
 
     protected:
         int             m_places;
-        std::ostream &  m_os;
-        std::string     m_format;
+        ostream_type &  m_os;
+        string_type     m_format;
         bool            m_reported;
 
 
Modified: sandbox/chrono/boost/chrono/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/time_formatter.hpp	(original)
+++ sandbox/chrono/boost/chrono/time_formatter.hpp	2010-01-17 17:08:24 EST (Sun, 17 Jan 2010)
@@ -13,6 +13,7 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/current_function.hpp>
+#include <boost/chrono/detail/default_out.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
@@ -31,14 +32,27 @@
 //--------------------------------------------------------------------------------------//
 
 
-    class time_formatter {
+    template <
+        typename CharT=char, 
+        typename Traits=std::char_traits<CharT>, 
+        class Alloc=std::allocator<CharT>
+    >
+    class basic_time_formatter {
     public:
-        static std::ostream &  default_os();
+        //~ typedef std::string string_type;
+        //~ typedef string_type::value_type char_type;
+        //~ typedef std::ostream ostream_type;
+    
+        typedef std::basic_string<CharT,Traits,Alloc> string_type;
+        typedef CharT char_type;
+        typedef std::basic_ostream<CharT,Traits> ostream_type;
+
+        static ostream_type &  default_os();
         static const int m_default_places = 3;
-        static const char* m_default_format;
-        static const char* default_format() { return m_default_format; }
-        static std::string format(const char* s) {
-            std::string res(s);
+        static const char_type* m_default_format;
+        static const char_type* default_format() { return m_default_format; }
+        static string_type format(const char_type* s) {
+            string_type res(s);
             res += " spent real %rs, cpu %cs (%p%), user %us, system %ss\n";
             return res;
         }
@@ -46,7 +60,7 @@
 
         template <class Stopwatch >
         static void show_time( Stopwatch & stopwatch_
-            , const char * format, int places, std::ostream & os
+            , const char_type* format, int places, ostream_type & os
             , system::error_code & ec)
           //  NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
           //  be as low as 10, although will be 15 for many common platforms.
@@ -108,10 +122,17 @@
           }
 
     };
-    const char * time_formatter::m_default_format = "real %rs, cpu %cs (%p%), user %us, system %ss\n";
-
-    std::ostream &  time_formatter::default_os()  { return std::cout; }
-
+    template <typename CharT,typename Traits, class Alloc>
+    const typename basic_time_formatter<CharT,Traits,Alloc>::char_type* 
+    basic_time_formatter<CharT,Traits,Alloc>::m_default_format = "real %rs, cpu %cs (%p%), user %us, system %ss\n";
+
+    template <typename CharT,typename Traits, class Alloc>
+    typename basic_time_formatter<CharT,Traits,Alloc>::ostream_type &  
+    basic_time_formatter<CharT,Traits,Alloc>::default_os()  { return detail::default_out<CharT,Traits>::apply(); }
+
+    typedef basic_time_formatter<char> time_formatter;
+    typedef basic_time_formatter<wchar_t> wtime_formatter;
+    
     template <>
     struct stopwatch_reporter_default_formatter<stopwatch<process_cpu_clock> > {
         typedef time_formatter type;