Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74370 - in sandbox/stopwatches: boost/chrono/stopwatches boost/chrono/stopwatches/formatters boost/chrono/stopwatches/reporters libs/chrono/stopwatches/example
From: vicente.botet_at_[hidden]
Date: 2011-09-13 18:15:02


Author: viboes
Date: 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
New Revision: 74370
URL: http://svn.boost.org/trac/boost/changeset/74370

Log:
Stopwatches: Going towards Boost.Format based formatters
Added:
   sandbox/stopwatches/boost/chrono/stopwatches/formatters/
   sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp (contents, props changed)
   sandbox/stopwatches/boost/chrono/stopwatches/formatters/oneshot_formatter.hpp (contents, props changed)
   sandbox/stopwatches/boost/chrono/stopwatches/reporters/
   sandbox/stopwatches/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp (contents, props changed)
Text files modified:
   sandbox/stopwatches/boost/chrono/stopwatches/clock_suspender.hpp | 39 ++++++++++-------
   sandbox/stopwatches/boost/chrono/stopwatches/lightweight_stopwatch.hpp | 30 --------------
   sandbox/stopwatches/boost/chrono/stopwatches/stopwatch_reporter.hpp | 5 +
   sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp | 85 +++++++++++++++++++++++++--------------
   sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp | 2
   5 files changed, 82 insertions(+), 79 deletions(-)

Modified: sandbox/stopwatches/boost/chrono/stopwatches/clock_suspender.hpp
==============================================================================
--- sandbox/stopwatches/boost/chrono/stopwatches/clock_suspender.hpp (original)
+++ sandbox/stopwatches/boost/chrono/stopwatches/clock_suspender.hpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -10,27 +10,34 @@
 #include <boost/system/error_code.hpp>
 #include <boost/mpl/bool.hpp>
 
