BoosterSeat
0.1
A C++ library that includes common utilities that are used in other projects.
|
A simple stopwatch class. Basic start (resume), stop (pause), and reset functionality. More...
#include <stopwatch.hpp>
Public Types | |
enum class | Scale { SECONDS , MILLISECONDS , MICROSECONDS } |
The resolution/scale of the time returned by elapsed() More... | |
Public Member Functions | |
Stopwatch ()=default | |
Construct a new Stopwatch object. The stopwatch is stopped. More... | |
~Stopwatch ()=default | |
Default destructor. More... | |
int64_t | elapsedMicroseconds () const |
Get the elapsed time in microseconds. More... | |
double | elapsedMicrosecondsF () const |
Get the elapsed time in microseconds in a floating point format. More... | |
int64_t | elapsedMilliseconds () const |
Get the elapsed time in milliseconds. More... | |
double | elapsedMillisecondsF () const |
Get the elapsed time in milliseconds in a floating point format. More... | |
int64_t | elapsedSeconds () const |
Get the elapsed time in seconds. More... | |
double | elapsedSecondsF () const |
Get the elapsed time in seconds in a floating point format. More... | |
bool | isRunning () const |
Returns the current state of the stopwatch. More... | |
void | pause () |
alias for stop() as it does what you want it to do. More... | |
void | reset (bool stop=true) |
Resets the elapsed time. The stopwatch will keep running by default. More... | |
void | resume () |
alias for start() as it does what you want it to do. More... | |
void | start () |
Start the stopwatch. More... | |
void | stop () |
Stops/Pauses the stopwatch. Does not reset the elapsed time. More... | |
Protected Types | |
enum class | State { RUNNING , STOPPED } |
The state of the stopwatch. More... | |
Protected Member Functions | |
bst::clck::Duration | getElapsed () const |
Handles the timekeeping. More... | |
Private Attributes | |
clck::Clock | clock_ |
clck::Duration | elapsed_ = clck::Duration::zero() |
clck::TimePoint | start_ = clck::TimePoint::min() |
State | state_ = State::STOPPED |
clck::TimePoint | stop_time_ = clck::TimePoint::min() |
A simple stopwatch class. Basic start (resume), stop (pause), and reset functionality.
|
strong |
|
strongprotectedinherited |
|
default |
Construct a new Stopwatch object. The stopwatch is stopped.
|
default |
Default destructor.
|
inlinevirtual |
Start the stopwatch.
BoosterSeatException | if the stopwatch is already running. |
Implements bst::IStopwatch.
References clock_, bst::IStopwatch::RUNNING, start_, state_, and bst::IStopwatch::STOPPED.
Referenced by resume(), and TEST().
|
inlinevirtual |
Stops/Pauses the stopwatch. Does not reset the elapsed time.
Implements bst::IStopwatch.
References clock_, elapsed_, bst::IStopwatch::RUNNING, start_, state_, stop_time_, and bst::IStopwatch::STOPPED.
Referenced by pause(), reset(), and TEST().
|
inlinevirtual |
Resets the elapsed time. The stopwatch will keep running by default.
stop | If true, the stopwatch will be stopped. |
Implements bst::IStopwatch.
References clock_, elapsed_, start_, state_, stop(), and bst::IStopwatch::STOPPED.
Referenced by TEST().
|
inlinevirtual |
Returns the current state of the stopwatch.
Implements bst::IStopwatch.
References bst::IStopwatch::RUNNING, and state_.
Referenced by TEST().
|
inlinevirtual |
Get the elapsed time in microseconds.
Implements bst::IStopwatch.
References getElapsed().
Referenced by TEST().
|
inlinevirtual |
Get the elapsed time in microseconds in a floating point format.
Implements bst::IStopwatch.
References getElapsed().
Referenced by TEST().
|
inlinevirtual |
Get the elapsed time in milliseconds.
Implements bst::IStopwatch.
References getElapsed().
|
inlinevirtual |
Get the elapsed time in milliseconds in a floating point format.
Implements bst::IStopwatch.
References getElapsed().
Referenced by TEST().
|
inlinevirtual |
Get the elapsed time in seconds.
Implements bst::IStopwatch.
References getElapsed().
|
inlinevirtual |
Get the elapsed time in seconds in a floating point format.
Implements bst::IStopwatch.
References getElapsed().
Referenced by TEST().
|
inlinevirtual |
alias for stop() as it does what you want it to do.
Implements bst::IStopwatch.
References stop().
|
inlinevirtual |
alias for start() as it does what you want it to do.
Implements bst::IStopwatch.
References start().
|
inlineprotected |
Handles the timekeeping.
References clock_, elapsed_, bst::IStopwatch::RUNNING, start_, and state_.
Referenced by elapsedMicroseconds(), elapsedMicrosecondsF(), elapsedMilliseconds(), elapsedMillisecondsF(), elapsedSeconds(), and elapsedSecondsF().
|
private |
Referenced by getElapsed(), reset(), start(), and stop().
|
private |
Referenced by getElapsed(), reset(), start(), and stop().
|
private |
Referenced by stop().
|
private |
Referenced by getElapsed(), reset(), and stop().
|
private |
Referenced by getElapsed(), isRunning(), reset(), start(), and stop().