BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
bst::SoftwareStopwatch Class Reference

A manually controlled stopwatch that does not use the system clock. More...

#include <stopwatch.hpp>

Inheritance diagram for bst::SoftwareStopwatch:
Collaboration diagram for bst::SoftwareStopwatch:

Public Member Functions

 SoftwareStopwatch ()=default
 
 ~SoftwareStopwatch ()=default
 
int64_t elapsedMicroseconds () const
 
double elapsedMicrosecondsF () const
 
int64_t elapsedMilliseconds () const
 
double elapsedMillisecondsF () const
 
int64_t elapsedSeconds () const
 
double elapsedSecondsF () const
 
bool isRunning () const
 
void pause ()
 
void reset (bool stop=true)
 
void resume ()
 
void start ()
 
void stop ()
 
void tick (int64_t microseconds)
 
void tickIfRunning (int64_t microseconds)
 

Protected Types

enum class  State { RUNNING , STOPPED }
 The state of the stopwatch. More...
 

Protected Member Functions

int64_t getElapsed () const
 

Private Attributes

int64_t elapsed_ = 0
 
int64_t start_ = 0
 
State state_ = State::STOPPED
 
int64_t stop_time_ = 0
 

Detailed Description

A manually controlled stopwatch that does not use the system clock.

Member Enumeration Documentation

◆ State

enum bst::IStopwatch::State
strongprotectedinherited

The state of the stopwatch.

Enumerator
RUNNING 
STOPPED 

Constructor & Destructor Documentation

◆ SoftwareStopwatch()

bst::SoftwareStopwatch::SoftwareStopwatch ( )
default

◆ ~SoftwareStopwatch()

bst::SoftwareStopwatch::~SoftwareStopwatch ( )
default

Member Function Documentation

◆ start()

void bst::SoftwareStopwatch::start ( )
inlinevirtual

Implements bst::IStopwatch.

References bst::IStopwatch::RUNNING, start_, state_, and bst::IStopwatch::STOPPED.

Referenced by resume().

Here is the caller graph for this function:

◆ stop()

void bst::SoftwareStopwatch::stop ( )
inlinevirtual

Implements bst::IStopwatch.

References elapsed_, bst::IStopwatch::RUNNING, start_, state_, stop_time_, and bst::IStopwatch::STOPPED.

Referenced by pause(), and reset().

Here is the caller graph for this function:

◆ reset()

void bst::SoftwareStopwatch::reset ( bool  stop = true)
inlinevirtual

Implements bst::IStopwatch.

References elapsed_, state_, stop(), and bst::IStopwatch::STOPPED.

Here is the call graph for this function:

◆ isRunning()

bool bst::SoftwareStopwatch::isRunning ( ) const
inlinevirtual

Implements bst::IStopwatch.

References bst::IStopwatch::RUNNING, and state_.

◆ elapsedMicroseconds()

int64_t bst::SoftwareStopwatch::elapsedMicroseconds ( ) const
inlinevirtual

Implements bst::IStopwatch.

References elapsed_.

◆ elapsedMicrosecondsF()

double bst::SoftwareStopwatch::elapsedMicrosecondsF ( ) const
inlinevirtual

Implements bst::IStopwatch.

References elapsed_.

◆ elapsedMilliseconds()

int64_t bst::SoftwareStopwatch::elapsedMilliseconds ( ) const
inlinevirtual

Implements bst::IStopwatch.

References elapsed_.

◆ elapsedMillisecondsF()

double bst::SoftwareStopwatch::elapsedMillisecondsF ( ) const
inlinevirtual

Implements bst::IStopwatch.

References elapsed_.

◆ elapsedSeconds()

int64_t bst::SoftwareStopwatch::elapsedSeconds ( ) const
inlinevirtual

Implements bst::IStopwatch.

References elapsed_.

◆ elapsedSecondsF()

double bst::SoftwareStopwatch::elapsedSecondsF ( ) const
inlinevirtual

Implements bst::IStopwatch.

References elapsed_.

◆ pause()

void bst::SoftwareStopwatch::pause ( )
inlinevirtual

Implements bst::IStopwatch.

References stop().

Here is the call graph for this function:

◆ resume()

void bst::SoftwareStopwatch::resume ( )
inlinevirtual

Implements bst::IStopwatch.

References start().

Here is the call graph for this function:

◆ tickIfRunning()

void bst::SoftwareStopwatch::tickIfRunning ( int64_t  microseconds)
inline

◆ tick()

void bst::SoftwareStopwatch::tick ( int64_t  microseconds)
inline

References elapsed_.

Referenced by TEST().

Here is the caller graph for this function:

◆ getElapsed()

int64_t bst::SoftwareStopwatch::getElapsed ( ) const
inlineprotected

Member Data Documentation

◆ start_

int64_t bst::SoftwareStopwatch::start_ = 0
private

Referenced by getElapsed(), start(), and stop().

◆ stop_time_

int64_t bst::SoftwareStopwatch::stop_time_ = 0
private

Referenced by getElapsed(), and stop().

◆ elapsed_

◆ state_

State bst::SoftwareStopwatch::state_ = State::STOPPED
private