MPD: PeriodClock Class Reference

MPD 0.20.15

Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions
PeriodClock Class Reference

This is a stopwatch which saves the timestamp of an event, and can check whether a specified time span has passed since then. More...

`#include <PeriodClock.hxx>`

## Public Types
typedef std::chrono::steady_clock::duration | Duration
typedef Duration | Delta
typedef std::chrono::steady_clock::time_point | Stamp

## Public Member Functions
constexpr | PeriodClock ()
| Initializes the object, setting the last time stamp to "0", i.e. More...
constexpr bool | IsDefined () const
void | Reset ()
| Resets the clock. More...
Delta | Elapsed () const
| Returns the time elapsed since the last update(). More...
Delta | ElapsedUpdate ()
| Combines a call to Elapsed() and Update(). More...
bool | Check (Duration duration) const
| Checks whether the specified duration has passed since the last update. More...
void | Update ()
| Updates the time stamp, setting it to the current clock. More...
void | UpdateWithOffset (Delta offset)
| Updates the time stamp, setting it to the current clock plus the specified offset. More...
bool | CheckUpdate (Duration duration)
| Checks whether the specified duration has passed since the last update. More...
bool | CheckAlwaysUpdate (Duration duration)
| Checks whether the specified duration has passed since the last update. More...

## Protected Member Functions
constexpr Delta | Elapsed (Stamp now) const
constexpr bool | Check (Stamp now, Duration duration) const
void | Update (Stamp now)

## Static Protected Member Functions
static Stamp | GetNow ()

## Detailed Description

This is a stopwatch which saves the timestamp of an event, and can check whether a specified time span has passed since then.

Definition at line 29 of file PeriodClock.hxx.

## Member Typedef Documentation

## ◆ Delta

typedef Duration PeriodClock::Delta

Definition at line 32 of file PeriodClock.hxx.

## ◆ Duration

typedef std::chrono::steady_clock::duration PeriodClock::Duration

Definition at line 31 of file PeriodClock.hxx.

## ◆ Stamp

typedef std::chrono::steady_clock::time_point PeriodClock::Stamp

Definition at line 33 of file PeriodClock.hxx.

## Constructor & Destructor Documentation

## ◆ PeriodClock()

constexpr PeriodClock::PeriodClock | ( |  | ) |
| inline

Initializes the object, setting the last time stamp to "0", i.e.

a Check() will always succeed. If you do not want this default behaviour, call Update() immediately after creating the object.

Definition at line 46 of file PeriodClock.hxx.

## Member Function Documentation

## ◆ Check() [1/2]

constexpr bool PeriodClock::Check | ( | Stamp | now,
|  | Duration | duration
| ) |  | const
| inlineprotected

Definition at line 59 of file PeriodClock.hxx.

## ◆ Check() [2/2]

bool PeriodClock::Check | ( | Duration | duration | ) | const
| inline

Checks whether the specified duration has passed since the last update.

Parameters

  duration | the duration

Definition at line 103 of file PeriodClock.hxx.

## ◆ CheckAlwaysUpdate()

bool PeriodClock::CheckAlwaysUpdate | ( | Duration | duration | ) |
| inline

Checks whether the specified duration has passed since the last update.

After that, it updates the time stamp.

Parameters

  duration | the duration in milliseconds

Definition at line 143 of file PeriodClock.hxx.

## ◆ CheckUpdate()

bool PeriodClock::CheckUpdate | ( | Duration | duration | ) |
| inline

Checks whether the specified duration has passed since the last update.

If yes, it updates the time stamp.

Parameters

  duration | the duration in milliseconds

Definition at line 128 of file PeriodClock.hxx.

## ◆ Elapsed() [1/2]

constexpr Delta PeriodClock::Elapsed | ( | Stamp | now | ) | const
| inlineprotected

Definition at line 53 of file PeriodClock.hxx.

## ◆ Elapsed() [2/2]

Delta PeriodClock::Elapsed | ( |  | ) | const
| inline

Returns the time elapsed since the last update().

Returns a negative value if update() was never called.

Definition at line 83 of file PeriodClock.hxx.

## ◆ ElapsedUpdate()

Delta PeriodClock::ElapsedUpdate | ( |  | ) |
| inline

Combines a call to Elapsed() and Update().

Definition at line 90 of file PeriodClock.hxx.

## ◆ GetNow()

static Stamp PeriodClock::GetNow | ( |  | ) |
| inlinestaticprotected

Definition at line 49 of file PeriodClock.hxx.

## ◆ IsDefined()

constexpr bool PeriodClock::IsDefined | ( |  | ) | const
| inline

Definition at line 68 of file PeriodClock.hxx.

## ◆ Reset()

void PeriodClock::Reset | ( |  | ) |
| inline

Resets the clock.

Definition at line 75 of file PeriodClock.hxx.

## ◆ Update() [1/2]

void PeriodClock::Update | ( | Stamp | now | ) |
| inlineprotected

Definition at line 63 of file PeriodClock.hxx.

## ◆ Update() [2/2]

void PeriodClock::Update | ( |  | ) |
| inline

Updates the time stamp, setting it to the current clock.

Definition at line 110 of file PeriodClock.hxx.

## ◆ UpdateWithOffset()

void PeriodClock::UpdateWithOffset | ( | Delta | offset | ) |
| inline

Updates the time stamp, setting it to the current clock plus the specified offset.

Definition at line 118 of file PeriodClock.hxx.

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

- system/PeriodClock.hxx