Time Shield Library
C++ library for working with time
|
Helper that measures elapsed monotonic time spans. More...
#include <ElapsedTimer.hpp>
Public Types | |
using | clock = std::chrono::steady_clock |
using | duration = clock::duration |
using | time_point = clock::time_point |
Public Member Functions | |
ElapsedTimer () noexcept=default | |
Constructs an invalid timer. | |
ElapsedTimer (bool start_immediately) noexcept | |
Constructs a timer that starts immediately when requested. | |
void | start () noexcept |
Starts the timer using the current steady clock time. | |
TIME_SHIELD_NODISCARD duration | restart () noexcept |
Restarts the timer and returns the elapsed duration so far. | |
TIME_SHIELD_NODISCARD ts_ms_t | restart_ms (ts_ms_t now_ms) noexcept |
Restarts the timer using a millisecond timestamp and returns elapsed milliseconds. | |
TIME_SHIELD_NODISCARD ts_t | restart_sec (ts_t now_sec) noexcept |
Restarts the timer using a second timestamp and returns elapsed seconds. | |
void | invalidate () noexcept |
Invalidates the timer so subsequent elapsed() calls return zero. | |
TIME_SHIELD_NODISCARD bool | is_running () const noexcept |
Checks whether the timer currently measures elapsed time. | |
TIME_SHIELD_NODISCARD bool | is_valid () const noexcept |
Alias for is_running() to match Qt naming conventions. | |
TIME_SHIELD_NODISCARD time_point | start_time () const noexcept |
Returns start time stored by the timer. | |
TIME_SHIELD_NODISCARD duration | elapsed () const noexcept |
Returns elapsed duration since the timer was started. | |
TIME_SHIELD_NODISCARD duration | elapsed (time_point now) const noexcept |
Returns elapsed duration relative to the provided time point. | |
TIME_SHIELD_NODISCARD std::int64_t | elapsed_ns () const noexcept |
Returns elapsed nanoseconds since the timer was started. | |
TIME_SHIELD_NODISCARD std::int64_t | elapsed_ns (std::int64_t now_ns) const noexcept |
Returns elapsed nanoseconds relative to the provided timestamp in nanoseconds. | |
TIME_SHIELD_NODISCARD ts_ms_t | elapsed_ms () const noexcept |
Returns elapsed milliseconds since the timer was started. | |
TIME_SHIELD_NODISCARD ts_ms_t | elapsed_ms (ts_ms_t now_ms) const noexcept |
Returns elapsed milliseconds relative to the provided timestamp in milliseconds. | |
TIME_SHIELD_NODISCARD ts_t | elapsed_sec () const noexcept |
Returns elapsed seconds since the timer was started. | |
TIME_SHIELD_NODISCARD ts_t | elapsed_sec (ts_t now_sec) const noexcept |
Returns elapsed seconds relative to the provided timestamp in seconds. | |
template<class Duration> | |
TIME_SHIELD_NODISCARD Duration::rep | elapsed_count () const noexcept |
Returns elapsed duration in the desired chrono duration type. | |
TIME_SHIELD_NODISCARD bool | has_expired (ts_ms_t timeout_ms) const noexcept |
Checks if the given timeout in milliseconds has expired. | |
TIME_SHIELD_NODISCARD bool | has_expired_sec (ts_t timeout_sec) const noexcept |
Checks if the given timeout in seconds has expired. | |
TIME_SHIELD_NODISCARD std::int64_t | ms_since_reference () const noexcept |
Returns milliseconds since the internal clock reference. | |
Private Attributes | |
time_point | m_start_time {} |
bool | m_is_running {false} |
Helper that measures elapsed monotonic time spans.
Instances are expected to be used from a single thread without additional synchronization.
Definition at line 25 of file ElapsedTimer.hpp.
using time_shield::ElapsedTimer::clock = std::chrono::steady_clock |
Definition at line 27 of file ElapsedTimer.hpp.
using time_shield::ElapsedTimer::duration = clock::duration |
Definition at line 28 of file ElapsedTimer.hpp.
using time_shield::ElapsedTimer::time_point = clock::time_point |
Definition at line 29 of file ElapsedTimer.hpp.
|
defaultnoexcept |
Constructs an invalid timer.
|
inlineexplicitnoexcept |
Constructs a timer that starts immediately when requested.
Definition at line 35 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed duration since the timer was started.
Definition at line 97 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed duration relative to the provided time point.
Definition at line 102 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed duration in the desired chrono duration type.
Definition at line 147 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed milliseconds since the timer was started.
Definition at line 122 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed milliseconds relative to the provided timestamp in milliseconds.
Definition at line 127 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed nanoseconds since the timer was started.
Definition at line 110 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed nanoseconds relative to the provided timestamp in nanoseconds.
Definition at line 115 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed seconds since the timer was started.
Definition at line 134 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed seconds relative to the provided timestamp in seconds.
Definition at line 139 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Checks if the given timeout in milliseconds has expired.
Definition at line 152 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Checks if the given timeout in seconds has expired.
Definition at line 163 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Invalidates the timer so subsequent elapsed() calls return zero.
Definition at line 77 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Checks whether the timer currently measures elapsed time.
Definition at line 82 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Alias for is_running() to match Qt naming conventions.
Definition at line 87 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns milliseconds since the internal clock reference.
Definition at line 174 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Restarts the timer and returns the elapsed duration so far.
Definition at line 48 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Restarts the timer using a millisecond timestamp and returns elapsed milliseconds.
Definition at line 57 of file ElapsedTimer.hpp.
Restarts the timer using a second timestamp and returns elapsed seconds.
Definition at line 67 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Starts the timer using the current steady clock time.
Definition at line 42 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns start time stored by the timer.
Definition at line 92 of file ElapsedTimer.hpp.
|
private |
Definition at line 183 of file ElapsedTimer.hpp.
|
private |
Definition at line 182 of file ElapsedTimer.hpp.