|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58481 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2009-12-21 11:56:35
Author: viboes
Date: 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
New Revision: 58481
URL: http://svn.boost.org/trac/boost/changeset/58481
Log:
Boost.Chrono: Version 0.3.0, New stopwatch feature
* independent cpu clocks for real, user, system process CPU time.
* new Stopwatch concept measuring elapsed time between different points in time associated to the operations start, stop, suspend and resume.
* stopwatch is a model Stopwatch measuring the elapsed time between the start and the stop operations.
* stopwatch_accumulator is a model Stopwatch allowing to accumulate several time samples and give the average, ...
* scoped helper classes allowing to pairwise start/stop operations, suspend/resume and resume/suspend a Stopwatch.
* new Stopwatch Formatter concept
* stopwatch_reporter is a generic class reporting elapsed time for the Stopwatch concept.
* process_times.hpp has been deprecated, see process_clocks.hpp, process_stopwhatches.hpp and process_stopwhatches_reporter.hpp.
* timer.hpp has been deprecated, see stopwatch.
Added:
sandbox/chrono/boost/chrono/cpu_clocks.hpp (contents, props changed)
sandbox/chrono/boost/chrono/process_clocks.hpp (contents, props changed)
sandbox/chrono/boost/chrono/process_stopwatches.hpp (contents, props changed)
sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp (contents, props changed)
sandbox/chrono/boost/chrono/stopwatch.hpp (contents, props changed)
sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp (contents, props changed)
sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp (contents, props changed)
sandbox/chrono/boost/chrono/stopwatch_formatter.hpp (contents, props changed)
sandbox/chrono/boost/chrono/stopwatch_reporter.hpp (contents, props changed)
sandbox/chrono/boost/chrono/stopwatch_scoped.hpp (contents, props changed)
Text files modified:
sandbox/chrono/boost/chrono/chrono.hpp | 9 ++-
sandbox/chrono/boost/chrono/process_times.hpp | 98 +++++++++++++++++++++++----------------
sandbox/chrono/boost/chrono/timer.hpp | 2
3 files changed, 64 insertions(+), 45 deletions(-)
Modified: sandbox/chrono/boost/chrono/chrono.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/chrono.hpp (original)
+++ sandbox/chrono/boost/chrono/chrono.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -58,6 +58,7 @@
#ifndef BOOST_CHRONO_HPP
#define BOOST_CHRONO_HPP
+#include <iostream>
#include <ctime>
#include <climits>
@@ -103,8 +104,6 @@
#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES)
#endif
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
#ifdef BOOST_CHRONO_WINDOWS_API
// The system_clock tick is 100 nanoseconds
# define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::duration<boost::int_least64_t, ratio<BOOST_INTMAX_C(1), BOOST_INTMAX_C(10000000)> >
@@ -112,6 +111,8 @@
# define BOOST_SYSTEM_CLOCK_DURATION boost::chrono::nanoseconds
#endif
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
//----------------------------------------------------------------------------//
// //
// 20.9 Time utilities [time] //
@@ -495,7 +496,7 @@
rep rep_;
public:
- BOOST_CONSTEXPR duration() {} // = default;
+ BOOST_CONSTEXPR duration() { } // = default;
template <class Rep2>
BOOST_CONSTEXPR explicit duration(const Rep2& r,
typename boost::enable_if_c
@@ -507,7 +508,7 @@
)
)
>::type* = 0)
- : rep_(r) {}
+ : rep_(r) { }
~duration() {} //= default;
duration(const duration& rhs) : rep_(rhs.rep_) {} // = default;
duration& operator=(const duration& rhs) // = default;
Added: sandbox/chrono/boost/chrono/cpu_clocks.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/cpu_clocks.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,58 @@
+// boost cpu_clocks.hpp -----------------------------------------------------------//
+
+// Copyright 2009 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/system for documentation.
+
+#ifndef BOOST_CHRONO_CPU_CLOCKS_HPP
+#define BOOST_CHRONO_CPU_CLOCKS_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace chrono {
+
+ class BOOST_CHRONO_DECL process_real_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_real_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( system::error_code & ec = system::throws );
+ };
+
+ class process_user_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_user_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( system::error_code & ec = system::throws );
+ };
+
+ class process_system_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_system_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+
+ static time_point now( system::error_code & ec = system::throws );
+ };
+
+} // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_PROCESS_TIMES_HPP
Added: sandbox/chrono/boost/chrono/process_clocks.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/process_clocks.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,61 @@
+// boost process_clocks.hpp -----------------------------------------------------------//
+
+// Copyright Beman Dawes 1994, 2007, 2008
+// Copyright 2009-2010 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/system for documentation.
+
+#ifndef BOOST_PROCESS_CLOCKS_HPP
+#define BOOST_PROCESS_CLOCKS_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+//#include <boost/cstdint.hpp>
+//#include <string>
+//#include <ostream>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ class BOOST_CHRONO_DECL process_clocks
+ {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_clocks> time_point;
+ static const bool is_monotonic = true;
+
+ struct durations
+ {
+ process_clocks::duration real; // real (i.e wall clock) time
+ process_clocks::duration user; // user cpu time
+ process_clocks::duration system; // system cpu time
+ };
+ struct time_points
+ {
+ process_clocks::time_point real; // real (i.e wall clock) time
+ process_clocks::time_point user; // user cpu time
+ process_clocks::time_point system; // system cpu time
+ };
+
+ static void now( durations & times,
+ system::error_code & ec = system::throws );
+ static void now( time_points & times,
+ system::error_code & ec = system::throws );
+ };
+
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_PROCESS_TIMES_HPP
Added: sandbox/chrono/boost/chrono/process_stopwatches.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/process_stopwatches.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,70 @@
+// boost process_times.hpp -----------------------------------------------------------//
+
+// Copyright Beman Dawes 1994, 2007, 2008
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_PROCESS_STOPWATCHED_HPP
+#define BOOST_PROCESS_STOPWATCHED_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/process_clocks.hpp>
+#include <boost/system/error_code.hpp>
+//#include <boost/cstdint.hpp>
+//#include <string>
+//#include <ostream>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace chrono
+ {
+
+
+ class BOOST_CHRONO_DECL process_stopwatches
+ // BOOST_CHRONO_DECL is required to quiet compiler warnings even though
+ // process_stopwatches has no dynamically linked members, because process_stopwatches is
+ // used as a base class for process_stopwatches_reporter, which does have dynamically linked members.
+ {
+ public:
+
+ typedef process_clocks clock;
+ typedef process_clocks::duration duration;
+ typedef process_clocks::time_point time_point;
+
+ explicit process_stopwatches( system::error_code & ec = system::throws )
+ {
+ start(ec);
+ }
+
+ ~process_stopwatches() {} // never throws
+
+ void start( system::error_code & ec = system::throws )
+ {
+ process_clocks::now( m_start, ec );
+ }
+
+ void elapsed( process_clocks::durations & times, system::error_code & ec = system::throws )
+ {
+ process_clocks::durations end;
+ process_clocks::now( end, ec );
+ times.real = end.real - m_start.real;
+ times.user = end.user - m_start.user;
+ times.system = end.system - m_start.system;
+ }
+
+ protected:
+ process_clocks::durations m_start;
+ };
+
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_PROCESS_TIMES_HPP
Added: sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,98 @@
+// boost process_times.hpp -----------------------------------------------------------//
+
+// Copyright Beman Dawes 1994, 2007, 2008
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_PROCESS_STOPWATCHED_REPORTER_HPP
+#define BOOST_PROCESS_STOPWATCHED_REPORTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/chrono/process_clocks.hpp>
+#include <boost/chrono/process_stopwatches.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <ostream>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ class BOOST_CHRONO_DECL process_stopwatches_reporter : public process_stopwatches
+ {
+ // every function making use of inlined functions of class string are not inlined to avoid DLL issues
+ public:
+
+ // each constructor form has two overloads to avoid a visible default to
+ // std::cout, which in turn would require including <iostream>, with its
+ // high associated cost, even when the standard streams are not used.
+
+ explicit process_stopwatches_reporter( system::error_code & ec = system::throws );
+ explicit process_stopwatches_reporter( std::ostream & os,
+ system::error_code & ec = system::throws );
+
+ explicit process_stopwatches_reporter( const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
+ system::error_code & ec = system::throws );
+
+ explicit process_stopwatches_reporter( const std::string & format, int places,
+ system::error_code & ec = system::throws );
+ explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
+ int places, system::error_code & ec = system::throws );
+
+ explicit process_stopwatches_reporter( int places,
+ system::error_code & ec = system::throws );
+ explicit process_stopwatches_reporter( std::ostream & os, int places,
+ system::error_code & ec = system::throws );
+
+ explicit process_stopwatches_reporter( int places, const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit process_stopwatches_reporter( std::ostream & os, int places, const std::string & format,
+ system::error_code & ec = system::throws );
+
+ ~process_stopwatches_reporter() // never throws
+ {
+ system::error_code ec;
+ if ( !reported() ) report( ec );
+ }
+
+ void start( system::error_code & ec = system::throws )
+ {
+ m_reported = false;
+ process_stopwatches::start( ec );
+ }
+
+ void report( system::error_code & ec = system::throws );
+
+ void test_report( duration real_, duration user_, duration system_ );
+
+ bool reported() const { return m_reported; }
+
+ static int default_places() { return m_default_places; }
+
+ private:
+ int m_places;
+ std::ostream & m_os;
+ std::string m_format;
+ bool m_reported;
+
+ static std::ostream & m_cout();
+ static const int m_default_places = 3;
+ };
+
+ typedef process_stopwatches_reporter run_timer; // backward comppatibility
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_PROCESS_TIMES_HPP
Modified: sandbox/chrono/boost/chrono/process_times.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_times.hpp (original)
+++ sandbox/chrono/boost/chrono/process_times.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -11,6 +11,10 @@
#define BOOST_PROCESS_TIMES_HPP
#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/process_clocks.hpp>
+#include <boost/chrono/process_stopwatches.hpp>
+#include <boost/chrono/process_stopwatches_reporter.hpp>
+
#include <boost/system/error_code.hpp>
#include <boost/cstdint.hpp>
#include <string>
@@ -22,68 +26,78 @@
{
namespace chrono
{
-
- struct process_times;
-
//--------------------------------------------------------------------------------------//
-// process_clock //
+// process_clocks //
//--------------------------------------------------------------------------------------//
+#if 0
- class BOOST_CHRONO_DECL process_clock
+ class BOOST_CHRONO_DECL process_clocks
{
public:
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
- typedef chrono::time_point<process_clock> time_point;
+ typedef chrono::time_point<process_clocks> time_point;
static const bool is_monotonic = true;
- static void now( process_times & times,
+ struct durations
+ {
+ process_clocks::duration real; // real (i.e wall clock) time
+ process_clocks::duration user; // user cpu time
+ process_clocks::duration system; // system cpu time
+ };
+ struct time_points
+ {
+ process_clocks::time_point real; // real (i.e wall clock) time
+ process_clocks::time_point user; // user cpu time
+ process_clocks::time_point system; // system cpu time
+ };
+
+ static void now( durations & times,
+ system::error_code & ec = system::throws );
+ static void now( time_points & times,
system::error_code & ec = system::throws );
};
-
+#endif
//--------------------------------------------------------------------------------------//
// process_times //
//--------------------------------------------------------------------------------------//
- struct process_times
- {
- process_clock::duration real; // real (i.e wall clock) time
- process_clock::duration user; // user cpu time
- process_clock::duration system; // system cpu time
- };
+ typedef process_clocks process_clock;
+ typedef process_clocks::durations process_times;
//--------------------------------------------------------------------------------------//
-// process_timer //
+// process_stopwatches //
//--------------------------------------------------------------------------------------//
+#if 0
- class BOOST_CHRONO_DECL process_timer
+ class BOOST_CHRONO_DECL process_stopwatches
// BOOST_CHRONO_DECL is required to quiet compiler warnings even though
- // process_timer has no dynamically linked members, because process_timer is
- // used as a base class for run_timer, which does have dynamically linked members.
+ // process_stopwatches has no dynamically linked members, because process_stopwatches is
+ // used as a base class for process_stopwatches_reporter, which does have dynamically linked members.
{
public:
- typedef process_clock clock;
- typedef process_clock::duration duration;
- typedef process_clock::time_point time_point;
+ typedef process_clocks clock;
+ typedef process_clocks::duration duration;
+ typedef process_clocks::time_point time_point;
- explicit process_timer( system::error_code & ec = system::throws )
+ explicit process_stopwatches( system::error_code & ec = system::throws )
{
start(ec);
}
- ~process_timer() {} // never throws
+ ~process_stopwatches() {} // never throws
void start( system::error_code & ec = system::throws )
{
- process_clock::now( m_start, ec );
+ process_clocks::now( m_start, ec );
}
void elapsed( process_times & times, system::error_code & ec = system::throws )
{
process_times end;
- process_clock::now( end, ec );
+ process_clocks::now( end, ec );
times.real = end.real - m_start.real;
times.user = end.user - m_start.user;
times.system = end.system - m_start.system;
@@ -92,12 +106,14 @@
protected:
process_times m_start;
};
-
+#endif
+ typedef process_stopwatches process_timer; // backward comppatibility
//--------------------------------------------------------------------------------------//
-// run_timer //
+// process_stopwatches_reporter //
//--------------------------------------------------------------------------------------//
+#if 0
- class BOOST_CHRONO_DECL run_timer : public process_timer
+ class BOOST_CHRONO_DECL process_stopwatches_reporter : public process_stopwatches
{
// every function making use of inlined functions of class string are not inlined to avoid DLL issues
public:
@@ -106,31 +122,31 @@
// std::cout, which in turn would require including <iostream>, with its
// high associated cost, even when the standard streams are not used.
- explicit run_timer( system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os,
+ explicit process_stopwatches_reporter( system::error_code & ec = system::throws );
+ explicit process_stopwatches_reporter( std::ostream & os,
system::error_code & ec = system::throws );
- explicit run_timer( const std::string & format,
+ explicit process_stopwatches_reporter( const std::string & format,
system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, const std::string & format,
+ explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
system::error_code & ec = system::throws );
- explicit run_timer( const std::string & format, int places,
+ explicit process_stopwatches_reporter( const std::string & format, int places,
system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, const std::string & format,
+ explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
int places, system::error_code & ec = system::throws );
- explicit run_timer( int places,
+ explicit process_stopwatches_reporter( int places,
system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, int places,
+ explicit process_stopwatches_reporter( std::ostream & os, int places,
system::error_code & ec = system::throws );
- explicit run_timer( int places, const std::string & format,
+ explicit process_stopwatches_reporter( int places, const std::string & format,
system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, int places, const std::string & format,
+ explicit process_stopwatches_reporter( std::ostream & os, int places, const std::string & format,
system::error_code & ec = system::throws );
- ~run_timer() // never throws
+ ~process_stopwatches_reporter() // never throws
{
system::error_code ec;
if ( !reported() ) report( ec );
@@ -139,7 +155,7 @@
void start( system::error_code & ec = system::throws )
{
m_reported = false;
- process_timer::start( ec );
+ process_stopwatches::start( ec );
}
void report( system::error_code & ec = system::throws );
@@ -159,6 +175,8 @@
static std::ostream & m_cout();
static const int m_default_places = 3;
};
+#endif
+ typedef process_stopwatches_reporter run_timer; // backward comppatibility
} // namespace chrono
} // namespace boost
Added: sandbox/chrono/boost/chrono/stopwatch.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/stopwatch.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,182 @@
+// boost/chrono/timer.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_STOPWATCH_HPP
+#define BOOST_CHRONO_STOPWATCH_HPP
+
+#include <utility>
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/stopwatch_scoped.hpp>
+#include <boost/chrono/stopwatch_formatter.hpp>
+#include <boost/chrono/stopwatch_reporter.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace chrono
+ {
+
+//--------------------------------------------------------------------------------------//
+// stopwatch
+//
+//~ A stopwatch is a class designed to measure the amount of time elapsed from a particular time
+//~ when activated to when it is deactivated.
+
+//~ Calling start starts the timer running, and calling stop stops it.
+//~ A call to reset resets the stopwatch to zero.
+//~ A stopwatch can also also used to record split times or lap times.
+//~ The elapsed time since the last start is available through the elapsed function.
+//~ When the freeze function is called while the watch is running, the elapsed time is frozen,
+//~ allowing the elapsed time to that point to be read using the frozen function,
+//~ but the watch mechanism continues running to record total elapsed time.
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock=high_resolution_clock>
+ class stopwatch;
+
+ template <class Clock>
+ struct stopwatch_reporter_default_formatter<stopwatch<Clock> > {
+ typedef stopwatch_formatter type;
+ };
+
+ struct dont_start_t{};
+ static const dont_start_t dont_start = {};
+ template <class Clock>
+ class stopwatch
+ {
+ public:
+ typedef Clock clock;
+ typedef typename Clock::duration duration;
+ typedef typename Clock::time_point time_point;
+
+ explicit stopwatch( system::error_code & ec = system::throws )
+ : running_(false), start_(), level_(0)
+ {
+ start(ec);
+ }
+
+ explicit stopwatch( const dont_start_t& t )
+ : running_(false), start_(), level_(0)
+ { }
+
+ time_point start( system::error_code & ec = system::throws ) {
+ ++level_;
+ if (!running_) {
+ time_point tmp = clock::now( ec );
+ if (ec) return time_point();
+ start_ = tmp;
+ running_=true;
+ return start_;
+ } else {
+ return time_point();
+ }
+ }
+
+ duration stop( system::error_code & ec = system::throws ) {
+ if (running_&&(--level_==0)) {
+ time_point tmp=clock::now( ec );
+ if (ec) return duration(0);
+ partial_ += tmp - start_;
+ duration frozen= partial_;
+ partial_=duration(0);
+ running_=false;
+ return frozen;
+ } else {
+ return duration(0);
+ }
+ }
+
+ std::pair<duration, time_point> restart( system::error_code & ec = system::throws ) {
+ duration frozen;
+ time_point tmp=clock::now( ec );
+ if (ec) return time_point();
+ if (running_&&(--level_==0)) {
+ partial_ += tmp - start_;
+ frozen = partial_;
+ partial_=duration(0);
+ } else {
+ frozen = duration(0);
+ running_=true;
+ }
+ start_=tmp;
+ ++level_;
+ return std::make_pair(frozen, start_);
+ }
+
+ duration suspend( system::error_code & ec = system::throws ) {
+ if (running_) {
+ ++suspend_level_;
+ if (!suspended_) {
+ time_point tmp=clock::now( ec );
+ if (ec) return duration(0);
+ partial_ += tmp - start_;
+ suspended_=true;
+ return partial_;
+ } else {
+ return duration(0);
+ }
+ } else {
+ return duration(0);
+ }
+ }
+ time_point resume( system::error_code & ec = system::throws ) {
+ if (suspended_&&(--suspend_level_==0)) {
+ time_point tmp = clock::now( ec );
+ if (ec) return time_point();
+ start_ = tmp;
+ suspended_=false;
+ return start_;
+ } else {
+ return time_point();
+ }
+ }
+
+ duration elapsed( system::error_code & ec = system::throws )
+ {
+ return clock::now( ec ) - start_;
+ }
+
+ void reset( system::error_code & ec = system::throws ) {
+ start_ = time_point();
+ level_=0;
+ running_=false;
+ }
+
+ typedef stopwatch_runner<stopwatch<Clock> > scoped_run;
+ typedef stopwatch_suspender<stopwatch<Clock> > scoped_suspend;
+ typedef stopwatch_resumer<stopwatch<Clock> > scoped_resume;
+ typedef stopwatch_reporter<stopwatch<Clock> > reporter;
+
+ private:
+ bool running_;
+ bool suspended_;
+ time_point start_;
+ std::size_t level_;
+ duration partial_;
+ std::size_t suspend_level_;
+
+ };
+
+//--------------------------------------------------------------------------------------//
+ typedef boost::chrono::stopwatch< boost::chrono::system_clock > system_stopwatch;
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::stopwatch< boost::chrono::monotonic_clock > monotonic_stopwatch;
+#endif
+ typedef boost::chrono::stopwatch< boost::chrono::high_resolution_clock > high_resolution_stopwatch;
+
+
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif
Added: sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,202 @@
+// boost/chrono/timer.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_STOPWATCH_ACCUMULATOR_HPP
+#define BOOST_CHRONO_STOPWATCH_ACCUMULATOR_HPP
+
+#include <utility>
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/stopwatch_scoped.hpp>
+#include <boost/chrono/stopwatch_reporter.hpp>
+#include <boost/chrono/stopwatch_accumulator_formatter.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/accumulators/framework/accumulator_set.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/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace chrono
+ {
+
+//--------------------------------------------------------------------------------------//
+// stopwatch
+//
+//~ A stopwatch accumulator is a class designed to measure the amount of time elapsed from a particular time
+//~ when activated to when it is deactivated.
+
+//~ Calling start starts the timer running, and calling stop stops it.
+//~ A call to reset resets the stopwatch to zero.
+//~ A stopwatch can also also used to record split times or lap times.
+//~ The elapsed time since the last start is available through the elapsed function.
+//~ When the freeze function is called while the watch is running, the elapsed time is frozen,
+//~ allowing the elapsed time to that point to be read using the frozen function,
+//~ but the watch mechanism continues running to record total elapsed time.
+//--------------------------------------------------------------------------------------//
+
+ // forward declaration
+ template <class Clock=high_resolution_clock,
+ class Accumulator=accumulators::accumulator_set<typename Clock::duration::rep,
+ accumulators::features<
+ accumulators::tag::count,
+ accumulators::tag::sum,
+ accumulators::tag::min,
+ accumulators::tag::max,
+ accumulators::tag::mean >
+ >
+ >
+ class stopwatch_accumulator;
+
+ template <class Clock>
+ struct stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock> > {
+ typedef stopwatch_accumulator_formatter type;
+ };
+
+//--------------------------------------------------------------------------------------//
+ template <class Clock, class Accumulator>
+ class stopwatch_accumulator
+ {
+ public:
+ typedef Clock clock;
+ typedef typename Clock::duration duration;
+ typedef typename Clock::time_point time_point;
+ typedef Accumulator accumulator;
+
+ stopwatch_accumulator( )
+ : running_(false), partial_(0)
+ {
+ }
+
+ std::pair<duration, time_point> restart( system::error_code & ec = system::throws ) {
+ time_point tmp=clock::now( ec );
+ if (ec) return time_point();
+ if (running_&&(--level_==0)) {
+ partial_ += tmp - start_;
+ accumulated_(partial_.count());
+ partial_=duration(0);
+ } else {
+ running_=true;
+ }
+ start_=tmp;
+ ++level_;
+ return std::make_pair(duration(accumulators::sum(accumulated_)),start_);
+ }
+
+ time_point start( system::error_code & ec = system::throws ) {
+ ++level_;
+ if (!running_) {
+ time_point tmp = clock::now( ec );
+ if (ec) return time_point();
+ start_ = tmp;
+ running_ = true;
+ return start_;
+ } else {
+ return time_point();
+ }
+ }
+
+ duration stop( system::error_code & ec = system::throws ) {
+ if (running_&&(--level_==0)) {
+ time_point tmp=clock::now( ec );
+ if (ec) return duration(0);
+ partial_ += tmp - start_;
+ accumulated_(partial_.count());
+ partial_=duration(0);
+ running_=false;
+ return duration(accumulators::extract::sum(accumulated_));
+ } else {
+ return duration(0);
+ }
+ }
+
+ duration suspend( system::error_code & ec = system::throws ) {
+ if (running_) {
+ ++suspend_level_;
+ if (!suspended_) {
+ time_point tmp=clock::now( ec );
+ if (ec) return duration(0);
+ partial_ += tmp - start_;
+ suspended_=true;
+ return duration(accumulators::sum(accumulated_));
+ } else {
+ return duration(0);
+ }
+ } else {
+ return duration(0);
+ }
+ }
+ time_point resume( system::error_code & ec = system::throws ) {
+ if (suspended_&&(--suspend_level_==0)) {
+ time_point tmp = clock::now( ec );
+ if (ec) return time_point();
+ start_ = tmp;
+ suspended_=false;
+ return start_;
+ } else {
+ return time_point();
+ }
+ }
+ duration elapsed( system::error_code & ec = system::throws )
+ {
+ if (running_) {
+ if (suspended_)
+ return duration(accumulators::sum(accumulated_));
+ else {
+ time_point tmp = clock::now( ec );
+ if (ec) return duration(0);
+ return duration(accumulators::sum(accumulated_))+tmp - start_;
+ }
+ } else {
+ return duration(accumulators::sum(accumulated_));
+ }
+ }
+
+ void reset( ) {
+ time_point tmp = time_point();
+ start_ = tmp;
+ accumulator tmp2;
+ accumulated_ = tmp2;
+ }
+ accumulator& accumulated( ) { return accumulated_; }
+
+ typedef stopwatch_runner<stopwatch_accumulator<Clock> > scoped_run;
+ typedef stopwatch_suspender<stopwatch_accumulator<Clock> > scoped_suspend;
+ typedef stopwatch_resumer<stopwatch_accumulator<Clock> > scoped_resume;
+ typedef stopwatch_reporter<stopwatch_accumulator<Clock> > reporter;
+ private:
+ bool running_;
+ bool suspended_;
+ accumulator accumulated_;
+ duration partial_;
+ time_point start_;
+ std::size_t level_;
+ std::size_t suspend_level_;
+ };
+
+//--------------------------------------------------------------------------------------//
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::system_clock > system_stopwatch_accumulator;
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_accumulator;
+#endif
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopwatch_accumulator;
+
+//--------------------------------------------------------------------------------------//
+
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif
Added: sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,104 @@
+// boost/chrono/timer.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_STOPWATCH_ACCUMULATOR_FORMATTER_HPP
+#define BOOST_CHRONO_STOPWATCH_ACCUMULATOR_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+#include <boost/accumulators/framework/accumulator_set.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/chrono/stopwatch_accumulator.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace chrono {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+
+ class stopwatch_accumulator_formatter {
+ public:
+ static std::ostream & m_cout();
+ static const int m_default_places = 3;
+ static const char * default_format;
+ 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)
+ // 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.
+ {
+ typedef typename Stopwatch::accumulator accumulator;
+ typedef typename Stopwatch::duration duration;
+ accumulator& acc = stopwatch_.accumulated();
+
+ //if ( d < duration(0) ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 0;
+
+ 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( places );
+
+ os << "***" ;
+ for ( ; *format; ++format ) {
+ if ( *format != '%' || !*(format+1) || !std::strchr("smMac", *(format+1)) ) {
+ os << *format;
+ } else {
+ ++format;
+ switch ( *format ) {
+ case 's':
+ os << boost::chrono::duration<double>(duration(accumulators::sum(acc))).count();
+ break;
+ case 'm':
+ os << boost::chrono::duration<double>(duration((accumulators::min)(acc))).count();
+ break;
+ case 'M':
+ os << boost::chrono::duration<double>(duration((accumulators::max)(acc))).count();
+ break;
+ case 'a':
+ os << ((accumulators::count(acc)>0)
+ ? (boost::chrono::duration<double>(duration(accumulators::sum(acc))).count())/accumulators::count(acc)
+ : 0);
+ break;
+ case 'c':
+ os << accumulators::count(acc);
+ break;
+ default:
+ assert(0 && "run_timer internal logic error");
+ }
+ }
+ }
+ }
+ };
+ const char * stopwatch_accumulator_formatter::default_format ="\nCount=%c times Sum=%ss Min=%ms Max=%Ms Mean=%as\n";
+ std::ostream & stopwatch_accumulator_formatter::m_cout() { return std::cout; }
+
+} // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif
Added: sandbox/chrono/boost/chrono/stopwatch_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/stopwatch_formatter.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,82 @@
+// boost/chrono/timer.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_STOPWATCH_FORMATTER_HPP
+#define BOOST_CHRONO_STOPWATCH_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+//#include <boost/chrono/stopwatch.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace chrono {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+
+ class stopwatch_formatter {
+ public:
+ static std::ostream & m_cout();
+ static const int m_default_places = 3;
+ static const char * default_format;
+ 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)
+ // 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.
+ {
+ typedef typename Stopwatch::duration duration;
+ duration d = stopwatch_.elapsed( ec );
+
+ if ( d < duration(0) ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 0;
+
+ 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( places );
+
+ 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:
+ assert(0 && "run_timer internal logic error");
+ }
+ }
+ }
+ }
+ };
+ const char * stopwatch_formatter::default_format ="\n%ds\n";
+
+ std::ostream & stopwatch_formatter::m_cout() { return std::cout; }
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif
Added: sandbox/chrono/boost/chrono/stopwatch_reporter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/stopwatch_reporter.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,220 @@
+// boost/chrono/timer.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_STOPWATCH_REPORTER_HPP
+#define BOOST_CHRONO_STOPWATCH_REPORTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/stopwatch_scoped.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+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:
+
+ //~ * format : The output format
+ //~ * places(precission): the number of decimal placess used.
+
+//~ The default places is given by default_places and is 3. The default format is "\n%ts\n", where
+
+ //~ * %t : the result of elapsed() when the reporting is done.
+
+//~ The time is given using the suffix "s" following the System International d'Unites Std.
+
+/* void f1()
+ * {
+ * stopwatch_reporter<stopwatch<> > _;
+ * // ...
+ * }
+ */
+/* void f2()
+ * {
+ * stopwatch<>::reporter _;
+ * // ...
+ * }
+ */
+/* void f3()
+ * {
+ * static stopwatch_reporter<stopwatch_accumulator<> > t;
+ * stopwatch_reporter<stopwatch_accumulator<> >::scoped_run _(t);
+ * // ...
+ * }
+ */
+/* void f4()
+ * {
+ * static stopwatch_accumulator<>::reporter t;
+ * stopwatch_accumulator<>::reporter::scoped_run _(t);
+ * // ...
+ * }
+ */
+//--------------------------------------------------------------------------------------//
+
+
+ template <class Stopwatch>
+ struct stopwatch_reporter_default_formatter {
+ typename Stopwatch::formatter type;
+ };
+
+ template <class Stopwatch, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
+ class stopwatch_reporter;
+
+ template <class Stopwatch, class Formatter>
+ struct stopwatch_reporter_default_formatter<stopwatch_reporter<Stopwatch, Formatter> > {
+ typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type type;
+ };
+
+
+ template <class Stopwatch, class Formatter>
+ class stopwatch_reporter : public Stopwatch {
+ public:
+ explicit stopwatch_reporter( system::error_code & ec = system::throws )
+ : m_places(Formatter::m_default_places), m_os(Formatter::m_cout()), m_reported(false) { }
+ explicit stopwatch_reporter( std::ostream & os,
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::m_default_places), m_os(os), m_reported(false) { }
+
+ explicit stopwatch_reporter( const std::string & format,
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::m_default_places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) { }
+
+ explicit stopwatch_reporter( std::ostream & os, const std::string & format,
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::m_default_places), m_os(os), m_format(format), m_reported(false) { }
+
+ explicit stopwatch_reporter( const std::string & format, int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) { }
+ explicit stopwatch_reporter( std::ostream & os, const std::string & format, int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_reported(false) { }
+
+ explicit stopwatch_reporter( int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::m_cout()), m_reported(false) { }
+ explicit stopwatch_reporter( std::ostream & os, int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_reported(false) { }
+
+ explicit stopwatch_reporter( int places, const std::string & format,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) { }
+ explicit stopwatch_reporter( std::ostream & os, int places, const std::string & format,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_format(format), m_reported(false) { }
+
+ ~stopwatch_reporter() {// never throws
+ system::error_code ec;
+ //this->stop(ec);
+ if ( !reported() )
+ this->report( ec );
+ }
+
+
+ inline void report( system::error_code & ec = system::throws );
+ bool reported() const { return m_reported; }
+
+
+ typedef stopwatch_runner<stopwatch_reporter<Stopwatch> > scoped_run;
+ typedef stopwatch_suspender<stopwatch_reporter<Stopwatch> > scoped_suspend;
+ typedef stopwatch_resumer<stopwatch_reporter<Stopwatch> > scoped_resume;
+
+ private:
+ int m_places;
+ std::ostream & m_os;
+ std::string m_format;
+ bool m_reported;
+
+
+ //stopwatch_reporter(); // = delete;
+ stopwatch_reporter(const stopwatch_reporter&); // = delete;
+ stopwatch_reporter& operator=(const stopwatch_reporter&); // = delete;
+ };
+
+
+ namespace detail {
+
+ template <class Stopwatch >
+ void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & 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.
+ {
+ typedef typename Stopwatch::duration duration;
+ duration d = stopwatch_.elapsed( ec );
+
+ if ( d < duration(0) ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 0;
+
+ 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( places );
+
+ 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();
+ //os << d.count();
+ break;
+ default:
+ assert(0 && "run_timer internal logic error");
+ }
+ }
+ }
+ }
+ }
+
+ template <class Stopwatch, class Formatter>
+ void stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
+ m_reported = true;
+ if ( m_format.empty() ) m_format = Formatter::default_format;
+
+ //typename Stopwatch::duration d = this->elapsed( ec );
+
+ if ( &ec == &system::throws ) {
+ Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec);
+ } else {// non-throwing
+ try {
+ Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec );
+ ec = system::error_code();
+ } catch (...) { // eat any exceptions
+ assert( 0 && "error reporting not fully implemented yet" );
+ //ec = error_code( EIO, errno_ecat );
+ }
+ }
+
+ }
+
+
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif
Added: sandbox/chrono/boost/chrono/stopwatch_scoped.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/stopwatch_scoped.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -0,0 +1,93 @@
+// boost/chrono/timer.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_STOPWATCH_SCOPED_HPP
+#define BOOST_CHRONO_STOPWATCH_SCOPED_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace chrono
+ {
+
+//--------------------------------------------------------------------------------------//
+ template <class Stopwatch> class stopwatch_runner {
+ public:
+ typedef Stopwatch stopwatch_type;
+ stopwatch_runner(stopwatch_type & a, system::error_code & ec = system::throws)
+ : stopwatch_(a) {
+ stopwatch_.start(ec);
+ }
+ ~stopwatch_runner() {
+ system::error_code ec;
+ stopwatch_.stop(ec);
+ }
+#if 0
+ typename Stopwatch::duration elapsed(system::error_code & ec = system::throws)
+ {
+ return stopwatch_.elapsed(ec)-stopwatch_.accumulated();
+ }
+#endif
+ private:
+ stopwatch_type& stopwatch_;
+ stopwatch_runner();//= delete;
+ stopwatch_runner(const stopwatch_runner&); // = delete;
+ stopwatch_runner& operator=(const stopwatch_runner&); // = delete;
+
+ };
+
+//--------------------------------------------------------------------------------------//
+ template <class Stopwatch> class stopwatch_suspender {
+ public:
+ typedef Stopwatch stopwatch_type;
+ stopwatch_suspender(stopwatch_type & a, system::error_code & ec = system::throws)
+ : stopwatch_(a) {
+ stopwatch_.suspend(ec);
+ }
+ ~stopwatch_suspender() {
+ system::error_code & ec;
+ stopwatch_.resume(ec);
+ }
+ private:
+ stopwatch_type& stopwatch_;
+ stopwatch_suspender(); // = delete;
+ stopwatch_suspender(const stopwatch_suspender&); // = delete;
+ stopwatch_suspender& operator=(const stopwatch_suspender&); // = delete;
+ };
+
+//--------------------------------------------------------------------------------------//
+ template <class Stopwatch> class stopwatch_resumer {
+ public:
+ typedef Stopwatch stopwatch_type;
+ stopwatch_resumer(stopwatch_type & a, system::error_code & ec = system::throws)
+ : stopwatch_(a) {
+ stopwatch_.resume(ec);
+ }
+ ~stopwatch_resumer() {
+ system::error_code & ec;
+ stopwatch_.suspend(ec);
+ }
+ private:
+ stopwatch_type& stopwatch_;
+ stopwatch_resumer(); // = delete;
+ stopwatch_resumer(const stopwatch_resumer&); // = delete;
+ stopwatch_resumer& operator=(const stopwatch_resumer&); // = delete;
+ };
+
+
+ } // namespace chrono
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif
Modified: sandbox/chrono/boost/chrono/timer.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/timer.hpp (original)
+++ sandbox/chrono/boost/chrono/timer.hpp 2009-12-21 11:56:33 EST (Mon, 21 Dec 2009)
@@ -23,7 +23,7 @@
// timer //
//--------------------------------------------------------------------------------------//
- template <class Clock>
+ template <class Clock=high_resolution_clock>
class timer
{
public:
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