aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-17 15:57:53 +0800
committercrupest <crupest@outlook.com>2020-10-17 15:57:53 +0800
commit46ff47d2f47a66372ca0a8a09dd08c4fb04004f3 (patch)
tree0a1168ea234cb545f76b6d9a8031c36c0f224f5c /include/cru/common
parent937b16dff40b6eba68d6bc13162f838c8432f43b (diff)
downloadcru-46ff47d2f47a66372ca0a8a09dd08c4fb04004f3.tar.gz
cru-46ff47d2f47a66372ca0a8a09dd08c4fb04004f3.tar.bz2
cru-46ff47d2f47a66372ca0a8a09dd08c4fb04004f3.zip
Refactor timer.
Diffstat (limited to 'include/cru/common')
-rw-r--r--include/cru/common/Event.hpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/include/cru/common/Event.hpp b/include/cru/common/Event.hpp
index 377ca7f3..6417bc78 100644
--- a/include/cru/common/Event.hpp
+++ b/include/cru/common/Event.hpp
@@ -5,6 +5,7 @@
#include <algorithm>
#include <functional>
+#include <initializer_list>
#include <memory>
#include <utility>
#include <vector>
@@ -183,6 +184,7 @@ struct EventRevokerDestroyer {
};
} // namespace details
+// A guard class for event revoker. Automatically revoke it when destroyed.
class EventRevokerGuard {
public:
EventRevokerGuard() = default;
@@ -201,7 +203,7 @@ class EventRevokerGuard {
return *revoker_;
}
- void Release() { revoker_.release(); }
+ EventRevoker Release() { return std::move(*revoker_.release()); }
void Reset(EventRevoker&& revoker) {
revoker_.reset(new EventRevoker(std::move(revoker)));
@@ -209,5 +211,28 @@ class EventRevokerGuard {
private:
std::unique_ptr<EventRevoker, details::EventRevokerDestroyer> revoker_;
-}; // namespace cru
+};
+
+class EventRevokerListGuard {
+ public:
+ EventRevokerListGuard() = default;
+ EventRevokerListGuard(const EventRevokerListGuard& other) = delete;
+ EventRevokerListGuard(EventRevokerListGuard&& other) = default;
+ EventRevokerListGuard& operator=(const EventRevokerListGuard& other) = delete;
+ EventRevokerListGuard& operator=(EventRevokerListGuard&& other) = default;
+ ~EventRevokerListGuard() = default;
+
+ public:
+ void Add(EventRevoker&& revoker) {
+ event_revoker_guard_list_.push_back(EventRevokerGuard(std::move(revoker)));
+ }
+
+ EventRevokerListGuard& operator+=(EventRevoker&& revoker) {
+ this->Add(std::move(revoker));
+ return *this;
+ }
+
+ private:
+ std::vector<EventRevokerGuard> event_revoker_guard_list_;
+};
} // namespace cru