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 {
67 public:
template <
typename E>
69 Connect(
const typename E::CallbackT &_subscriber)
71 if (this->events.find(
typeid(E)) == this->events.end()) {
72 this->events[
typeid(E)] = std::make_unique<E>();
75 E *eventPtr =
dynamic_cast<E *
>(this->events[
typeid(E)].get());
78 if (eventPtr !=
nullptr)
80 return eventPtr->Connect(_subscriber);
84 gzerr <<
"Failed to connect event: "
93 public:
template <
typename E,
typename ... Args>
94 void Emit(Args && ... _args)
96 if (this->events.find(
typeid(E)) == this->events.end())
103 this->events[
typeid(E)] = std::make_unique<E>();
107 E *eventPtr =
dynamic_cast<E *
>(this->events[
typeid(E)].get());
110 if (eventPtr !=
nullptr)
112 eventPtr->Signal(std::forward<Args>(_args) ...);
116 gzerr <<
"Failed to signal event: "
123 public:
template <
typename E>
127 if (this->events.find(
typeid(E)) == this->events.end())
132 E *eventPtr =
dynamic_cast<E *
>(this->events[
typeid(E)].get());
135 if (eventPtr !=
nullptr)
137 return eventPtr->ConnectionCount();
141 gzerr <<
"Failed to get connection count for event: "
151 private:
struct Hasher
155 return _code.get().hash_code();
160 private:
struct EqualTo
162 bool operator()(TypeInfoRef _lhs, TypeInfoRef _rhs)
const
164 return _lhs.get() == _rhs.get();
171 Hasher, EqualTo> events;
177 #endif // GZ_SIM_EVENTMANAGER_HH_