SPH
Public Member Functions | Protected Types | Protected Attributes | List of all members
Timer Class Reference

Basic time-measuring tool. Starts automatically when constructed. More...

#include <Timer.h>

Inheritance diagram for Timer:
StoppableTimer

Public Member Functions

 Timer (const int64_t interval=0, const Flags< TimerFlags > flags=EMPTY_FLAGS)
 Creates timer with given expiration duration. More...
 
void restart ()
 Reset elapsed duration to zero. More...
 
int64_t elapsed (const TimerUnit unit) const
 Returns elapsed time in timer units. Does not reset the timer. More...
 
bool isExpired () const
 Checks if the interval has already passed. More...
 
bool isPeriodic () const
 

Protected Types

using Clock = std::chrono::system_clock
 
using TimePoint = std::chrono::time_point< Clock >
 

Protected Attributes

TimePoint started
 
int64_t interval
 
Flags< TimerFlagsflags
 

Detailed Description

Basic time-measuring tool. Starts automatically when constructed.

Definition at line 27 of file Timer.h.

Member Typedef Documentation

◆ Clock

using Timer::Clock = std::chrono::system_clock
protected

Definition at line 29 of file Timer.h.

◆ TimePoint

using Timer::TimePoint = std::chrono::time_point<Clock>
protected

Definition at line 30 of file Timer.h.

Constructor & Destructor Documentation

◆ Timer()

Timer::Timer ( const int64_t  interval = 0,
const Flags< TimerFlags flags = EMPTY_FLAGS 
)

Creates timer with given expiration duration.

Flag TimerFlags::PERIODIC does not do anything in this case, user must check for expiration and possibly restart timer, this isn't provided by timer constructed this way.

Parameters
intervalTimer interval in milliseconds. It isn't currently possible to create interval in different units.
flagsOptional parameters of the timer, see TimerFlags.

Definition at line 40 of file Timer.cpp.

Member Function Documentation

◆ elapsed()

int64_t Timer::elapsed ( const TimerUnit  unit) const

Returns elapsed time in timer units. Does not reset the timer.

Definition at line 55 of file Timer.cpp.

◆ isExpired()

bool Timer::isExpired ( ) const
inline

Checks if the interval has already passed.

Definition at line 53 of file Timer.h.

◆ isPeriodic()

bool Timer::isPeriodic ( ) const
inline

Definition at line 57 of file Timer.h.

◆ restart()

void Timer::restart ( )

Reset elapsed duration to zero.

Definition at line 51 of file Timer.cpp.

Member Data Documentation

◆ flags

Flags<TimerFlags> Timer::flags
protected

Definition at line 34 of file Timer.h.

◆ interval

int64_t Timer::interval
protected

Definition at line 33 of file Timer.h.

◆ started

TimePoint Timer::started
protected

Definition at line 32 of file Timer.h.


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