aboutsummaryrefslogtreecommitdiff
path: root/src/timer.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-03-31 17:14:47 +0800
committercrupest <crupest@outlook.com>2019-03-31 17:14:47 +0800
commitfbfd90255731954fb80483f4ba7188d3611fafec (patch)
tree8e3283c911d7aec76130d6a1dc7f5d8a85512b59 /src/timer.hpp
parent877f65e2e2c40eecc7cfeb194dc9d391af60711b (diff)
downloadcru-fbfd90255731954fb80483f4ba7188d3611fafec.tar.gz
cru-fbfd90255731954fb80483f4ba7188d3611fafec.tar.bz2
cru-fbfd90255731954fb80483f4ba7188d3611fafec.zip
...
Diffstat (limited to 'src/timer.hpp')
-rw-r--r--src/timer.hpp64
1 files changed, 0 insertions, 64 deletions
diff --git a/src/timer.hpp b/src/timer.hpp
deleted file mode 100644
index 7199adc2..00000000
--- a/src/timer.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#pragma once
-#include "pre.hpp"
-
-#include <Windows.h>
-#include <chrono>
-#include <functional>
-#include <map>
-#include <optional>
-
-#include "base.hpp"
-
-namespace cru {
-using TimerAction = std::function<void()>;
-
-class TimerManager : public Object {
- public:
- static TimerManager* GetInstance();
-
- private:
- TimerManager() = default;
-
- public:
- TimerManager(const TimerManager& other) = delete;
- TimerManager(TimerManager&& other) = delete;
- TimerManager& operator=(const TimerManager& other) = delete;
- TimerManager& operator=(TimerManager&& other) = delete;
- ~TimerManager() override = default;
-
- UINT_PTR CreateTimer(UINT milliseconds, bool loop, const TimerAction& action);
- void KillTimer(UINT_PTR id);
- std::optional<std::pair<bool, TimerAction>> GetAction(UINT_PTR id);
-
- private:
- std::map<UINT_PTR, std::pair<bool, TimerAction>> map_{};
- UINT_PTR current_count_ = 0;
-};
-
-class TimerTask {
- friend TimerTask SetTimeout(std::chrono::milliseconds milliseconds,
- const TimerAction& action);
- friend TimerTask SetInterval(std::chrono::milliseconds milliseconds,
- const TimerAction& action);
-
- private:
- explicit TimerTask(UINT_PTR id);
-
- public:
- TimerTask(const TimerTask& other) = default;
- TimerTask(TimerTask&& other) = default;
- TimerTask& operator=(const TimerTask& other) = default;
- TimerTask& operator=(TimerTask&& other) = default;
- ~TimerTask() = default;
-
- void Cancel() const;
-
- private:
- UINT_PTR id_;
-};
-
-TimerTask SetTimeout(std::chrono::milliseconds milliseconds,
- const TimerAction& action);
-TimerTask SetInterval(std::chrono::milliseconds milliseconds,
- const TimerAction& action);
-} // namespace cru