libzed 1.12.3
A general-purpose library for quick and simple data manipulation.
Loading...
Searching...
No Matches
timeout.hpp
1#pragma once
2
3#include "timer.hpp"
4
5namespace z {
6namespace core {
13class timeout : public timer {
14private:
15 unsigned int timeout_goal;
16
17public:
28 timeout(unsigned int timeout_micros = -1, bool run = true) noexcept;
29
37 void setTimeOut(unsigned int timeout_micros) noexcept;
38
45 bool timedOut() const noexcept;
46
47#ifdef __has_include
48#if __has_include(<cereal/cereal.hpp>)
53 template <class Archive>
54 void save(Archive &ar) const {
55 time_t elapsed = micros();
56 int goal = timeout_goal;
57 ar(CEREAL_NVP(elapsed));
58 ar(CEREAL_NVP(goal));
59 }
60
65 template <class Archive>
66 void load(Archive &ar) {
67 time_t elapsed;
68 int goal;
69 ar(CEREAL_NVP(elapsed));
70 ar(CEREAL_NVP(goal));
71 reset(std::chrono::high_resolution_clock::now() - std::chrono::microseconds(elapsed));
72 timeout_goal = goal;
73 }
74#endif
75#endif
76};
77} // namespace core
78} // namespace z
timeout(unsigned int timeout_micros=-1, bool run=true) noexcept
Timeout constructor.
bool timedOut() const noexcept
Check whether the timer has timed out.
void setTimeOut(unsigned int timeout_micros) noexcept
Set the time out goal.
void reset() noexcept
Reset the timer.
timer(bool run=true) noexcept
Timer constructor.
unsigned int micros() const noexcept
Get the elapsed time in microseconds.
Section containing core functions and classes.