This repository has been archived on 2024-06-01. You can view files and clone it, but cannot push or open issues or pull requests.
cathook/include/timer.hpp
2018-12-20 18:35:59 +01:00

41 lines
686 B
C++

/*
* timer.hpp
*
* Created on: Jul 29, 2017
* Author: nullifiedcat
*/
#ifndef CH_TIMER_HPP
#define CH_TIMER_HPP
#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{};
};
#endif