From 74bb9cd27242b9320f99ff4d2b50c3051576cc14 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 16:53:51 +0800 Subject: ... --- include/cru/common/HandlerRegistry.hpp | 87 ---------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 include/cru/common/HandlerRegistry.hpp (limited to 'include/cru/common/HandlerRegistry.hpp') diff --git a/include/cru/common/HandlerRegistry.hpp b/include/cru/common/HandlerRegistry.hpp deleted file mode 100644 index 8049e74b..00000000 --- a/include/cru/common/HandlerRegistry.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once -#include "Base.hpp" - -#include -#include -#include -#include - -namespace cru { - -template -class HandlerRegistryIterator { - public: - using RawIterator = - typename std::vector>>::const_iterator; - - explicit HandlerRegistryIterator(RawIterator raw) : raw_(std::move(raw)) {} - - CRU_DELETE_COPY(HandlerRegistryIterator) - CRU_DELETE_MOVE(HandlerRegistryIterator) - - ~HandlerRegistryIterator() = default; - - const std::function& operator*() const { return raw_->second; } - const std::function* operator->() const { return &raw_->second; } - - HandlerRegistryIterator& operator++() { - ++raw_; - return *this; - } - - HandlerRegistryIterator operator++(int) { - auto c = *this; - this->operator++(); - return c; - } - - bool operator==(const HandlerRegistryIterator& other) const { - return this->raw_ == other.raw_; - } - - bool operator!=(const HandlerRegistryIterator& other) const { - return !this->operator==(other); - } - - private: - RawIterator raw_; -}; - -template -class HandlerRegistry final { - public: - HandlerRegistry() = default; - CRU_DEFAULT_COPY(HandlerRegistry) - CRU_DEFAULT_MOVE(HandlerRegistry) - ~HandlerRegistry() = default; - - public: - int AddHandler(std::function 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>& d) { - return d.first == id; - }); - if (result != handler_list_.cend()) { - handler_list_.erase(result); - } - } - - HandlerRegistryIterator begin() const { - return HandlerRegistryIterator(handler_list_.begin()); - } - - HandlerRegistryIterator end() const { - return HandlerRegistryIterator(handler_list_.end()); - } - - private: - int current_id_ = 1; - std::vector>> handler_list_; -}; -} // namespace cru -- cgit v1.2.3