|
Time Shield Library 2.0.0
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 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 24 of file ElapsedTimer.hpp.
| using time_shield::ElapsedTimer::clock = std::chrono::steady_clock |
Definition at line 26 of file ElapsedTimer.hpp.
| using time_shield::ElapsedTimer::duration = clock::duration |
Definition at line 27 of file ElapsedTimer.hpp.
| using time_shield::ElapsedTimer::time_point = clock::time_point |
Definition at line 28 of file ElapsedTimer.hpp.
|
defaultnoexcept |
Constructs an invalid timer.
|
inlineexplicitnoexcept |
Constructs a timer that starts immediately when requested.
Definition at line 34 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed duration since the timer was started.
Definition at line 96 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed duration relative to the provided time point.
Definition at line 101 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed duration in the desired chrono duration type.
Definition at line 146 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed milliseconds since the timer was started.
Definition at line 121 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed milliseconds relative to the provided timestamp in milliseconds.
Definition at line 126 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed nanoseconds since the timer was started.
Definition at line 109 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed nanoseconds relative to the provided timestamp in nanoseconds.
Definition at line 114 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed seconds since the timer was started.
Definition at line 133 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns elapsed seconds relative to the provided timestamp in seconds.
Definition at line 138 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Checks if the given timeout in milliseconds has expired.
Definition at line 151 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Checks if the given timeout in seconds has expired.
Definition at line 162 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Invalidates the timer so subsequent elapsed() calls return zero.
Definition at line 76 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Checks whether the timer measures elapsed time.
Definition at line 81 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Alias for is_running() to match Qt naming conventions.
Definition at line 86 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns milliseconds since the internal clock reference.
Definition at line 173 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Restarts the timer and returns the elapsed duration so far.
Definition at line 47 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Restarts the timer using a millisecond timestamp and returns elapsed milliseconds.
Definition at line 56 of file ElapsedTimer.hpp.
Restarts the timer using a second timestamp and returns elapsed seconds.
Definition at line 66 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Starts the timer using the current steady clock time.
Definition at line 41 of file ElapsedTimer.hpp.
|
inlinenoexcept |
Returns start time stored by the timer.
Definition at line 91 of file ElapsedTimer.hpp.
|
private |
Definition at line 182 of file ElapsedTimer.hpp.
|
private |
Definition at line 181 of file ElapsedTimer.hpp.