BasicTimer Class Reference

CPP API: mio::timing::BasicTimer Class Reference

A minimal timer class. More...

#include <basic_timer.h>

Inheritance diagram for mio::timing::BasicTimer:

Public Member Functions

DurationType get_elapsed_time () const
 Get the total time spent between starts and stops. Only call while the timer is stopped. More...
 
void reset ()
 Set the elapsed time to 0. Only call while the timer is stopped. More...
 
template<class IOContext >
void serialize (IOContext &io) const
 serialize this. More...
 
void start ()
 Start the timer. Must be followed by exactly one stop. More...
 
void stop ()
 Stop the timer and update the elapsed time. After calling stop, the timer may be started again. More...
 
 ~BasicTimer ()
 

Static Public Member Functions

template<class IOContext >
static IOResult< BasicTimerdeserialize (IOContext &io)
 deserialize an object of this class. More...
 

Private Member Functions

void set_running (bool new_state)
 In Debug builds, set whether the timer is running or not. More...
 
void should_be_running (bool expected, const std::string_view function) const
 In Debug builds, check that the state of m_is_running is as expected. Log an error if not. More...
 

Private Attributes

DurationType m_elapsed_time {0}
 The total time spent between starts and stops. More...
 
bool m_is_running = false
 In Debug builds, tracks whether the timer is running. More...
 
TimeType m_start_time
 The last time point at which start() was called. More...
 

Detailed Description

A minimal timer class.

Constructor & Destructor Documentation

◆ ~BasicTimer()

mio::timing::BasicTimer::~BasicTimer ( )
inline

Member Function Documentation

◆ deserialize()

template<class IOContext >
static IOResult<BasicTimer> mio::timing::BasicTimer::deserialize ( IOContext &  io)
inlinestatic

deserialize an object of this class.

See also
mio::deserialize

◆ get_elapsed_time()

DurationType mio::timing::BasicTimer::get_elapsed_time ( ) const
inline

Get the total time spent between starts and stops. Only call while the timer is stopped.

◆ reset()

void mio::timing::BasicTimer::reset ( )
inline

Set the elapsed time to 0. Only call while the timer is stopped.

◆ serialize()

template<class IOContext >
void mio::timing::BasicTimer::serialize ( IOContext &  io) const
inline

serialize this.

See also
mio::serialize

◆ set_running()

void mio::timing::BasicTimer::set_running ( bool  new_state)
private

In Debug builds, set whether the timer is running or not.

◆ should_be_running()

void mio::timing::BasicTimer::should_be_running ( bool  expected,
const std::string_view  function 
) const
private

In Debug builds, check that the state of m_is_running is as expected. Log an error if not.

◆ start()

void mio::timing::BasicTimer::start ( )
inline

Start the timer. Must be followed by exactly one stop.

◆ stop()

void mio::timing::BasicTimer::stop ( )
inline

Stop the timer and update the elapsed time. After calling stop, the timer may be started again.

Member Data Documentation

◆ m_elapsed_time

DurationType mio::timing::BasicTimer::m_elapsed_time {0}
private

The total time spent between starts and stops.

◆ m_is_running

bool mio::timing::BasicTimer::m_is_running = false
private

In Debug builds, tracks whether the timer is running.

◆ m_start_time

TimeType mio::timing::BasicTimer::m_start_time
private

The last time point at which start() was called.