|
Time Shield Library 2.0.0
C++ library for working with time
|
Helper that models a monotonic deadline for timeout management. More...
#include <DeadlineTimer.hpp>
Public Types | |
| using | clock = std::chrono::steady_clock |
| using | duration = clock::duration |
| using | time_point = clock::time_point |
Public Member Functions | |
| DeadlineTimer () noexcept=default | |
| Constructs an inactive timer. | |
| DeadlineTimer (time_point deadline) noexcept | |
| Constructs a timer with the specified absolute deadline. | |
| template<class Rep , class Period > | |
| DeadlineTimer (std::chrono::duration< Rep, Period > timeout) noexcept | |
| Constructs a timer that expires after the given timeout. | |
| DeadlineTimer (ts_ms_t timeout_ms) noexcept | |
| Constructs a timer that expires after the given number of milliseconds. | |
| void | start (time_point deadline) noexcept |
| Sets the absolute deadline and marks the timer as active. | |
| template<class Rep , class Period > | |
| void | start (std::chrono::duration< Rep, Period > timeout) noexcept |
| Starts the timer so it expires after the specified timeout. | |
| void | start_sec (ts_t timeout_sec) noexcept |
| Starts the timer so it expires after the specified number of seconds. | |
| void | start_ms (ts_ms_t timeout_ms) noexcept |
| Starts the timer so it expires after the specified number of milliseconds. | |
| void | stop () noexcept |
| Stops the timer and invalidates the stored deadline. | |
| void | set_forever () noexcept |
| Marks the timer as running forever (no timeout). | |
| TIME_SHIELD_NODISCARD bool | is_running () const noexcept |
| Checks whether the timer tracks a deadline. | |
| TIME_SHIELD_NODISCARD bool | is_forever () const noexcept |
| Checks whether the timer is configured for an infinite timeout. | |
| TIME_SHIELD_NODISCARD time_point | deadline () const noexcept |
| Returns stored deadline. | |
| TIME_SHIELD_NODISCARD ts_ms_t | deadline_ms () const noexcept |
| Returns stored deadline as milliseconds since the steady epoch. | |
| TIME_SHIELD_NODISCARD ts_t | deadline_sec () const noexcept |
| Returns stored deadline as seconds since the steady epoch. | |
| TIME_SHIELD_NODISCARD bool | has_expired () const noexcept |
| Checks if the deadline has already expired. | |
| TIME_SHIELD_NODISCARD bool | has_expired_ms (ts_ms_t now_ms) const noexcept |
| Checks if the deadline has expired relative to the provided millisecond timestamp. | |
| TIME_SHIELD_NODISCARD bool | has_expired_sec (ts_t now_sec) const noexcept |
| Checks if the deadline has expired relative to the provided second timestamp. | |
| TIME_SHIELD_NODISCARD bool | has_expired (time_point now) const noexcept |
| Checks if the deadline has expired relative to the provided time point. | |
| TIME_SHIELD_NODISCARD duration | remaining_time () const noexcept |
| Returns time remaining until the deadline. | |
| TIME_SHIELD_NODISCARD ts_ms_t | remaining_time_ms () const noexcept |
| Returns remaining time in milliseconds until the deadline. | |
| TIME_SHIELD_NODISCARD ts_t | remaining_time_sec () const noexcept |
| Returns remaining time in seconds until the deadline. | |
| TIME_SHIELD_NODISCARD duration | remaining_time (time_point now) const noexcept |
| Returns remaining time relative to the provided time point. | |
| void | add (duration extend_by) noexcept |
| Extends deadline by the specified duration while preventing overflow. | |
| void | add_sec (ts_t extend_by_sec) noexcept |
| Extends deadline by the specified number of seconds while preventing overflow. | |
| void | add_ms (ts_ms_t extend_by_ms) noexcept |
| Extends deadline by the specified number of milliseconds while preventing overflow. | |
Static Public Member Functions | |
| static DeadlineTimer | from_timeout (duration timeout) noexcept |
| Creates a timer that expires after the specified timeout. | |
| template<class Rep , class Period > | |
| static DeadlineTimer | from_timeout (std::chrono::duration< Rep, Period > timeout) noexcept |
| Creates a timer that expires after the specified timeout. | |
| static DeadlineTimer | from_timeout_sec (ts_t timeout_sec) noexcept |
| Creates a timer that expires after the specified number of seconds. | |
| static DeadlineTimer | from_timeout_ms (ts_ms_t timeout_ms) noexcept |
| Creates a timer that expires after the specified number of milliseconds. | |
Private Attributes | |
| time_point | m_deadline {} |
| bool | m_is_running {false} |
Helper that models a monotonic deadline for timeout management.
DeadlineTimer invariants:
start(timeout <= 0) marks the deadline as already due.set_forever() to represent "no timeout" semantics. Definition at line 25 of file DeadlineTimer.hpp.
| using time_shield::DeadlineTimer::clock = std::chrono::steady_clock |
Definition at line 27 of file DeadlineTimer.hpp.
| using time_shield::DeadlineTimer::duration = clock::duration |
Definition at line 28 of file DeadlineTimer.hpp.
| using time_shield::DeadlineTimer::time_point = clock::time_point |
Definition at line 29 of file DeadlineTimer.hpp.
|
defaultnoexcept |
Constructs an inactive timer.
|
inlineexplicitnoexcept |
Constructs a timer with the specified absolute deadline.
Definition at line 35 of file DeadlineTimer.hpp.
|
inlineexplicitnoexcept |
Constructs a timer that expires after the given timeout.
Definition at line 41 of file DeadlineTimer.hpp.
|
inlineexplicitnoexcept |
Constructs a timer that expires after the given number of milliseconds.
Definition at line 46 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Extends deadline by the specified duration while preventing overflow.
Definition at line 208 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Extends deadline by the specified number of milliseconds while preventing overflow.
Definition at line 229 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Extends deadline by the specified number of seconds while preventing overflow.
Definition at line 221 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Returns stored deadline.
Definition at line 146 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Returns stored deadline as milliseconds since the steady epoch.
Definition at line 151 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Returns stored deadline as seconds since the steady epoch.
Definition at line 156 of file DeadlineTimer.hpp.
|
inlinestaticnoexcept |
Creates a timer that expires after the specified timeout.
Definition at line 51 of file DeadlineTimer.hpp.
|
inlinestaticnoexcept |
Creates a timer that expires after the specified timeout.
Definition at line 59 of file DeadlineTimer.hpp.
|
inlinestaticnoexcept |
Creates a timer that expires after the specified number of milliseconds.
Definition at line 73 of file DeadlineTimer.hpp.
|
inlinestaticnoexcept |
Creates a timer that expires after the specified number of seconds.
Definition at line 66 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Checks if the deadline has already expired.
Definition at line 161 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Checks if the deadline has expired relative to the provided time point.
Definition at line 178 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Checks if the deadline has expired relative to the provided millisecond timestamp.
Definition at line 166 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Checks if the deadline has expired relative to the provided second timestamp.
Definition at line 172 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Checks whether the timer is configured for an infinite timeout.
Definition at line 141 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Checks whether the timer tracks a deadline.
Definition at line 136 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Returns time remaining until the deadline.
Definition at line 183 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Returns remaining time relative to the provided time point.
Non-running timers and already expired timers report zero duration.
Definition at line 200 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Returns remaining time in milliseconds until the deadline.
Definition at line 188 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Returns remaining time in seconds until the deadline.
Definition at line 193 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Marks the timer as running forever (no timeout).
Definition at line 130 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Starts the timer so it expires after the specified timeout.
Negative durations result in an immediate expiration. Durations that are shorter than the steady clock tick are rounded up to a single tick to preserve the monotonic nature of the timer.
Definition at line 91 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Sets the absolute deadline and marks the timer as active.
Definition at line 80 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Starts the timer so it expires after the specified number of milliseconds.
Definition at line 119 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Starts the timer so it expires after the specified number of seconds.
Definition at line 114 of file DeadlineTimer.hpp.
|
inlinenoexcept |
Stops the timer and invalidates the stored deadline.
Definition at line 124 of file DeadlineTimer.hpp.
|
private |
Definition at line 237 of file DeadlineTimer.hpp.
|
private |
Definition at line 238 of file DeadlineTimer.hpp.