diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-16 10:22:07 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-16 10:22:07 +0800 |
| commit | d7fbe9332f01153efaea40e7a35f0025c75b9a04 (patch) | |
| tree | 83cace7d4edba6453ed4749efa96921272085796 /include/cru/platform/gui/TimerHelper.h | |
| parent | 246eb9266b9349b44cbe96f3f839124ab30cbb89 (diff) | |
| download | cru-d7fbe9332f01153efaea40e7a35f0025c75b9a04.tar.gz cru-d7fbe9332f01153efaea40e7a35f0025c75b9a04.tar.bz2 cru-d7fbe9332f01153efaea40e7a35f0025c75b9a04.zip | |
Abstract out AutoDestruct.
Diffstat (limited to 'include/cru/platform/gui/TimerHelper.h')
| -rw-r--r-- | include/cru/platform/gui/TimerHelper.h | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/include/cru/platform/gui/TimerHelper.h b/include/cru/platform/gui/TimerHelper.h deleted file mode 100644 index 91d436a4..00000000 --- a/include/cru/platform/gui/TimerHelper.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once -#include "UiApplication.h" - -namespace cru::platform::gui { - -class TimerAutoCanceler { - public: - TimerAutoCanceler() : id_(0) {} - explicit TimerAutoCanceler(long long id) : id_(id) {} - - CRU_DELETE_COPY(TimerAutoCanceler) - - TimerAutoCanceler(TimerAutoCanceler&& other) : id_(other.id_) { - other.id_ = 0; - } - - TimerAutoCanceler& operator=(TimerAutoCanceler&& other) { - if (&other == this) { - return *this; - } - Reset(other.id_); - other.id_ = 0; - return *this; - } - - TimerAutoCanceler& operator=(long long other) { - return this->operator=(TimerAutoCanceler(other)); - } - - ~TimerAutoCanceler() { Reset(); } - - long long Release() { - auto temp = id_; - id_ = 0; - return temp; - } - - void Reset(long long id = 0) { - if (id_ > 0) IUiApplication::GetInstance()->CancelTimer(id_); - id_ = id; - } - - explicit operator bool() const { return id_; } - - private: - long long id_; -}; - -class TimerListAutoCanceler { - public: - TimerListAutoCanceler() = default; - CRU_DELETE_COPY(TimerListAutoCanceler) - CRU_DEFAULT_MOVE(TimerListAutoCanceler) - ~TimerListAutoCanceler() = default; - - TimerListAutoCanceler& operator+=(long long id) { - list_.push_back(TimerAutoCanceler(id)); - return *this; - } - - void Clear() { list_.clear(); } - - bool IsEmpty() const { return list_.empty(); } - - private: - std::vector<TimerAutoCanceler> list_; -}; - -} // namespace cru::platform::gui |
