Avara3D 0.2.0
C++ API reference
a3d::util::PeriodicTrigger Class Reference

Invokes a callback at fixed intervals along a caller-supplied time line. More...

#include <a3d/util/PeriodicTrigger.h>

Public Member Functions

 PeriodicTrigger (std::chrono::duration< double > interval, bool deferFirstFire=false)
 Creates a trigger with interval between firings. More...
 
template<typename Function >
std::size_t update (double time, Function &&function)
 Advances the trigger to time and invokes function once for each due firing. More...
 
void reset () noexcept
 Clears timing history so the next update establishes a new schedule. More...
 

Detailed Description

Invokes a callback at fixed intervals along a caller-supplied time line.

update() catches up missed intervals by invoking the callback once for every elapsed trigger time. Supplying a time earlier than the previous update resets the schedule automatically.

Definition at line 26 of file PeriodicTrigger.h.

Constructor & Destructor Documentation

◆ PeriodicTrigger()

a3d::util::PeriodicTrigger::PeriodicTrigger ( std::chrono::duration< double >  interval,
bool  deferFirstFire = false 
)
explicit

Creates a trigger with interval between firings.

By default, the first update fires immediately. When deferFirstFire is true, the first firing is scheduled one interval after the first update time.

Exceptions
std::invalid_argumentif interval is less than or equal to zero.

Member Function Documentation

◆ reset()

void a3d::util::PeriodicTrigger::reset ( )
noexcept

Clears timing history so the next update establishes a new schedule.

◆ update()

template<typename Function >
std::size_t a3d::util::PeriodicTrigger::update ( double  time,
Function &&  function 
)
inline

Advances the trigger to time and invokes function once for each due firing.

Parameters
timeCurrent caller-defined time in seconds.
functionCallable invoked for every due interval.
Returns
Number of callback invocations due at this update.

Definition at line 51 of file PeriodicTrigger.h.


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