-namespace boost { namespace chrono {
-
-
- template <class Clock>
- struct is_suspendible : mpl:: false_ {};
+namespace boost
+{
+ namespace chrono
+ {
+
+ template<class Clock>
+ struct is_suspendible: mpl::false_
+ {
+ };
 
- template <class Clock>
- class clock_suspender {
+ template<class Clock>
+ class clock_suspender
+ {
     public:
- clock_suspender(system::error_code & ec = BOOST_CHRONO_THROWS) {
- ec.clear();
- }
- ~clock_suspender() {}
+ clock_suspender(system::error_code & ec = BOOST_CHRONO_THROWS)
+ {
+ ec.clear();
+ }
+ ~clock_suspender()
+ {
+ }
     private:
- //~ clock_suspender(); // = delete;
- clock_suspender(const clock_suspender&); // = delete;
- clock_suspender& operator=(const clock_suspender&); // = delete;
+ //~ clock_suspender(); // = delete;
+ clock_suspender(const clock_suspender&); // = delete;
+ clock_suspender& operator=(const clock_suspender&); // = delete;
     };
 
-
-} // namespace chrono
+ } // namespace chrono
 } // namespace boost
 
 

Added: sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -0,0 +1,141 @@
+// 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_STOPWATCHES_FORMATTERS_ELAPSED_HPP
+#define BOOST_STOPWATCHES_FORMATTERS_ELAPSED_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
+#include <boost/chrono/stopwatches/detail/adaptive_string.hpp>
+#include <boost/chrono/chrono_io.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_ELAPSED_FORMAT_DEFAULT "%1%"
+
+namespace boost
+{
+ 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
+ {
+
+ public:
+ 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_elapsed_formatter() :
+ internal_fmt_(BOOST_CHRONO_STOPWATCHES_ELAPSED_FORMAT_DEFAULT),
+ fmt_(internal_fmt_), precision_(3), os_(std::cout),
+ style_(basic_elapsed_formatter::symbol_manip)
+ {
+ }
+ 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)
+ {
+ }
+ basic_elapsed_formatter(string_type const& fmt) :
+ internal_fmt_(fmt), fmt_(internal_fmt_), precision_(3), os_(std::cout),
+ style_(basic_elapsed_formatter::symbol_manip)
+ {
+ }
+ basic_elapsed_formatter(format_type & fmt) :
+ fmt_(fmt), precision_(3), os_(std::cout),
+ style_(basic_elapsed_formatter::symbol_manip)
+ {
+ }
+
+ void set_precision(std::size_t precision)
+ {
+ precision_=precision;
+ if (precision_ > 9)
+ precision_ = 9; // sanity check
+ }
+ void set_os(ostream_type& os)
+ {
+ os_=os;
+ }
+ void set_duration_style(duration_style style)
+ {
+ if (style==symbol) style_=symbol_manip;
+ else if (style==text) style_=text_manip;
+ }
+ static string_type format(const char* s)
+ {
+ string_type res(s);
+ res += boost::chrono::detail::adaptive_string(" : ");
+ res += BOOST_CHRONO_STOPWATCHES_ELAPSED_FORMAT_DEFAULT;
+ return res;
+ }
+
+ template<class Stopwatch>
+ void operator()(Stopwatch & stopwatch_, system::error_code & ec)
+ {
+ typedef typename Stopwatch::duration duration_t;
+ duration_t d = stopwatch_.elapsed(ec);
+
+ if (d < duration_t::zero())
+ return;
+
+ os_
+ << fmt_
+ % io::group(std::fixed, std::setprecision(precision_), style_, boost::chrono::duration<
+ double, Ratio>(d)) << std::endl;
+
+ }
+ private:
+ boost::format internal_fmt_;
+ boost::format& fmt_;
+ std::size_t precision_;
+ ostream_type & os_;
+ ostream_type& (*style_)(ostream_type& os);
+
+ 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;
+
+ } // namespace chrono
+} // namespace boost
+
+#define BOOST_CHRONO_STOPWATCHES_ELAPSED_FORMAT(F) \
+ boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_STOPWATCHES_ELAPSED_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_CHRONO_STOPWATCHES_ELAPSED_FUNCTION_FORMAT \
+ boost::chrono::elapsed_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_CHRONO_STOPWATCHES_ELAPSED_FUNCTION_FORMAT \
+ BOOST_CHRONO_STOPWATCHES_ELAPSED_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+#endif

Added: sandbox/stopwatches/boost/chrono/stopwatches/formatters/oneshot_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/stopwatches/boost/chrono/stopwatches/formatters/oneshot_formatter.hpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -0,0 +1,128 @@
+// 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_STOPWATCHES_FORMATTERS_ONESHOT_HPP
+#define BOOST_STOPWATCHES_FORMATTERS_ONESHOT_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
+#include <boost/chrono/stopwatches/detail/adaptive_string.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+#include <boost/assert.hpp>
+
+#define BOOST_CHRONO_STOPWATCHES_ONESHOOT_FORMAT_DEFAULT "%ds\n"
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ template<typename CharT = char, typename Traits = std::char_traits<CharT>,
+ class Alloc = std::allocator<CharT> >
+ class basic_oneshot_formatter
+ {
+ public:
+ typedef std::basic_string<CharT, Traits, Alloc> string_type;
+ typedef CharT char_type;
+ typedef std::basic_ostream<CharT, Traits> ostream_type;
+
+ basic_oneshot_formatter() :
+ format_(BOOST_CHRONO_STOPWATCHES_ONESHOOT_FORMAT_DEFAULT), precision_(3),
+ os_(std::cout)
+ {
+ }
+ basic_oneshot_formatter(const char_type* fmt) :
+ format_(fmt), precision_(3), os_(std::cout)
+ {
+ }
+ basic_oneshot_formatter(string_type const& fmt) :
+ str_(fmt), format_(str_.c_str()), precision_(3), os_(std::cout)
+ {
+ }
+ void set_precision(std::size_t precision)
+ {
+ precision_=precision;
+ if (precision_ > 9)
+ precision_ = 9; // sanity check
+ }
+ void set_os(ostream_type os)
+ {
+ os_=os;
+ }
+ static string_type format(const char* s)
+ {
+ string_type res(s);
+ res += boost::chrono::detail::adaptive_string(" : ");
+ res += BOOST_CHRONO_STOPWATCHES_ONESHOOT_FORMAT_DEFAULT;
+ return res;
+ }
+
+ template<class Stopwatch>
+ void operator()(Stopwatch & stopwatch_, system::error_code & ec)
+ {
+ typedef typename Stopwatch::duration duration_t;
+ duration_t d = stopwatch_.elapsed(ec);
+
+ if (d < duration_t::zero())
+ return;
+
+ boost::io::ios_flags_saver ifs(os_);
+ os_.setf(std::ios_base::fixed, std::ios_base::floatfield);
+ boost::io::ios_precision_saver ips(os_);
+ os_.precision(precision_);
+
+ for (; *format_; ++format_)
+ {
+ if ((*format_ != '%') || (!*(format_ + 1))
+ || (!std::strchr("d", *(format_ + 1))))
+ {
+ os_ << *format_;
+ } else
+ {
+ ++format_;
+ switch (*format_)
+ {
+ case 'd':
+ os_ << boost::chrono::duration<double>(d).count();
+ break;
+ default:
+ // todo this should be replaced by a ec or an exception.
+ BOOST_ASSERT(0
+ && "basic_stopwatch_formatter internal logic error");
+ }
+ }
+ }
+ }
+ private:
+ string_type str_;
+ const char_type* format_;
+ std::size_t precision_;
+ ostream_type & os_;
+ };
+
+ typedef basic_oneshot_formatter<char> oneshot_formatter;
+ typedef basic_oneshot_formatter<wchar_t> woneshot_formatter;
+
+ } // namespace chrono
+} // namespace boost
+
+#define BOOST_CHRONO_STOPWATCHES_ONESHOT_FORMAT(F) \
+ boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_STOPWATCHES_ONESHOOT_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_CHRONO_STOPWATCHES_ONESHOT_FUNCTION_FORMAT \
+ boost::chrono::oneshot_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_CHRONO_STOPWATCHES_ONESHOT_FUNCTION_FORMAT \
+ BOOST_CHRONO_STOPWATCHES_ONESHOT_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+#endif

