Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Timer Class Reference

Countdown helper tracking elapsed ratio and timeout state. More...

#include <spk_timer.hpp>

Collaboration diagram for spk::Timer:
Collaboration graph

Public Types

enum class  State { Idle , Running , Paused , TimedOut }
 Lifecycle state of the countdown.

Public Member Functions

 Timer (const Duration &p_expectedDuration)
 Builds a timer with the expected duration preconfigured.
 Timer ()
 Builds an idle timer with zero expected duration.
State state () const
 Reports the current timer state.
Duration elapsed () const
 Measures time accumulated since last start, excluding pauses.
Duration expectedDuration () const
 Returns the configured timeout duration.
float elapsedRatio () const
 Ratio of elapsed time over expected duration in [0,1] or above when overdue.
bool hasTimedOut () const
 Indicates whether the timer exceeded its expected duration.
void start ()
 Starts or restarts the timer from zero.
void stop ()
 Stops the timer and clears accumulated time.
void pause ()
 Suspends the timer without discarding elapsed time.
void resume ()
 Resumes counting after a pause.

Detailed Description

Countdown helper tracking elapsed ratio and timeout state.

spk::Timer timer{2.0_s};
timer.start();
if (timer.hasTimedOut())
{
// handle timeout
}
Countdown helper tracking elapsed ratio and timeout state.
Definition spk_timer.hpp:24
bool hasTimedOut() const
Indicates whether the timer exceeded its expected duration.
Definition spk_timer.cpp:48
void start()
Starts or restarts the timer from zero.
Definition spk_timer.cpp:54

Constructor & Destructor Documentation

◆ Timer()

spk::Timer::Timer ( const Duration & p_expectedDuration)
explicit

Builds a timer with the expected duration preconfigured.

Parameters
p_expectedDurationDuration required to reach timeout.
Here is the caller graph for this function:

Member Function Documentation

◆ elapsed()

Duration spk::Timer::elapsed ( ) const

Measures time accumulated since last start, excluding pauses.

Returns
Elapsed duration.
Here is the caller graph for this function:

◆ elapsedRatio()

float spk::Timer::elapsedRatio ( ) const

Ratio of elapsed time over expected duration in [0,1] or above when overdue.

Returns
Elapsed fraction as floating value.
Here is the call graph for this function:

◆ expectedDuration()

Duration spk::Timer::expectedDuration ( ) const

Returns the configured timeout duration.

Returns
Expected duration.

◆ hasTimedOut()

bool spk::Timer::hasTimedOut ( ) const

Indicates whether the timer exceeded its expected duration.

Returns
true when elapsed duration is greater or equal to expected duration.

◆ state()

Timer::State spk::Timer::state ( ) const

Reports the current timer state.

Returns
Current countdown lifecycle state.

The documentation for this class was generated from the following files:
  • includes/structure/system/time/spk_timer.hpp
  • srcs/structure/system/time/spk_timer.cpp