Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74649 - in trunk/boost/chrono/stopwatches: . collectors formatters reporters
From: vicente.botet_at_[hidden]
Date: 2011-10-02 11:09:55


Author: viboes
Date: 2011-10-02 11:09:54 EDT (Sun, 02 Oct 2011)
New Revision: 74649
URL: http://svn.boost.org/trac/boost/changeset/74649

Log:
Chrono: Extract dont_start used by basic_stopwatch_reporter and fix some errors in accumulator set formatter
Added:
   trunk/boost/chrono/stopwatches/dont_start.hpp (contents, props changed)
Text files modified:
   trunk/boost/chrono/stopwatches/basic_stopwatch.hpp | 33 ++++++++++++++++++++-------------
   trunk/boost/chrono/stopwatches/collectors/laps_accumulator_set.hpp | 4 ++--
   trunk/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp | 30 ++++++++++++++++++++++--------
   trunk/boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp | 11 ++++-------
   trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp | 33 +++++++++++++++++++++++++++++----
   5 files changed, 77 insertions(+), 34 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 11:09:54 EDT (Sun, 02 Oct 2011)
@@ -12,6 +12,7 @@
 #include <boost/chrono/config.hpp>
 #include <boost/chrono/stopwatches/stopwatch_scoped.hpp>
 #include <boost/chrono/stopwatches/collectors/no_memory.hpp> // default laps_collector
+#include <boost/chrono/stopwatches/dont_start.hpp>
 #include <boost/chrono/system_clocks.hpp> // default_clock
 #include <boost/system/error_code.hpp>
 
@@ -20,18 +21,6 @@
   namespace chrono
   {
 
- /**
- * Type used to don't start a basic_stopwatch at construction time.
- */
- struct dont_start_t
- {
- };
-
- /**
- * Instance used to don't start a basic_stopwatch at construction time.
- */
- static const dont_start_t dont_start =
- { };
 
     /**
      * A basic_stopwatch is a model of @c Stopwatch taking as parameters the @c Clock and the @c LapsCollector.
@@ -112,6 +101,24 @@
       /**
        * Starting constructor from a LapsCollector instance.
        *
+ * Effects: Copies the LapsCollector. Starts the stopwatch.
+ * Post-conditions: is_running() if no error occur.
+ *
+ * Remark: The LapsCollector is copied and owned by the stopwatch.
+ */
+ explicit basic_stopwatch(
+ laps_collector const& acc
+ ) :
+ start_(duration::zero()),
+ running_(false),
+ laps_collector_(acc)
+ {
+ start();
+ }
+
+ /**
+ * Starting constructor from a LapsCollector instance.
+ *
        * Effects: Assign the error code if any internal error occur while retrieving the current time.
        * Effects: Copies the LapsCollector. Starts the stopwatch.
        * Post-conditions: is_running() if no error occur.
@@ -120,7 +127,7 @@
        */
       explicit basic_stopwatch(
           laps_collector const& acc,
- system::error_code & ec = BOOST_CHRONO_THROWS
+ system::error_code & ec
           ) :
         start_(duration::zero()),
         running_(false),

Modified: trunk/boost/chrono/stopwatches/collectors/laps_accumulator_set.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/collectors/laps_accumulator_set.hpp (original)
+++ trunk/boost/chrono/stopwatches/collectors/laps_accumulator_set.hpp 2011-10-02 11:09:54 EDT (Sun, 02 Oct 2011)
@@ -5,8 +5,8 @@
 // copy at http://www.boost.org/LICENSE_1_0.txt)
 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
 
-#ifndef BOOST_CHRONO_STOPWATCHES_MEMORIES_LAPS_ACCUMULETOR_SET_HPP
-#define BOOST_CHRONO_STOPWATCHES_MEMORIES_LAPS_ACCUMULETOR_SET_HPP
+#ifndef BOOST_CHRONO_STOPWATCHES_MEMORIES_LAPS_ACCUMULATOR_SET_HPP
+#define BOOST_CHRONO_STOPWATCHES_MEMORIES_LAPS_ACCUMULATOR_SET_HPP
 
 #include <boost/chrono/stopwatches/collectors/last_lap.hpp>
 #include <boost/accumulators/framework/accumulator_set.hpp>

Added: trunk/boost/chrono/stopwatches/dont_start.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/chrono/stopwatches/dont_start.hpp 2011-10-02 11:09:54 EDT (Sun, 02 Oct 2011)
@@ -0,0 +1,32 @@
+// boost/chrono/stopwatches/basic_stopwatch.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/libs/chrono/stopwatches for documentation.
+
+#ifndef BOOST_CHRONO_STOPWATCHES_DONT_START__HPP
+#define BOOST_CHRONO_STOPWATCHES_DONT_START__HPP
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ /**
+ * Type used to don't start a basic_stopwatch at construction time.
+ */
+ struct dont_start_t
+ {
+ };
+
+ /**
+ * Instance used to don't start a basic_stopwatch at construction time.
+ */
+ static const dont_start_t dont_start =
+ { };
+
+
+ } // namespace chrono
+} // namespace boost
+
+#endif

