#include "message_bus_impl.h" namespace robotics::v3 { message_bus_impl::message_bus_impl() { } message_bus_impl::~message_bus_impl() { map_.clear(); } message_bus_impl* message_bus_impl::instance() { static message_bus_impl g_message_bus_impl; return &g_message_bus_impl; } bool message_bus_impl::bind(std::string const& str_topic, bool observer, std::any const& fn) { auto range = map_.equal_range(str_topic); for (Iterater it = range.first; it != range.second; ++it) { if (it->second.first == false && !observer) { return false; } } map_.emplace(str_topic, std::pair(observer, fn)); return true; } std::vector> message_bus_impl::find(const std::string& str_topic) { std::vector> result; auto range = map_.equal_range(str_topic); for (Iterater it = range.first; it != range.second; ++it) { result.push_back(it->second); } return result; } void message_bus_impl::remove(const std::string& str_topic) { auto range = map_.equal_range(str_topic); map_.erase(range.first, range.second); } }