Modified: sandbox/stopwatches/boost/chrono/stopwatches/lightweight_stopwatch.hpp
==============================================================================
--- sandbox/stopwatches/boost/chrono/stopwatches/lightweight_stopwatch.hpp (original)
+++ sandbox/stopwatches/boost/chrono/stopwatches/lightweight_stopwatch.hpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -12,7 +12,6 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/stopwatches/stopwatch_scoped.hpp>
 #include <boost/system/error_code.hpp>
-//#include <boost/chrono/chrono_io.hpp>
 
 namespace boost
 {
@@ -30,7 +29,6 @@
     class lightweight_stopwatch;
 
 
-//--------------------------------------------------------------------------------------//
     template <typename Clock, typename Traits>
     class lightweight_stopwatch
     {
@@ -48,7 +46,6 @@
           start_(duration::zero()), level_(0), partial_(duration::zero()), suspend_level_(0)
           , storage_(&acc), construction_(clock::now( ))
         {
- //std::cout << "construction_:" << construction_ << std::endl;
             start(ec);
         }
 
@@ -57,7 +54,6 @@
           start_(duration::zero()), level_(0), partial_(duration::zero()), suspend_level_(0)
           , storage_(&acc), construction_(clock::now( ))
         {
- //std::cout << "construction_:" << construction_ << std::endl;
         }
 
         ~lightweight_stopwatch() {
@@ -66,7 +62,6 @@
         }
 
         
-//--------------------------------------------------------------------------------------//
         std::pair<duration, time_point> restart( system::error_code & ec = BOOST_CHRONO_THROWS )
         {
           time_point tmp=clock::now( ec );
@@ -225,31 +220,6 @@
         time_point construction_;
     };
 
-//--------------------------------------------------------------------------------------//
-// typedef accumulators::features<
-// accumulators::tag::count,
-// accumulators::tag::sum,
-// accumulators::tag::min,
-// accumulators::tag::max,
-// accumulators::tag::mean
-// > default_features;
-// typedef boost::chrono::lightweight_stopwatch< boost::chrono::system_clock > system_lightweight_stopwatch;
-//#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
-// typedef boost::chrono::lightweight_stopwatch< boost::chrono::steady_clock > steady_lightweight_stopwatch;
-//#endif
-// typedef boost::chrono::lightweight_stopwatch< boost::chrono::high_resolution_clock > high_resolution_lightweight_stopwatch;
-//
-// typedef boost::chrono::lightweight_stopwatch< boost::chrono::system_clock,
-// lightweight_stopwatch_accumulator_set_traits<default_features> > system_lightweight_stopwatch_accumulator;
-//#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
-// typedef boost::chrono::lightweight_stopwatch< boost::chrono::steady_clock,
-// lightweight_stopwatch_accumulator_set_traits<default_features> > steady_lightweight_stopwatch_accumulator;
-//#endif
-// typedef boost::chrono::lightweight_stopwatch< boost::chrono::high_resolution_clock,
-// lightweight_stopwatch_accumulator_set_traits<default_features> > high_resolution_lightweight_stopwatch_accumulator;
-
-//--------------------------------------------------------------------------------------//
-
 
   } // namespace chrono
 } // namespace boost

