#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