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

A simple timer class for timing events. More...

#include <timer.hpp>

Inheritance diagram for bst::Timer:
Collaboration diagram for bst::Timer:

Public Member Functions

 Timer ()
 Create a new timer with a timeout of 0. Must call setTimeout before using. More...
 
 Timer (int timeout_ms)
 Create a new timer with a timeout. More...
 
bool isDone () const override
 Check if the timer has expired. More...
 
void reset () override
 Reset the timer to the current time. More...
 
void setDone () override
 Set the timer to be done. Changes the start time. More...
 
void setTimeout (int timeout_ms) override
 Set the timeout of the timer. More...
 

Private Attributes

bst::clck::TimePoint start_ = bst::clck::Clock::now()
 
int timeout_ms_
 

Detailed Description

A simple timer class for timing events.

Constructor & Destructor Documentation

◆ Timer() [1/2]

bst::Timer::Timer ( int  timeout_ms)

Create a new timer with a timeout.

Parameters
timeout_msThe timeout in milliseconds

◆ Timer() [2/2]

bst::Timer::Timer ( )

Create a new timer with a timeout of 0. Must call setTimeout before using.

Member Function Documentation

◆ reset()

void bst::Timer::reset ( )
overridevirtual

Reset the timer to the current time.

Implements bst::ITimer.

References bst::clck::now(), and start_.

Referenced by main(), and TEST().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDone()

bool bst::Timer::isDone ( ) const
overridevirtual

Check if the timer has expired.

Returns
true if the timer has expired, false otherwise

Implements bst::ITimer.

References bst::clck::now(), start_, and timeout_ms_.

Referenced by main(), and TEST().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTimeout()

void bst::Timer::setTimeout ( int  timeout_ms)
overridevirtual

Set the timeout of the timer.

Parameters
timeout_msThe timeout in milliseconds

Implements bst::ITimer.

References timeout_ms_.

Referenced by TEST().

Here is the caller graph for this function:

◆ setDone()

void bst::Timer::setDone ( )
overridevirtual

Set the timer to be done. Changes the start time.

Implements bst::ITimer.

References bst::clck::now(), start_, and timeout_ms_.

Here is the call graph for this function:

Member Data Documentation

◆ start_

bst::clck::TimePoint bst::Timer::start_ = bst::clck::Clock::now()
private

Referenced by isDone(), reset(), and setDone().

◆ timeout_ms_

int bst::Timer::timeout_ms_
private

Referenced by isDone(), setDone(), and setTimeout().