Time Shield Library
C++ library for working with time
|
Timer that mimics the behavior of Qt timers. More...
#include <TimerScheduler.hpp>
Public Types | |
using | Callback = detail::TimerCallback |
Public Member Functions | |
Timer (TimerScheduler &scheduler) | |
~Timer () | |
Timer (const Timer &)=delete | |
Timer & | operator= (const Timer &)=delete |
Timer (Timer &&)=delete | |
Timer & | operator= (Timer &&)=delete |
template<class Rep, class Period> | |
void | set_interval (std::chrono::duration< Rep, Period > interval) noexcept |
Sets the interval used by the timer. | |
std::chrono::milliseconds | interval () const noexcept |
Returns the currently configured interval. | |
void | start () |
Starts the timer using the previously configured interval. | |
template<class Rep, class Period> | |
void | start (std::chrono::duration< Rep, Period > interval) |
Starts the timer with the specified interval. | |
void | stop () |
Stops the timer. | |
void | stop_and_wait () |
Stops the timer and waits until an active callback finishes. | |
void | set_single_shot (bool is_single_shot) noexcept |
Sets whether the timer should fire only once. | |
bool | is_single_shot () const noexcept |
Returns true if the timer fires only once. | |
bool | is_active () const noexcept |
Returns true if the timer is active. | |
bool | is_running () const noexcept |
Returns true if the timer callback is being executed. | |
void | set_callback (Callback callback) |
Sets the callback that should be invoked when the timer fires. | |
Static Public Member Functions | |
template<class Rep, class Period> | |
static void | single_shot (TimerScheduler &scheduler, std::chrono::duration< Rep, Period > interval, Callback callback) |
Creates a single-shot timer that invokes the callback once. | |
Private Attributes | |
TimerScheduler & | m_scheduler |
timer_state_ptr | m_state |
Timer that mimics the behavior of Qt timers.
Definition at line 176 of file TimerScheduler.hpp.
Definition at line 178 of file TimerScheduler.hpp.
|
inlineexplicit |
Definition at line 518 of file TimerScheduler.hpp.
|
inline |
Definition at line 525 of file TimerScheduler.hpp.
|
delete |
|
delete |
|
inlinenoexcept |
Returns the currently configured interval.
Definition at line 549 of file TimerScheduler.hpp.
|
inlinenoexcept |
Returns true if the timer is active.
Definition at line 587 of file TimerScheduler.hpp.
|
inlinenoexcept |
Returns true if the timer callback is being executed.
Definition at line 591 of file TimerScheduler.hpp.
|
inlinenoexcept |
Returns true if the timer fires only once.
Definition at line 583 of file TimerScheduler.hpp.
|
inline |
Sets the callback that should be invoked when the timer fires.
Definition at line 595 of file TimerScheduler.hpp.
|
noexcept |
Sets the interval used by the timer.
Negative durations are clamped to zero. An interval of zero means the timer is rescheduled immediately after firing.
Definition at line 541 of file TimerScheduler.hpp.
|
inlinenoexcept |
Sets whether the timer should fire only once.
Definition at line 579 of file TimerScheduler.hpp.
|
static |
Creates a single-shot timer that invokes the callback once.
The helper keeps the timer alive until the callback finishes.
Definition at line 601 of file TimerScheduler.hpp.
|
inline |
Starts the timer using the previously configured interval.
Definition at line 554 of file TimerScheduler.hpp.
void time_shield::Timer::start | ( | std::chrono::duration< Rep, Period > | interval | ) |
Starts the timer with the specified interval.
Definition at line 561 of file TimerScheduler.hpp.
|
inline |
Stops the timer.
The operation is non-blocking: the method does not wait for a running callback to finish. Use stop_and_wait() to synchronously wait for completion.
Definition at line 566 of file TimerScheduler.hpp.
|
inline |
Stops the timer and waits until an active callback finishes.
Must not be called from inside the timer callback itself.
Definition at line 570 of file TimerScheduler.hpp.
|
private |
Definition at line 241 of file TimerScheduler.hpp.
|
private |
Definition at line 242 of file TimerScheduler.hpp.