⏱️ golxzn::os::chrono ⏱️ 1.2.4
Chrono for golxzn's projects.
|
Class that represents timer. More...
#include <timer.hpp>
Public Member Functions | |
template<class Rep , class Period > | |
timer (const std::chrono::duration< Rep, Period > timer_interval, timer_end_callback &&callback) | |
Timer constructor from timer interval and callback. | |
timer (const time timer_interval, timer_end_callback &&callback) | |
Timer constructor from timer interval and callback. | |
void | update () |
Updates timer. (only when GOLXZN_MULTITHREADING is not defined) | |
bool | is_done () const noexcept |
Returns true if timer is done. | |
bool | is_running () const noexcept |
Returns true if timer is running. | |
time | time_left () const noexcept |
Returns time left to the end of the timer. | |
Class that represents timer.
GOLXZN_MULTITHREADING
macros definition. OnTimerDone | type of function that will be called when timer is done. |
BaseClock | clock that will be used for measurement. It has to be monotonic and STL compatible. |
This class is used to measure time. It calls callback when it's done. If GOLXZN_MULTITHREADING
is not defined it doesn't use a thread. So to call callback it has to be updated in main thread. It storing callback. If GOLXZN_MULTITHREADING
is defined it uses a thread. So to call callback it doesn't have to be updated. It doesn't storing callback, but std::thread
Example of using:
golxzn::os::chrono::timer< OnTimerDone, BaseClock >::timer | ( | const std::chrono::duration< Rep, Period > | timer_interval, |
timer_end_callback && | callback | ||
) |
Timer constructor from timer interval and callback.
Timer's callback will be called after timer_interval.
timer_interval | Timer interval. |
callback | Function that will be called after timer_interval. |
precision | Precision of timer. By default it's 1 microsecond (1us). Only if GOLXZN_MULTITHREADING is defined. |
golxzn::os::chrono::timer< OnTimerDone, BaseClock >::timer | ( | const time | timer_interval, |
timer_end_callback && | callback | ||
) |
Timer constructor from timer interval and callback.
Timer's callback will be called after timer_interval.
timer_interval | Timer interval. |
callback | Function that will be called after timer_interval. |
precision | Precision of timer. By default it's 1 microsecond (1us). Only if GOLXZN_MULTITHREADING is defined. |
|
noexcept |
Returns true if timer is done.
|
noexcept |
Returns true if timer is running.
|
noexcept |
Returns time left to the end of the timer.
void golxzn::os::chrono::timer< OnTimerDone, BaseClock >::update | ( | ) |
Updates timer. (only when GOLXZN_MULTITHREADING is not defined)
Should be called in main thread. It's not needed if GOLXZN_MULTITHREADING
is defined.