message_bus_impl.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 fn
  31. * @return
  32. */
  33. bool bind(std::string const& str_topic, std::any const& fn);
  34. /**
  35. * @brief 绑定多个函数
  36. * @param str_topic
  37. * @param fn
  38. */
  39. void bind_multiple(std::string const& str_topic, std::any const& fn);
  40. /**
  41. * @brief 查找
  42. * @param str_topic
  43. * @return
  44. */
  45. std::vector<std::any> find(const std::string& str_topic);
  46. /**
  47. * @brief 删除
  48. * @param str_topic
  49. */
  50. void remove(const std::string& str_topic);
  51. private:
  52. message_bus_impl();
  53. private:
  54. std::multimap<std::string, std::pair<bool, std::any>> map_;
  55. typedef std::multimap<std::string, std::pair<bool, std::any>>::iterator Iterater;
  56. };
  57. }