Modified: trunk/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp (original)
+++ trunk/boost/chrono/stopwatches/formatters/accumulator_set_formatter.hpp 2011-10-02 11:09:54 EDT (Sun, 02 Oct 2011)
@@ -11,6 +11,13 @@
 #include <boost/system/error_code.hpp>
 #include <boost/current_function.hpp>
 //#include <boost/chrono/stopwatches/detail/adaptive_string.hpp>
+#include <boost/accumulators/framework/accumulator_set.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/accumulators.hpp>
 #include <boost/format.hpp>
 #include <boost/format/group.hpp>
 #include <boost/cstdint.hpp>
@@ -73,29 +80,36 @@
       {
 
 
- typedef typename Stopwatch::laps_collector laps_collector;
- laps_collector const& acc = this->get_laps_collector();
+ typedef typename Stopwatch::laps_collector::storage_type laps_collector_acc;
+ laps_collector_acc const& acc = stopwatch_.get_laps_collector().accumulator_set();
+
         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<
+ % 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::zero()) :
+ 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<
+ % 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::zero()) :
+ 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<
+ % 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::zero()) :
+ 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))))
+ double, Ratio>(duration_t::zero())))
         ;
 
       }
     };
 
- typedef basic_accumulator_set_formatter<milli, char> elapsed_formatter;
- typedef basic_accumulator_set_formatter<milli, wchar_t> welapsed_formatter;
+ typedef basic_accumulator_set_formatter<milli, char> accumulator_set_formatter;
+ typedef basic_accumulator_set_formatter<milli, wchar_t> waccumulator_set_formatter;
 
   } // namespace chrono
 } // namespace boost

Modified: trunk/boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp (original)
+++ trunk/boost/chrono/stopwatches/reporters/basic_stopwatch_default_formatter.hpp 2011-10-02 11:09:54 EDT (Sun, 02 Oct 2011)
@@ -8,10 +8,9 @@
 #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/formatters/accumulator_set_formatter.hpp>
+#include <boost/chrono/stopwatches/collectors/laps_accumulator_set.hpp>
 #include <boost/chrono/stopwatches/basic_stopwatch.hpp>
 #include <boost/chrono/thread_clock.hpp>
 
@@ -21,13 +20,13 @@
   {
 
     template <typename Clock, typename Features, typename Weight>
- struct stopwatch_reporter_default_formatter<basic_stopwatch<Clock,laps_accumulator_set<typename Clock::duration,Features, 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> >
+ struct wstopwatch_reporter_default_formatter<basic_stopwatch<Clock,laps_accumulator_set<typename Clock::duration,Features, Weight> > >
     {
       typedef waccumulator_set_formatter type;
     };
@@ -38,6 +37,4 @@
 
 #endif
 
-#endif
-
 

Modified: trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp (original)
+++ trunk/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp 2011-10-02 11:09:54 EDT (Sun, 02 Oct 2011)
@@ -20,6 +20,7 @@
 
 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter_default_formatter.hpp>
 #include <boost/chrono/stopwatches/stopwatch_scoped.hpp>
+#include <boost/chrono/stopwatches/dont_start.hpp>
 #include <boost/chrono/chrono.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
@@ -34,6 +35,7 @@
     class basic_stopwatch_reporter: public Stopwatch
     {
     public:
+ typedef Stopwatch base_type;
       typedef typename Stopwatch::clock clock;
       typedef Stopwatch stopwatch;
       typedef Formatter formatter_type;
@@ -43,8 +45,16 @@
       {
       }
 
- basic_stopwatch_reporter(system::error_code & ec) :
- Stopwatch(ec), formatter_(), reported_(false)
+ explicit basic_stopwatch_reporter(system::error_code & ec) :
+ base_type(ec), formatter_(), reported_(false)
+ {
+ }
+
+ explicit basic_stopwatch_reporter(
+ const dont_start_t& tag
+ ) BOOST_CHRONO_NOEXCEPT :
+ base_type(tag),
+ formatter_(), reported_(false)
       {
       }
 
@@ -126,11 +136,18 @@
       {
       }
 
- stopwatch_reporter(system::error_code & ec) :
+ explicit stopwatch_reporter(system::error_code & ec) :
         base_type(ec)
       {
       }
 
+ explicit stopwatch_reporter(
+ const dont_start_t& tag
+ ) BOOST_CHRONO_NOEXCEPT :
+ base_type(tag)
+ {
+ }
+
       explicit stopwatch_reporter(formatter_type const& fmt) :
         base_type(fmt)
       {
@@ -185,10 +202,18 @@
         base_type()
       {
       }
- wstopwatch_reporter(system::error_code & ec) :
+ explicit wstopwatch_reporter(system::error_code & ec) :
         base_type(ec)
       {
       }
+
+ explicit wstopwatch_reporter(
+ const dont_start_t& tag
+ ) BOOST_CHRONO_NOEXCEPT :
+ base_type(tag)
+ {
+ }
+
       explicit wstopwatch_reporter(formatter_type const& fmt) :
         base_type(fmt)
       {


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