diff --git a/include/td/protocol/Dispatcher.h b/include/td/protocol/Dispatcher.h deleted file mode 100644 index 037ce03..0000000 --- a/include/td/protocol/Dispatcher.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -/** - * \file PacketDispatcher.h - * \brief File containing the td::protocol::PacketDispatcher class - */ - -#include -#include - -#include - -namespace td { -namespace protocol { - -/** - * \class Dispatcher - * \brief Class used to dispatch things - */ -template -class Dispatcher : private NonCopyable { - private: - std::map> m_Handlers; - - public: - /** - * \brief Constructor - */ - Dispatcher() {} - - /** - * \brief Dispatch a packet - * \param packet The packet to dispatch - */ - void Dispatch(const T& packet); - - /** - * \brief Register a packet handler - * \param type The packet type - * \param handler The packet handler - */ - void RegisterHandler(T_Enum type, T_Handler& handler); - - /** - * \brief Unregister a packet handler - * \param type The packet type - * \param handler The packet handler - */ - void UnregisterHandler(T_Enum type, T_Handler& handler); - - /** - * \brief Unregister a packet handler - * \param handler The packet handler - */ - void UnregisterHandler(T_Handler& handler); -}; - -} // namespace protocol -} // namespace td - -#include "Dispatcher.inl" \ No newline at end of file diff --git a/include/td/protocol/Dispatcher.inl b/include/td/protocol/Dispatcher.inl deleted file mode 100644 index d807f9b..0000000 --- a/include/td/protocol/Dispatcher.inl +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -namespace td { -namespace protocol { - -template -void Dispatcher::Dispatch(const T& packet) { - T_Enum type = packet.GetType(); - for (auto* handler : m_Handlers[type]) - handler->Check(packet); -} - -template -void Dispatcher::RegisterHandler(T_Enum type, T_Handler& handler) { - auto found = std::find(m_Handlers[type].begin(), m_Handlers[type].end(), &handler); - if (found == m_Handlers[type].end()) - m_Handlers[type].push_back(&handler); -} - -template -void Dispatcher::UnregisterHandler(T_Enum type, T_Handler& handler) { - m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end()); -} - -template -void Dispatcher::UnregisterHandler(T_Handler& handler) { - for (auto& pair : m_Handlers) { - if (pair.second.empty()) - continue; - - PacketType type = pair.first; - - m_Handlers[type].erase(std::remove(m_Handlers[type].begin(), m_Handlers[type].end(), &handler), m_Handlers[type].end()); - } -} - -} // namespace protocol -} // namespace td