Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74638 - in trunk/boost/chrono/stopwatches: . formatters reporters
From: vicente.botet_at_[hidden]
Date: 2011-10-02 04:19:03


Author: viboes
Date: 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
New Revision: 74638
URL: http://svn.boost.org/trac/boost/changeset/74638

Log:
Make the default formatter to be elapsed_formatter while been possible to specialize it for Stopwatches and Clocks. Added accumulator_set_formatter.hpp and the corresponding specializations for default formatter
Added:
   trunk/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp (contents, props changed)
   trunk/boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp (contents, props changed)
   trunk/boost/chrono/stopwatches/reporters/clock_default_formatter.hpp (contents, props changed)
Text files modified:
   trunk/boost/chrono/stopwatches/basic_stopwatch.hpp | 4 +-
   trunk/boost/chrono/stopwatches/reporters/process_default_formatter.hpp | 43 ++-------------------------------------
   trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp | 12 +++++++++-
   trunk/boost/chrono/stopwatches/reporters/system_default_formatter.hpp | 35 -------------------------------
   trunk/boost/chrono/stopwatches/reporters/thread_default_formatter.hpp | 21 ------------------
   5 files changed, 17 insertions(+), 98 deletions(-)

Modified: trunk/boost/chrono/stopwatches/basic_stopwatch.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/basic_stopwatch.hpp (original)
+++ trunk/boost/chrono/stopwatches/basic_stopwatch.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -11,8 +11,8 @@
 
 #include <boost/chrono/config.hpp>
 #include <boost/chrono/stopwatches/stopwatch_scoped.hpp>
-#include <boost/chrono/stopwatches/collectors/no_memory.hpp>
-#include <boost/chrono/system_clocks.hpp>
+#include <boost/chrono/stopwatches/collectors/no_memory.hpp> // default laps_collector
+#include <boost/chrono/system_clocks.hpp> // default_clock
 #include <boost/system/error_code.hpp>
 
 namespace boost

Added: trunk/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -0,0 +1,115 @@
+// boost/chrono/stopwatches/stopwatch_formatter.hpp ------------------------------------------------------------//
+// Copyright 2011 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org/libs/chrono/stopwatches for documentation.
+
+#ifndef BOOST_CHRONO_STOPWATCHES_FORMATTERS_ACCUMULATOR_SET_HPP
+#define BOOST_CHRONO_STOPWATCHES_FORMATTERS_ACCUMULATOR_SET_HPP
+
+#include <boost/chrono/stopwatches/formatters/base_formatter.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
+//#include <boost/chrono/stopwatches/detail/adaptive_string.hpp>
+#include <boost/format.hpp>
+#include <boost/format/group.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/assert.hpp>
+#include <string>
+#include <iostream>
+#include <cassert>
+#include <iomanip>
+
+#define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT "count=%1%, sum=%2%, min=%3%, max=%4%, mean=%5%\n"
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ template<typename Ratio = milli, typename CharT = char,
+ typename Traits = std::char_traits<CharT>,
+ class Alloc = std::allocator<CharT> >
+ class basic_accumulator_set_formatter: public base_formatter<CharT, Traits>, public basic_format<CharT, Traits>
+ {
+
+ public:
+ typedef base_formatter<CharT, Traits> base_type;
+ typedef basic_format<CharT, Traits> format_type;
+ typedef std::basic_string<CharT, Traits, Alloc> string_type;
+ typedef CharT char_type;
+ typedef std::basic_ostream<CharT, Traits> ostream_type;
+
+ basic_accumulator_set_formatter() :
+ base_type(),
+ format_type(BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT)
+ {
+ }
+ basic_accumulator_set_formatter(ostream_type& os) :
+ base_type(os),
+ format_type(BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT)
+ {
+ }
+ basic_accumulator_set_formatter(const char* fmt, ostream_type& os = std::cout) :
+ base_type(os), format_type(fmt)
+ {
+ }
+ basic_accumulator_set_formatter(string_type const& fmt, ostream_type& os =
+ std::cout) :
+ base_type(os), format_type(fmt)
+ {
+ }
+
+// static string_type format(const char* s)
+// {
+// string_type res(s);
+// res += boost::chrono::detail::adaptive_string(" : ");
+// res += BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT;
+// return res;
+// }
+
+ template<class Stopwatch>
+ void operator()(Stopwatch & stopwatch_, system::error_code & ec= BOOST_CHRONO_THROWS)
+ {
+
+
+ typedef typename Stopwatch::laps_collector laps_collector;
+ laps_collector const& acc = this->get_laps_collector();
+ typedef typename Stopwatch::duration duration_t;
+
+ this->os_ << static_cast<format_type&>(*this)
+ % boost::accumulators::count(acc)
+ % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), boost::chrono::duration<
+ double, Ratio>(duration_t(boost::accumulators::sum(acc))))
+ % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), boost::chrono::duration<
+ double, Ratio>(duration_t((boost::accumulators::min)(acc))))
+ % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), boost::chrono::duration<
+ double, Ratio>(duration_t((boost::accumulators::max)(acc))))
+ % io::group(std::fixed, std::setprecision(this->precision_), duration_fmt(this->duration_style_), ((boost::accumulators::count(acc)
+ > 0) ? boost::chrono::duration<double, Ratio>(duration_t(boost::accumulators::sum(acc)
+ / boost::accumulators::count(acc))) : boost::chrono::duration<
+ double, Ratio>(duration_t(0))))
+ ;
+
+ }
+ };
+
+ typedef basic_accumulator_set_formatter<milli, char> elapsed_formatter;
+ typedef basic_accumulator_set_formatter<milli, wchar_t> welapsed_formatter;
+
+ } // namespace chrono
+} // namespace boost
+
+#if 0
+#define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT(F) \
+ boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FUNCTION_FORMAT \
+ boost::chrono::elapsed_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FUNCTION_FORMAT \
+ BOOST_CHRONO_STOPWATCHES_ACCUMULATOR_SET_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+#endif
+
+#endif

