aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/HandlerRegistry.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-04 22:18:44 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-04 22:18:44 +0800
commit38b1268028d4d631de15ca85826c241e39c82675 (patch)
tree8359891236b3cd766068cf87cfbd566ac507fc93 /include/cru/base/HandlerRegistry.h
parentef6cff0f308d49326bbe0c3b557cb8ab6cca455b (diff)
downloadcru-38b1268028d4d631de15ca85826c241e39c82675.tar.gz
cru-38b1268028d4d631de15ca85826c241e39c82675.tar.bz2
cru-38b1268028d4d631de15ca85826c241e39c82675.zip
Remove Event2 and HandlerRegistry.
Diffstat (limited to 'include/cru/base/HandlerRegistry.h')
-rw-r--r--include/cru/base/HandlerRegistry.h87
1 files changed, 0 insertions, 87 deletions
diff --git a/include/cru/base/HandlerRegistry.h b/include/cru/base/HandlerRegistry.h
deleted file mode 100644
index e405d1fd..00000000
--- a/include/cru/base/HandlerRegistry.h
+++ /dev/null
@@ -1,87 +0,0 @@
-#pragma once
-#include "Base.h"
-
-#include <algorithm>
-#include <functional>
-#include <utility>
-#include <vector>
-
-namespace cru {
-
-template <typename T>
-class HandlerRegistryIterator {
- public:
- using RawIterator =
- typename std::vector<std::pair<int, std::function<T>>>::const_iterator;
-
- explicit HandlerRegistryIterator(RawIterator raw) : raw_(std::move(raw)) {}
-
- CRU_DELETE_COPY(HandlerRegistryIterator)
- CRU_DELETE_MOVE(HandlerRegistryIterator)
-
- ~HandlerRegistryIterator() = default;
-
- const std::function<T>& operator*() const { return raw_->second; }
- const std::function<T>* operator->() const { return &raw_->second; }
-
- HandlerRegistryIterator& operator++() {
- ++raw_;
- return *this;
- }
-
- HandlerRegistryIterator operator++(int) {
- auto c = *this;
- this->operator++();
- return c;
- }
-
- bool operator==(const HandlerRegistryIterator<T>& other) const {
- return this->raw_ == other.raw_;
- }
-
- bool operator!=(const HandlerRegistryIterator<T>& other) const {
- return !this->operator==(other);
- }
-
- private:
- RawIterator raw_;
-};
-
-template <typename T>
-class HandlerRegistry final {
- public:
- HandlerRegistry() = default;
- CRU_DEFAULT_COPY(HandlerRegistry)
- CRU_DEFAULT_MOVE(HandlerRegistry)
- ~HandlerRegistry() = default;
-
- public:
- int AddHandler(std::function<T> handler) {
- auto id = current_id_++;
- handler_list_.push_back({id, std::move(handler)});
- return id;
- }
-
- void RemoveHandler(int id) {
- auto result = std::find_if(handler_list_.cbegin(), handler_list_.cend(),
- [id](const std::pair<int, std::function<T>>& d) {
- return d.first == id;
- });
- if (result != handler_list_.cend()) {
- handler_list_.erase(result);
- }
- }
-
- HandlerRegistryIterator<T> begin() const {
- return HandlerRegistryIterator<T>(handler_list_.begin());
- }
-
- HandlerRegistryIterator<T> end() const {
- return HandlerRegistryIterator<T>(handler_list_.end());
- }
-
- private:
- int current_id_ = 1;
- std::vector<std::pair<int, std::function<T>>> handler_list_;
-};
-} // namespace cru