message_bus_impl.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #ifdef WINDOWS_BUILD
  3. #ifdef MESSAGE_BUS_EXPORTS
  4. #define MESSAGE_BUS_IMPL _declspec(dllexport)
  5. #else
  6. #define MESSAGE_BUS_IMPL _declspec(dllimport)
  7. #endif
  8. #endif
  9. //stl
  10. #include <map>
  11. #include <any>
  12. #include <string>
  13. #include <functional>
  14. namespace robotics::v3 {
  15. #ifdef WINDOWS_BUILD
  16. class MESSAGE_BUS_IMPL message_bus_impl {
  17. #elif LINUX_BUILD
  18. class message_bus_impl {
  19. #endif
  20. public:
  21. /**
  22. * @brief 单例
  23. * @return
  24. */
  25. static message_bus_impl* instance();
  26. ~message_bus_impl();
  27. /**
  28. * @brief 函数绑定到指定主题。
  29. * @param str_topic 要绑定的主题名称。
  30. * @param observer 指示是否作为观察者绑定的布尔值。
  31. * @param fn 要绑定的函数对象。
  32. * @return 如果绑定成功则返回 true,否则返回 false。
  33. */
  34. bool bind(std::string const& str_topic, bool observer, std::any const& fn);
  35. /**
  36. * @brief 查找
  37. * @param str_topic
  38. * @return
  39. */
  40. std::vector<std::pair<bool, std::any>> find(const std::string& str_topic);
  41. /**
  42. * @brief 删除
  43. * @param str_topic
  44. */
  45. void remove(const std::string& str_topic);
  46. private:
  47. message_bus_impl();
  48. private:
  49. std::multimap<std::string, std::pair<bool, std::any>> map_;
  50. typedef std::multimap<std::string, std::pair<bool, std::any>>::iterator Iterater;
  51. };
  52. }