Added: sandbox/stopwatches/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp
==============================================================================
--- (empty file)
+++ sandbox/stopwatches/boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -0,0 +1,236 @@
+// boost/chrono/stopwatches/stopwatch_reporter2.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_STOPWATCHES_REPORTERS_STOPWATCH_REPORTER_HPP
+#define BOOST_STOPWATCHES_REPORTERS_STOPWATCH_REPORTER_HPP
+
+#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_STOPWATCHES_ENABLE_WARNINGS)
+#if defined __GNUC__
+#pragma GCC system_header
+#elif defined __SUNPRO_CC
+#pragma disable_warn
+#elif defined _MSC_VER
+#pragma warning(push, 1)
+#endif
+#endif
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/stopwatches/stopwatch_scoped.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/chrono/stopwatches/clock_suspender.hpp>
+#include <boost/cstdint.hpp>
+#include <cassert>
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ template<class Stopwatch, class Formatter>
+ class basic_stopwatch_reporter2: public Stopwatch
+ {
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter_type;
+
+ basic_stopwatch_reporter2() :
+ formatter_(), reported_(false)
+ {
+ }
+
+ explicit basic_stopwatch_reporter2(const typename Formatter::char_type* fmt) :
+ formatter_(fmt), reported_(false)
+ {
+ }
+ explicit basic_stopwatch_reporter2(typename Formatter::string_type const& fmt) :
+ formatter_(fmt), reported_(false)
+ {
+ }
+ explicit basic_stopwatch_reporter2(formatter_type const& fmt) :
+ formatter_(fmt), reported_(false)
+ {
+ }
+
+ ~basic_stopwatch_reporter2() // never throws
+ {
+ system::error_code ec;
+ if (!reported())
+ {
+ this->report(ec);
+ }
+ }
+
+ inline void report(system::error_code & /*ec*/= BOOST_CHRONO_THROWS);
+ bool reported() const
+ {
+ return reported_;
+ }
+
+ typedef stopwatch_runner<basic_stopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_run;
+ typedef stopwatch_stopper<basic_stopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_stop;
+ typedef stopwatch_suspender<basic_stopwatch_reporter2<Stopwatch,
+ Formatter> > scoped_suspend;
+ typedef stopwatch_resumer<basic_stopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_resume;
+
+ protected:
+ formatter_type formatter_;
+ bool reported_;
+
+ basic_stopwatch_reporter2(const basic_stopwatch_reporter2&); // = delete;
+ basic_stopwatch_reporter2& operator=(const basic_stopwatch_reporter2&); // = delete;
+ };
+
+ template<class Stopwatch, class Formatter>
+ void basic_stopwatch_reporter2<Stopwatch, Formatter>::report(system::error_code & ec)
+ {
+ // chrono::clock_suspender<typename Stopwatch::clock> _(ec);
+ // if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ // if (ec) return;
+ // }
+
+ reported_ = true;
+ formatter_(*this, ec);
+ }
+
+ template<class Stopwatch>
+ struct stopwatch_reporter2_default_formatter;
+
+ template<class Stopwatch,
+ class Formatter = typename stopwatch_reporter2_default_formatter<
+ Stopwatch>::type>
+ class stopwatch_reporter2;
+
+ template<class Stopwatch, class Formatter>
+ struct stopwatch_reporter2_default_formatter<stopwatch_reporter2<Stopwatch,
+ Formatter> >
+ {
+ typedef Formatter type;
+ };
+
+ template<class Stopwatch, class Formatter>
+ class stopwatch_reporter2: public basic_stopwatch_reporter2<Stopwatch,
+ Formatter>
+ {
+ typedef basic_stopwatch_reporter2<Stopwatch, Formatter> base_type;
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter_type;
+
+ stopwatch_reporter2()
+ //: base_type()
+ {
+ }
+ explicit stopwatch_reporter2(formatter_type const& fmt) :
+ base_type(fmt)
+ {
+ }
+ explicit stopwatch_reporter2(const typename Formatter::char_type* fmt) :
+ base_type(fmt)
+ {
+ }
+ explicit stopwatch_reporter2(typename Formatter::string_type const& fmt) :
+ base_type(fmt)
+ {
+ }
+ typedef stopwatch_runner<stopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_run;
+ typedef stopwatch_stopper<stopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_stop;
+ typedef stopwatch_suspender<stopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_suspend;
+ typedef stopwatch_resumer<stopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_resume;
+
+ protected:
+
+ stopwatch_reporter2(const stopwatch_reporter2&); // = delete;
+ stopwatch_reporter2& operator=(const stopwatch_reporter2&); // = delete;
+ };
+
+ template<class Stopwatch>
+ struct wstopwatch_reporter2_default_formatter;
+
+ template<class Stopwatch,
+ class Formatter = typename wstopwatch_reporter2_default_formatter<
+ Stopwatch>::type>
+ class wstopwatch_reporter2;
+
+ template<class Stopwatch, class Formatter>
+ struct wstopwatch_reporter2_default_formatter<wstopwatch_reporter2<
+ Stopwatch, Formatter> >
+ {
+ typedef Formatter type;
+ };
+
+ template<class Stopwatch, class Formatter>
+ class wstopwatch_reporter2: public basic_stopwatch_reporter2<Stopwatch,
+ Formatter>
+ {
+ typedef basic_stopwatch_reporter2<Stopwatch, Formatter> base_type;
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter_type;
+
+ wstopwatch_reporter2() :
+ base_type()
+ {
+ }
+ explicit wstopwatch_reporter2(formatter_type const& fmt) :
+ base_type(fmt)
+ {
+ }
+
+ typedef stopwatch_runner<wstopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_run;
+ typedef stopwatch_stopper<wstopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_stop;
+ typedef stopwatch_suspender<wstopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_suspend;
+ typedef stopwatch_resumer<wstopwatch_reporter2<Stopwatch, Formatter> >
+ scoped_resume;
+
+ protected:
+
+ //wstopwatch_reporter2(); // = delete;
+ wstopwatch_reporter2(const wstopwatch_reporter2&); // = delete;
+ wstopwatch_reporter2& operator=(const wstopwatch_reporter2&); // = delete;
+ };
+
+ } // namespace chrono
+} // namespace boost
+
+
+#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_STOPWATCHES_ENABLE_WARNINGS)
+#if defined __SUNPRO_CC
+#pragma enable_warn
+#elif defined _MSC_VER
+#pragma warning(pop)
+#endif
+#endif
+
+#endif
+
+//boost::chrono::basic_stopwatch_reporter2<Stopwatch, Formatter>::basic_stopwatch_reporter2(const Formatter&)Õ
+//boost::chrono::basic_stopwatch_reporter2<Stopwatch, Formatter>::basic_stopwatch_reporter2(const boost::chrono::basic_stopwatch_reporter2<Stopwatch, Formatter>&) [with Stopwatch = boost::chrono::stopwatch<boost::chrono::system_clock>, Formatter = boost::chrono::basic_elapsed_formatter<boost::ratio<1l, 1000000l>, char, std::char_traits<char>, std::allocator<char> >]
+//boost::chrono::basic_stopwatch_reporter2<Stopwatch, Formatter>::basic_stopwatch_reporter2(const typename Formatter::string_type&) [with Stopwatch = boost::chrono::stopwatch<boost::chrono::system_clock>, Formatter = boost::chrono::basic_elapsed_formatter<boost::ratio<1l, 1000000l>, char, std::char_traits<char>, std::allocator<char> >]
+//boost::chrono::basic_stopwatch_reporter2<Stopwatch, Formatter>::basic_stopwatch_reporter2(const typename Formatter::char_type*) [with Stopwatch = boost::chrono::stopwatch<boost::chrono::system_clock>, Formatter = boost::chrono::basic_elapsed_formatter<boost::ratio<1l, 1000000l>, char, std::char_traits<char>, std::allocator<char> >]
+
+
+
+
+
+
+
+
+
+

