add timer
This commit is contained in:
parent
e5a248b966
commit
ef8d0bc527
@ -34,6 +34,7 @@
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
|
||||
#include "timer.hpp"
|
||||
#include "averager.hpp"
|
||||
|
||||
#include "aftercheaders.h"
|
||||
|
36
src/timer.hpp
Normal file
36
src/timer.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* timer.hpp
|
||||
*
|
||||
* Created on: Jul 29, 2017
|
||||
* Author: nullifiedcat
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
typedef std::chrono::system_clock clock;
|
||||
|
||||
inline Timer() {};
|
||||
|
||||
inline bool check(unsigned ms) const {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(clock::now() - last).count() >= ms;
|
||||
}
|
||||
inline bool test_and_set(unsigned ms) {
|
||||
if (check(ms)) {
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
inline void update() {
|
||||
last = clock::now();
|
||||
}
|
||||
|
||||
public:
|
||||
std::chrono::time_point<clock> last {};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user