Files
Simple-Protocol-Lib/include/sp/protocol/MessageDispatcherImpl.inl
Persson-dev 75bae99daa
All checks were successful
Linux arm64 / Build (push) Successful in 16s
remove id from dispatcher
2025-08-04 10:11:11 +02:00

28 lines
749 B
C++

#pragma once
#include <algorithm>
#include <cassert>
namespace sp {
template <typename MessageBase>
void MessageDispatcher<MessageBase>::RegisterHandler(const std::shared_ptr<MessageHandler>& a_Handler) {
assert(a_Handler);
m_Handlers.push_back(a_Handler);
}
template <typename MessageBase>
void MessageDispatcher<MessageBase>::UnregisterHandler(const std::shared_ptr<MessageHandler>& a_Handler) {
auto found = std::find(m_Handlers.begin(), m_Handlers.end(), a_Handler);
if (found != m_Handlers.end())
m_Handlers.erase(found);
}
template <typename MessageBase>
void MessageDispatcher<MessageBase>::Dispatch(const MessageBase& a_Message) {
for (auto& handler : m_Handlers) {
a_Message.Dispatch(*handler.lock());
}
}
} // namespace sp