17 #ifndef GZ_SIM_EVENTMANAGER_HH_
18 #define GZ_SIM_EVENTMANAGER_HH_
23 #include <unordered_map>
26 #include <gz/common/Console.hh>
27 #include <gz/common/Event.hh>
29 #include <gz/sim/config.hh>
30 #include <gz/sim/Export.hh>
38 inline namespace GZ_SIM_VERSION_NAMESPACE {
70 public:
template <
typename E>
72 Connect(
const typename E::CallbackT &_subscriber)
74 if (this->
events.find(
typeid(E)) == this->events.end()) {
75 this->
events[
typeid(E)] = std::make_unique<E>();
78 E *eventPtr =
dynamic_cast<E *
>(this->
events[
typeid(E)].get());
81 if (eventPtr !=
nullptr)
83 return eventPtr->Connect(_subscriber);
87 gzerr <<
"Failed to connect event: "
96 public:
template <
typename E,
typename ... Args>
97 void Emit(Args && ... _args)
99 if (this->
events.find(
typeid(E)) == this->events.end())
106 this->
events[
typeid(E)] = std::make_unique<E>();
110 E *eventPtr =
dynamic_cast<E *
>(this->
events[
typeid(E)].get());
113 if (eventPtr !=
nullptr)
115 eventPtr->Signal(std::forward<Args>(_args) ...);
119 gzerr <<
"Failed to signal event: "
126 public:
template <
typename E>
130 if (this->
events.find(
typeid(E)) == this->events.end())
135 E *eventPtr =
dynamic_cast<E *
>(this->
events[
typeid(E)].get());
138 if (eventPtr !=
nullptr)
140 return eventPtr->ConnectionCount();
144 gzerr <<
"Failed to get connection count for event: "
154 private:
struct Hasher
158 return _code.get().hash_code();
163 private:
struct EqualTo
165 bool operator()(TypeInfoRef _lhs, TypeInfoRef _rhs)
const
167 return _lhs.get() == _rhs.get();