ROSE  0.9.9.109
Stopwatch.h
1 // WARNING: Changes to this file must be contributed back to Sawyer or else they will
2 // be clobbered by the next update from Sawyer. The Sawyer repository is at
3 // https://github.com/matzke1/sawyer.
4 
5 
6 
7 
8 #ifndef Sawyer_Stopwatch_H
9 #define Sawyer_Stopwatch_H
10 
11 #include <Sawyer/Sawyer.h>
12 
13 #ifdef SAWYER_HAVE_BOOST_CHRONO
14 # include <boost/chrono/duration.hpp>
15 # include <boost/chrono/system_clocks.hpp>
16 #endif
17 
18 namespace Sawyer {
19 
41 class SAWYER_EXPORT Stopwatch {
42 public:
43 #ifdef SAWYER_HAVE_BOOST_CHRONO
44  typedef boost::chrono::high_resolution_clock::time_point TimePoint;
45  typedef boost::chrono::duration<double> Duration;
46 #else
47  typedef double TimePoint;
48  typedef double Duration;
49 #endif
50 
51 private:
52 #include <Sawyer/WarningsOff.h>
53  mutable TimePoint begin_; // time that this stopwatch (re)started
54  mutable Duration elapsed_; // sum of elapsed run time in seconds
55  bool running_; // state of the stopwatch: running or not
56 #include <Sawyer/WarningsRestore.h>
57 
58 public:
62  explicit Stopwatch(bool start=true): elapsed_(0), running_(false) {
63  start && this->start();
64  }
65 
69  double clear(double value=0.0);
70 
77  double start();
78  double start(double value);
79  double start(bool b) SAWYER_DEPRECATED("use start() or start(double)") { return b ? start() : start(0.0); }
85  double restart();
86 
92  double stop(bool clear=false);
93 
98  double report(bool clear=false) const;
99 
103  bool isRunning() const { return running_; }
104 };
105 
106 
107 SAWYER_EXPORT std::ostream& operator<<(std::ostream&, const Stopwatch&);
108 
109 } // namespace
110 #endif
void clear(SharedPointer< T > &ptr)
Make pointer point to nothing.
bool isRunning() const
Query state of stopwatch.
Definition: Stopwatch.h:103
Name space for the entire library.
Definition: Access.h:11
Simple elapsed time.
Definition: Stopwatch.h:41
Stopwatch(bool start=true)
Construct and optionally start a timer.
Definition: Stopwatch.h:62
double start(bool b) __attribute__((deprecated))
Start the timer and report accumulated time.
Definition: Stopwatch.h:79