|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65154 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-08-31 15:42:31
Author: viboes
Date: 2010-08-31 15:42:28 EDT (Tue, 31 Aug 2010)
New Revision: 65154
URL: http://svn.boost.org/trac/boost/changeset/65154
Log:
Refactoring of lihtweight_stopwatch
Text files modified:
sandbox/chrono/boost/chrono/lightweight_stopwatch.hpp | 110 +++++++++++++++++++--------------------
sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp | 12 ++-
sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp | 4
sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp | 4
sandbox/chrono/boost/chrono/stopwatch_scoped.hpp | 4
5 files changed, 67 insertions(+), 67 deletions(-)
Modified: sandbox/chrono/boost/chrono/lightweight_stopwatch.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/lightweight_stopwatch.hpp (original)
+++ sandbox/chrono/boost/chrono/lightweight_stopwatch.hpp 2010-08-31 15:42:28 EDT (Tue, 31 Aug 2010)
@@ -29,35 +29,34 @@
namespace chrono
{
- template <typename Clock, typename Features, typename Weight>
- class lightweight_stopwatch_traits {
- public:
- static const bool is_accumulator_set = true;
- typedef accumulators::accumulator_set<typename Clock::duration::rep, Features, Weight> accumulator_set_t;
- typedef typename Clock::duration duration;
- static duration get_duration(accumulator_set_t& acc_) { return duration(accumulators::sum(acc_)); }
- static void set_duration(accumulator_set_t& acc_, duration d) { acc_(d.count()); }
- static void reset(accumulator_set_t& acc_) { acc_=accumulator_set_t(); }
+ template <typename Features, typename Weight=void>
+ struct lightweight_stopwatch_accumulator_set_traits {
+ template <typename D>
+ struct apply {
+ struct type {
+ typedef accumulators::accumulator_set<typename D::rep, Features, Weight> storage_type;
+ typedef D duration_type;
+ static duration_type get_duration(storage_type& acc_) { return duration_type(accumulators::sum(acc_)); }
+ static void set_duration(storage_type& acc_, duration_type d) { acc_(d.count()); }
+ static void reset(storage_type& acc_) { acc_=storage_type(); }
+ };
+ };
};
- template <typename Clock>
- class lightweight_stopwatch_traits<Clock, void, void> {
- public:
- static const bool is_accumulator_set = false;
- typedef typename Clock::duration duration;
- typedef duration accumulator_set_t;
- static duration get_duration(accumulator_set_t& acc_) { return acc_; }
- static void set_duration(accumulator_set_t& acc_, duration d) { acc_=d; }
- static void reset(accumulator_set_t& acc_) { acc_=duration(); }
+ struct lightweight_stopwatch_identity_traits {
+ template <typename D>
+ struct apply {
+ struct type {
+ typedef D duration_type;
+ typedef duration_type storage_type;
+ static duration_type get_duration(storage_type& acc_) { return acc_; }
+ static void set_duration(storage_type& acc_, duration_type d) { acc_=d; }
+ static void reset(storage_type& acc_) { acc_=storage_type(); }
+ };
+ };
+
};
- //~ template <typename Clock>
- //~ class default_features;
-
- //~ template <>
- //~ class default_features<high_resolution_clock> {
- //~ typedef void type;
- //~ };
struct dont_start_t{};
static const dont_start_t dont_start = {};
@@ -65,40 +64,36 @@
// forward declaration
template <
typename Clock=high_resolution_clock,
- typename Features=void,
- typename Weight=void
- //~ typename Features=typename default_features<Clock>::type
+ typename Traits=lightweight_stopwatch_identity_traits
>
class lightweight_stopwatch;
//--------------------------------------------------------------------------------------//
- template <typename Clock, typename Features, typename Weight>
+ template <typename Clock, typename Traits>
class lightweight_stopwatch
{
public:
- typedef lightweight_stopwatch_traits<Clock,Features,Weight> traits;
- typedef typename traits::accumulator_set_t Accumulator;
+ typedef typename Traits::template apply<typename Clock::duration>::type traits;
+ typedef typename traits::storage_type storage_type;
typedef Clock clock;
typedef typename Clock::duration duration;
typedef typename Clock::time_point time_point;
typedef typename Clock::rep rep;
typedef typename Clock::period period;
- typedef Accumulator accumulator;
- static const bool is_accumulator_set = traits::is_accumulator_set;
- explicit lightweight_stopwatch( accumulator& acc, system::error_code & ec = system::throws )
+ explicit lightweight_stopwatch( storage_type& acc, system::error_code & ec = system::throws )
: running_(false), suspended_(false),
start_(duration::zero()), level_(0), partial_(duration::zero()), suspend_level_(0)
- , accumulated_(&acc), construction_(clock::now( ))
+ , storage_(&acc), construction_(clock::now( ))
{
start(ec);
}
- lightweight_stopwatch( accumulator& acc, const dont_start_t& )
+ lightweight_stopwatch( storage_type& acc, const dont_start_t& )
: running_(false), suspended_(false),
start_(duration::zero()), level_(0), partial_(duration::zero()), suspend_level_(0)
- , accumulated_(&acc), construction_(clock::now( ))
+ , storage_(&acc), construction_(clock::now( ))
{
}
@@ -115,13 +110,13 @@
if (ec) return time_point();
if (running_&&(level_==1)) {
partial_ += tmp - start_;
- traits::set_duration(accumulated(),partial_);
+ traits::set_duration(get_storage(),partial_);
partial_=duration::zero();
} else {
running_=true;
}
start_=tmp;
- return std::make_pair(traits::get_duration(accumulated()),start_);
+ return std::make_pair(traits::get_duration(get_storage()),start_);
}
time_point start( system::error_code & ec = system::throws )
@@ -146,10 +141,10 @@
time_point tmp=clock::now( ec );
if (ec) return duration::zero();
partial_ += tmp - start_;
- traits::set_duration(accumulated(),partial_);
+ traits::set_duration(get_storage(),partial_);
partial_=duration::zero();
running_=false;
- return traits::get_duration(accumulated());
+ return traits::get_duration(get_storage());
} else {
ec.clear();
return duration::zero();
@@ -165,7 +160,7 @@
++suspend_level_;
partial_ += tmp - start_;
suspended_=true;
- return traits::get_duration(accumulated());
+ return traits::get_duration(get_storage());
} else {
++suspend_level_;
ec.clear();
@@ -195,14 +190,14 @@
{
if (running_) {
if (suspended_)
- return traits::get_duration(accumulated());
+ return traits::get_duration(get_storage());
else {
time_point tmp = clock::now( ec );
if (ec) return duration::zero();
- return traits::get_duration(accumulated())+tmp - start_;
+ return traits::get_duration(get_storage())+tmp - start_;
}
} else {
- return traits::get_duration(accumulated());
+ return traits::get_duration(get_storage());
}
}
@@ -215,7 +210,7 @@
{
construction_=clock::now( ec );
if (ec) return;
- traits::reset(accumulated());
+ traits::reset(get_storage());
running_=false;
suspended_=false;
partial_ = duration::zero();
@@ -224,9 +219,9 @@
suspend_level_=0;
}
- accumulator& accumulated( )
+ storage_type& get_storage( )
{
- return *accumulated_;
+ return *storage_;
}
duration lifetime( system::error_code & ec = system::throws )
@@ -234,10 +229,10 @@
return clock::now( ec ) - construction_;
}
- typedef stopwatch_runner<lightweight_stopwatch<Clock,Features,Weight> > scoped_run;
- typedef stopwatch_stopper<lightweight_stopwatch<Clock,Features,Weight> > scoped_stop;
- typedef stopwatch_suspender<lightweight_stopwatch<Clock,Features,Weight> > scoped_suspend;
- typedef stopwatch_resumer<lightweight_stopwatch<Clock,Features,Weight> > scoped_resume;
+ typedef stopwatch_runner<lightweight_stopwatch<Clock,Traits> > scoped_run;
+ typedef stopwatch_stopper<lightweight_stopwatch<Clock,Traits> > scoped_stop;
+ typedef stopwatch_suspender<lightweight_stopwatch<Clock,Traits> > scoped_suspend;
+ typedef stopwatch_resumer<lightweight_stopwatch<Clock,Traits> > scoped_resume;
private:
bool running_;
bool suspended_;
@@ -245,7 +240,7 @@
std::size_t level_;
duration partial_;
std::size_t suspend_level_;
- accumulator* accumulated_;
+ storage_type* storage_;
time_point construction_;
};
@@ -263,11 +258,14 @@
#endif
typedef boost::chrono::lightweight_stopwatch< boost::chrono::high_resolution_clock > high_resolution_lightweight_stopwatch;
- typedef boost::chrono::lightweight_stopwatch< boost::chrono::system_clock,default_features > system_lightweight_stopwatch_accumulator;
+ 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_MONOTONIC
- typedef boost::chrono::lightweight_stopwatch< boost::chrono::monotonic_clock,default_features > monotonic_lightweight_stopwatch_accumulator;
+ typedef boost::chrono::lightweight_stopwatch< boost::chrono::monotonic_clock,
+ lightweight_stopwatch_accumulator_set_traits<default_features> > monotonic_lightweight_stopwatch_accumulator;
#endif
- typedef boost::chrono::lightweight_stopwatch< boost::chrono::high_resolution_clock,default_features > high_resolution_lightweight_stopwatch_accumulator;
+ typedef boost::chrono::lightweight_stopwatch< boost::chrono::high_resolution_clock,
+ lightweight_stopwatch_accumulator_set_traits<default_features> > high_resolution_lightweight_stopwatch_accumulator;
//--------------------------------------------------------------------------------------//
Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp 2010-08-31 15:42:28 EDT (Tue, 31 Aug 2010)
@@ -54,17 +54,19 @@
template <class Clock, typename Features, typename Weight>
class stopwatch_accumulator
- : private base_from_member<typename accumulators::accumulator_set<typename Clock::duration::rep, Features, Weight> >,
- public lightweight_stopwatch<Clock,Features,Weight>
+ : private base_from_member<
+ typename accumulators::accumulator_set<typename Clock::duration::rep, Features, Weight>
+ //~ typename lightweight_stopwatch_accumulator_set_traits<Features,Weight>::template apply<Clock::duration>::storage_type
+ >,
+ public lightweight_stopwatch<Clock,lightweight_stopwatch_accumulator_set_traits<Features,Weight> >
{
public:
typedef base_from_member<typename accumulators::accumulator_set<typename Clock::duration::rep, Features, Weight> > pbase_type;
stopwatch_accumulator( )
- : pbase_type(), lightweight_stopwatch<Clock,Features,Weight>(pbase_type::member, dont_start)
+ : pbase_type(),
+ lightweight_stopwatch<Clock,lightweight_stopwatch_accumulator_set_traits<Features,Weight> >(pbase_type::member, dont_start)
{ }
- //~ private:
- //~ stopwatch_accumulator operator=( stopwatch_accumulator const& rhs );
};
//--------------------------------------------------------------------------------------//
Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp 2010-08-31 15:42:28 EDT (Tue, 31 Aug 2010)
@@ -67,9 +67,9 @@
{
if (&ec==&system::throws) ec.clear();
- typedef typename Stopwatch::accumulator accumulator;
+ typedef typename Stopwatch::storage_type accumulator;
typedef typename Stopwatch::duration duration_t;
- accumulator& acc = stopwatch_.accumulated();
+ accumulator& acc = stopwatch_.get_storage();
duration_t lt= stopwatch_.lifetime(ec);
if (ec) return;
Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_time_formatter.hpp 2010-08-31 15:42:28 EDT (Tue, 31 Aug 2010)
@@ -69,9 +69,9 @@
{
if (&ec==&system::throws) ec.clear();
- typedef typename Stopwatch::accumulator accumulator;
+ typedef typename Stopwatch::storage_type accumulator;
typedef typename Stopwatch::duration duration_t;
- accumulator& acc = stopwatch_.accumulated();
+ accumulator& acc = stopwatch_.get_storage();
duration_t lt= stopwatch_.lifetime();
//if ( d < duration_t::zero() ) return;
Modified: sandbox/chrono/boost/chrono/stopwatch_scoped.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_scoped.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_scoped.hpp 2010-08-31 15:42:28 EDT (Tue, 31 Aug 2010)
@@ -35,7 +35,7 @@
#if 0
typename Stopwatch::duration elapsed(system::error_code & ec = system::throws)
{
- return stopwatch_.elapsed(ec)-stopwatch_.accumulated();
+ return stopwatch_.elapsed(ec)-stopwatch_.get_storage();
}
#endif
private:
@@ -61,7 +61,7 @@
#if 0
typename Stopwatch::duration elapsed(system::error_code & ec = system::throws)
{
- return stopwatch_.elapsed(ec)-stopwatch_.accumulated();
+ return stopwatch_.elapsed(ec)-stopwatch_.get_storage();
}
#endif
private:
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