Modified: sandbox/stopwatches/boost/chrono/stopwatches/stopwatch_reporter.hpp
==============================================================================
--- sandbox/stopwatches/boost/chrono/stopwatches/stopwatch_reporter.hpp (original)
+++ sandbox/stopwatches/boost/chrono/stopwatches/stopwatch_reporter.hpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -33,10 +33,11 @@
 namespace boost { namespace chrono {
 
 //--------------------------------------------------------------------------------------//
-//~ provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+//~ Provides a everything a Stopwatch provides and it adds reporting capabilities that can be invoked in a single line of code.
+// The reporting is controlled by two parameters:
 
     //~ * format : The output format
- //~ * places(precission): the number of decimal placess used.
+ //~ * places(precision): the number of decimal places used.
 
 //~ The default places is given by default_places and is 3. The default format is "\n%ts\n", where
 

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -3,59 +3,84 @@
 // 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.
+#include <iostream>
 
 #include <boost/chrono/stopwatches/stopwatches.hpp>
+#include <boost/chrono/stopwatches/formatters/elapsed_formatter.hpp>
+#include <boost/chrono/stopwatches/formatters/oneshot_formatter.hpp>
+#include <boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp>
 #include <cmath>
 #include <string>
 #include "sleep_for.hpp"
 #include <boost/chrono/chrono_io.hpp>
 #include <boost/format.hpp>
 
+namespace boost { namespace chrono {
+ template <>
+ struct stopwatch_reporter2_default_formatter<stopwatch<system_clock> > {
+ typedef elapsed_formatter type;
+ }; template <>
+ struct stopwatch_reporter2_default_formatter<stopwatch<high_resolution_clock> > {
+ typedef elapsed_formatter type;
+ };
+}}
+
 using namespace boost::chrono;
+using namespace boost;
 
-template <typename Stopwatch>
-class stopwatch_reporter : public Stopwatch
-{
- public:
- stopwatch_reporter( )
- : internal_fmt_("%1%"), fmt_(internal_fmt_) {}
- stopwatch_reporter(const char* str )
- : internal_fmt_(str), fmt_(internal_fmt_) {}
- stopwatch_reporter(std::string const& str )
- : internal_fmt_(str), fmt_(internal_fmt_) {}
- stopwatch_reporter(boost::format & fmt )
- : fmt_(fmt) {}
- ~stopwatch_reporter() {
- std::cout << fmt_ % this->elapsed() << std::endl;
- }
- private:
- boost::format internal_fmt_;
- boost::format& fmt_;
-};
 
 long double res;
+void f0(long j)
+{
+ stopwatch_reporter2<stopwatch<high_resolution_clock> > sw;
+ for (long i =0; i< j; i+=1)
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+}
 void f1(long j)
 {
- //stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
- boost::format fmt("f1(%1%): Elapsed time: %2%");
- fmt % j;
- ::stopwatch_reporter<stopwatch<> > sw(fmt);
+ boost::format fmt("%1%[%2%] f1(%3%) - Elapsed time: %4%");
+ fmt % __FILE__ % __LINE__ % j;
+ stopwatch_reporter2<stopwatch<high_resolution_clock> > sw(fmt);
   for (long i =0; i< j; i+=1)
     res+=std::sqrt( res+123.456L+i ); // burn some time
- stopwatch_suspender< ::stopwatch_reporter<stopwatch<> > > _(sw);
+}
+
+void f2(long j)
+{
+ boost::format fmt("%1%[%2%] %3% - Elapsed time: %4%");
+ fmt % __FILE__ % __LINE__ % BOOST_CURRENT_FUNCTION;
+ stopwatch_reporter2<stopwatch<high_resolution_clock> > sw(fmt);
+ for (long i =0; i< j; i+=1)
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ stopwatch_suspender< stopwatch_reporter2<stopwatch<high_resolution_clock> > > _(sw);
   boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
 }
+void f3(long j)
+{
+ typedef basic_elapsed_formatter<milli > formatter;
+ formatter fmt("Elapsed time: %1%",std::cerr);
+ fmt.set_duration_style(text);
+ fmt.set_precision(6);
+
+ stopwatch_reporter2<stopwatch<high_resolution_clock>, formatter> sw(fmt);
+ for (long i =0; i< j; i+=1)
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+}
 
 int main()
 {
- //stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
- ::stopwatch_reporter<stopwatch<> > _("main(): Elapsed time: %1%");
+ std::cout << __FILE__ << "[" << __LINE__ <<"]"<< std::endl;
+ stopwatch_reporter2<stopwatch<> > sw(BOOST_CHRONO_STOPWATCHES_ELAPSED_FUNCTION_FORMAT);
 
   res=0;
- for (long i =1; i< 4; ++i) {
- f1(i*1000000);
- }
+ f0(1000000);
+ f1(1000000);
+ f2(1000000);
+ f3(3000000);
 
   std::cout<< res << std::endl;
- return 0;
+ return 1;
 }
+
+
+

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp 2011-09-13 18:15:00 EDT (Tue, 13 Sep 2011)
@@ -50,7 +50,7 @@
   ~stopwatch_reporter() {
     typename Stopwatch::accumulator_set& acc = this->get_storage();
     typedef typename Stopwatch::duration duration_t;
- int precision_=3;
+ std::size_t precision_=3;
 
     os_ << fmt_
         % boost::accumulators::count(acc)


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