-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimer.hpp
More file actions
39 lines (36 loc) · 1.06 KB
/
Timer.hpp
File metadata and controls
39 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef EVOAI_TIMER_HPP
#define EVOAI_TIMER_HPP
#include <functional>
#include <chrono>
namespace EvoAI{
/**
* @brief a timer
*/
class Timer final{
public:
using Clock = std::chrono::steady_clock;
public:
/**
* @brief constructor
* @param duration std::chrono::duration<std::int64_t, std::milli> duration in milliseconds
*/
Timer(std::chrono::duration<std::int64_t, std::milli> duration) noexcept;
/**
* @brief checks if the duration has been exceeded
* @code
* Timer(std::chrono::seconds(20));
* while(true){
* if(timer.update()){
* // code to exec every 20 secods
* }
* }
* @endcode
* @return bool true if mStart > mDuration
*/
bool update() noexcept;
private:
Clock::time_point mStart;
Clock::time_point mDuration;
};
}
#endif // EVOAI_TIMER_HPP