Added: trunk/boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -0,0 +1,43 @@
+// boost/chrono/stopwatches/stopwatch_reporter.hpp
+// Copyright 2011 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/chrono/stopwatches for documentation.
+
+#ifndef BOOST_CHRONO_STOPWATCHES_REPORTERS_LAPS_ACCUMULATOR_SET_DEFAULT_FORMATTER_HPP
+#define BOOST_CHRONO_STOPWATCHES_REPORTERS_LAPS_ACCUMULATOR_SET_DEFAULT_FORMATTER_HPP
+
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+
+#include <boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp>
+#include <boost/chrono/stopwatches/formatters/elapsed_formatter.hpp>
+#include <boost/chrono/stopwatches/basic_stopwatch.hpp>
+#include <boost/chrono/thread_clock.hpp>
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ template <typename Clock, typename Features, typename Weight>
+ struct stopwatch_reporter_default_formatter<basic_stopwatch<Clock,laps_accumulator_set<typename Clock::duration,Features, Weight> >
+ {
+ typedef accumulator_set_formatter type;
+ };
+
+ template <typename Clock, typename Features, typename Weight>
+ struct wstopwatch_reporter_default_formatter<basic_stopwatch<Clock,laps_accumulator_set<typename Clock::duration,Features, Weight> >
+ {
+ typedef waccumulator_set_formatter type;
+ };
+
+ } // namespace chrono
+} // namespace boost
+
+
+#endif
+
+#endif
+
+

Added: trunk/boost/chrono/stopwatches/reporters/clock_default_formatter.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/chrono/stopwatches/reporters/clock_default_formatter.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -0,0 +1,36 @@
+// boost/chrono/stopwatches/stopwatch_reporter.hpp
+// Copyright 2011 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/chrono/stopwatches for documentation.
+
+#ifndef BOOST_CHRONO_STOPWATCHES_REPORTERS_CLOCK_DEFAULT_FORMATTER_HPP
+#define BOOST_CHRONO_STOPWATCHES_REPORTERS_CLOCK_DEFAULT_FORMATTER_HPP
+
+#include <boost/chrono/stopwatches/formatters/elapsed_formatter.hpp>
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ template<class Clock>
+ struct clock_default_formatter
+ {
+ typedef elapsed_formatter type;
+ };
+
+ template<class Clock>
+ struct wclock_default_formatter
+ {
+ typedef welapsed_formatter type;
+ };
+ } // namespace chrono
+} // namespace boost
+
+
+
+#endif
+
+

Modified: trunk/boost/chrono/stopwatches/reporters/process_default_formatter.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/reporters/process_default_formatter.hpp (original)
+++ trunk/boost/chrono/stopwatches/reporters/process_default_formatter.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -9,9 +9,9 @@
 #define BOOST_CHRONO_STOPWATCHES_REPORTERS_PROCESS_DEFAULT_FORMATTER_HPP
 
 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp>
+#include <boost/chrono/stopwatches/reporters/clock_default_formatter.hpp>
 #include <boost/chrono/stopwatches/formatters/elapsed_formatter.hpp>
 #include <boost/chrono/stopwatches/formatters/times_formatter.hpp>
-#include <boost/chrono/stopwatches/simple_stopwatch.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 
 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
