Devel Lib
Devel::CTimer Class Reference

A high-precision timer class. More...

#include <Timer.h>

Public Member Functions

 CTimer (const bool i_fAutoStart=false)
 Constructor. More...
 
 ~CTimer ()=default
 Default destructor.
 
void start ()
 Starts or restarts the timer.
 
void restart ()
 Restarts the timer.
 
bool hasExpired (const uint64 i_nTimeMs) const
 Checks if a certain amount of time has passed since the timer was started. More...
 
bool isStarted () const
 Checks if the timer is running. More...
 
uint64 elapsed () const
 Gets the elapsed time since the timer was started. More...
 
void clear ()
 Resets the timer. The timer is stopped and the elapsed time is set to zero.
 
void reset ()
 Resets the timer. The timer is stopped and the elapsed time is set to zero.
 

Detailed Description

A high-precision timer class.

This class can be used for timekeeping, measuring the elapsed time, checking if a given time duration has expired, etc.

Example

This is an example on how to use the CTimer class.

// Create a CTimer instance and auto start the timer
Devel::CTimer timer(true);
// Do some time-consuming operations
// ...
// Check if a certain time period has expired
if (timer.hasExpired(1000)) { // Check if 1000 milliseconds have passed
// Time period has expired, perform an action
// ...
} else {
// Time period has not expired, do nothing or do something else
// ...
}
// You can also manually start/restart the timer
timer.start();
// Or check if the timer has started
bool isStarted = timer.isStarted();
// Or reset/clear the timer
timer.reset();
A high-precision timer class.
Definition: Timer.h:43
bool isStarted() const
Checks if the timer is running.
Definition: Timer.h:74

Constructor & Destructor Documentation

◆ CTimer()

Devel::CTimer::CTimer ( const bool  i_fAutoStart = false)
inlineexplicit

Constructor.

Parameters
i_fAutoStartIf true, the timer starts automatically upon construction.

Member Function Documentation

◆ elapsed()

uint64 Devel::CTimer::elapsed ( ) const

Gets the elapsed time since the timer was started.

Returns
The elapsed time (in milliseconds).

◆ hasExpired()

bool Devel::CTimer::hasExpired ( const uint64  i_nTimeMs) const
inline

Checks if a certain amount of time has passed since the timer was started.

Parameters
i_nTimeMsThe amount of time (in milliseconds) to check for.
Returns
True if the elapsed time is equal to or greater than i_nTimeMs.

◆ isStarted()

bool Devel::CTimer::isStarted ( ) const
inline

Checks if the timer is running.

Returns
True if the timer is started.

The documentation for this class was generated from the following files: