Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74371 - sandbox/stopwatches/boost/chrono/stopwatches/formatters
From: vicente.botet_at_[hidden]
Date: 2011-09-14 01:57:22


Author: viboes
Date: 2011-09-14 01:57:19 EDT (Wed, 14 Sep 2011)
New Revision: 74371
URL: http://svn.boost.org/trac/boost/changeset/74371

Log:
Stopwatches: Adding a parameterized duration_fmt manimulator
Text files modified:
   sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp | 30 ++++++++----------------------
   1 files changed, 8 insertions(+), 22 deletions(-)

Modified: sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp
==============================================================================
--- sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp (original)
+++ sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp 2011-09-14 01:57:19 EDT (Wed, 14 Sep 2011)
@@ -11,6 +11,7 @@
 #include <boost/system/error_code.hpp>
 #include <boost/current_function.hpp>
 #include <boost/chrono/stopwatches/detail/adaptive_string.hpp>
+#include <boost/chrono/stopwatches/formatters/duration_style.hpp>
 #include <boost/chrono/chrono_io.hpp>
 #include <boost/format.hpp>
 #include <boost/format/group.hpp>
@@ -27,8 +28,6 @@
   namespace chrono
   {
 
- enum duration_style {text, symbol};
-
     template<typename Ratio=micro, typename CharT = char, typename Traits = std::char_traits<CharT>,
         class Alloc = std::allocator<CharT> >
     class basic_elapsed_formatter
@@ -43,22 +42,22 @@
       basic_elapsed_formatter() :
         internal_fmt_(BOOST_CHRONO_STOPWATCHES_ELAPSED_FORMAT_DEFAULT),
             fmt_(internal_fmt_), precision_(3), os_(std::cout),
- style_(basic_elapsed_formatter::symbol_manip)
+ style_(symbol)
       {
       }
       basic_elapsed_formatter(const char* fmt, ostream_type& os=std::cout) :
         internal_fmt_(fmt), fmt_(internal_fmt_), precision_(3), os_(os),
- style_(basic_elapsed_formatter::symbol_manip)
+ style_(symbol)
       {
       }
       basic_elapsed_formatter(string_type const& fmt) :
         internal_fmt_(fmt), fmt_(internal_fmt_), precision_(3), os_(std::cout),
- style_(basic_elapsed_formatter::symbol_manip)
+ style_(symbol)
       {
       }
       basic_elapsed_formatter(format_type & fmt) :
         fmt_(fmt), precision_(3), os_(std::cout),
- style_(basic_elapsed_formatter::symbol_manip)
+ style_(symbol)
       {
       }
 
@@ -74,8 +73,7 @@
       }
       void set_duration_style(duration_style style)
       {
- if (style==symbol) style_=symbol_manip;
- else if (style==text) style_=text_manip;
+ style_==style;
       }
       static string_type format(const char* s)
       {
@@ -96,7 +94,7 @@
 
         os_
             << fmt_
- % io::group(std::fixed, std::setprecision(precision_), style_, boost::chrono::duration<
+ % io::group(std::fixed, std::setprecision(precision_), duration_fmt(style_), boost::chrono::duration<
                     double, Ratio>(d)) << std::endl;
 
       }
@@ -105,23 +103,11 @@
       boost::format& fmt_;
       std::size_t precision_;
       ostream_type & os_;
- ostream_type& (*style_)(ostream_type& os);
+ duration_style style_;
 
- static ostream_type&
- symbol_manip(ostream_type& os)
- {
- return boost::chrono::duration_short(os);
- }
- static ostream_type&
- text_manip(ostream_type& os)
- {
- return boost::chrono::duration_long(os);
- }
 
     };
 
-
-
     typedef basic_elapsed_formatter<micro, char> elapsed_formatter;
     typedef basic_elapsed_formatter<micro, wchar_t> welapsed_formatter;
 


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