@@ -22,49 +22,13 @@
   {
 
     template<>
- struct stopwatch_reporter_default_formatter<simple_stopwatch<process_real_cpu_clock> >
- {
- typedef elapsed_formatter type;
- };
-
- template<>
- struct wstopwatch_reporter_default_formatter<simple_stopwatch<process_real_cpu_clock> >
- {
- typedef welapsed_formatter type;
- };
-
- template<>
- struct stopwatch_reporter_default_formatter<simple_stopwatch<process_user_cpu_clock> >
- {
- typedef elapsed_formatter type;
- };
-
- template<>
- struct wstopwatch_reporter_default_formatter<simple_stopwatch<process_user_cpu_clock> >
- {
- typedef welapsed_formatter type;
- };
-
- template<>
- struct stopwatch_reporter_default_formatter<simple_stopwatch<process_system_cpu_clock> >
- {
- typedef elapsed_formatter type;
- };
-
- template<>
- struct wstopwatch_reporter_default_formatter<simple_stopwatch<process_system_cpu_clock> >
- {
- typedef welapsed_formatter type;
- };
-
- template<>
- struct stopwatch_reporter_default_formatter<simple_stopwatch<process_cpu_clock> >
+ struct clock_default_formatter<process_cpu_clock>
     {
       typedef times_formatter type;
     };
 
     template<>
- struct wstopwatch_reporter_default_formatter<simple_stopwatch<process_cpu_clock> >
+ struct wclock_default_formatter<process_cpu_clock>
     {
       typedef wtimes_formatter type;
     };
@@ -77,4 +41,3 @@
 
 #endif
 
-

Modified: trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp (original)
+++ trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -8,16 +8,24 @@
 #ifndef BOOST_CHRONO_STOPWATCHES_REPORTERS_DEFAULT_FORMATTER_HPP
 #define BOOST_CHRONO_STOPWATCHES_REPORTERS_DEFAULT_FORMATTER_HPP
 
+#include <boost/chrono/stopwatches/reporters/clock_default_formatter.hpp>
+
 namespace boost
 {
   namespace chrono
   {
 
     template<class Stopwatch>
- struct stopwatch_reporter_default_formatter;
+ struct stopwatch_reporter_default_formatter
+ : clock_default_formatter<typename Stopwatch::clock>
+ {
+ };
 
     template<class Stopwatch>
- struct wstopwatch_reporter_default_formatter;
+ struct wstopwatch_reporter_default_formatter
+ : wclock_default_formatter<typename Stopwatch::clock>
+ {
+ };
 
   } // namespace chrono
 } // namespace boost

Modified: trunk/boost/chrono/stopwatches/reporters/system_default_formatter.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/reporters/system_default_formatter.hpp (original)
+++ trunk/boost/chrono/stopwatches/reporters/system_default_formatter.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -9,44 +9,11 @@
 #define BOOST_CHRONO_STOPWATCHES_REPORTERS_SYSTEM_DEFAULT_FORMATTER_HPP
 
 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp>
+#include <boost/chrono/stopwatches/reporters/clock_default_formatter.hpp>
 #include <boost/chrono/stopwatches/formatters/elapsed_formatter.hpp>
-#include <boost/chrono/stopwatches/simple_stopwatch.hpp>
 #include <boost/chrono/system_clocks.hpp>
 
-namespace boost
-{
- namespace chrono
- {
-
- template<>
- struct stopwatch_reporter_default_formatter<simple_stopwatch<system_clock> >
- {
- typedef elapsed_formatter type;
- };
-
- template<>
- struct wstopwatch_reporter_default_formatter<simple_stopwatch<system_clock> >
- {
- typedef welapsed_formatter type;
- };
-
- template<>
- struct stopwatch_reporter_default_formatter<simple_stopwatch<steady_clock> >
- {
- typedef elapsed_formatter type;
- };
-
- template<>
- struct wstopwatch_reporter_default_formatter<simple_stopwatch<steady_clock> >
- {
- typedef welapsed_formatter type;
- };
-
- } // namespace chrono
-} // namespace boost
-
 
 
 #endif
 
-

Modified: trunk/boost/chrono/stopwatches/reporters/thread_default_formatter.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/reporters/thread_default_formatter.hpp (original)
+++ trunk/boost/chrono/stopwatches/reporters/thread_default_formatter.hpp 2011-10-02 04:19:01 EDT (Sun, 02 Oct 2011)
@@ -11,29 +11,10 @@
 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
 
 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp>
+#include <boost/chrono/stopwatches/reporters/clock_default_formatter.hpp>
 #include <boost/chrono/stopwatches/formatters/elapsed_formatter.hpp>
-#include <boost/chrono/stopwatches/simple_stopwatch.hpp>
 #include <boost/chrono/thread_clock.hpp>
 
-namespace boost
-{
- namespace chrono
- {
-
- template<>
- struct stopwatch_reporter_default_formatter<simple_stopwatch<thread_clock> >
- {
- typedef elapsed_formatter type;
- };
-
- template<>
- struct wstopwatch_reporter_default_formatter<simple_stopwatch<thread_clock> >
- {
- typedef welapsed_formatter type;
- };
-
- } // namespace chrono
-} // namespace boost
 
 
 #endif


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