17 #ifndef GZ_SIM_EVENTMANAGER_HH_
18 #define GZ_SIM_EVENTMANAGER_HH_
25 #include <unordered_map>
28 #include <gz/common/Console.hh>
29 #include <gz/common/Event.hh>
31 #include <gz/sim/config.hh>
32 #include <gz/sim/Export.hh>
40 inline namespace GZ_SIM_VERSION_NAMESPACE {
72 public:
template <
typename E>
74 Connect(
const typename E::CallbackT &_subscriber)
76 if (this->
events.find(
typeid(E)) == this->events.end()) {
77 this->
events[
typeid(E)] = std::make_unique<E>();
85 E *eventPtr =
static_cast<E *
>(this->
events[
typeid(E)].get());
86 return eventPtr->Connect(_subscriber);
92 public:
template <
typename E,
typename ... Args>
93 void Emit(Args && ... _args)
95 if (this->
events.find(
typeid(E)) == this->events.end())
102 this->
events[
typeid(E)] = std::make_unique<E>();
107 E *eventPtr =
static_cast<E *
>(this->
events[
typeid(E)].get());
108 eventPtr->Signal(std::forward<Args>(_args) ...);
113 public:
template <
typename E>
117 if (this->
events.find(
typeid(E)) == this->events.end())
123 E *eventPtr =
static_cast<E *
>(this->
events[
typeid(E)].get());
124 return eventPtr->ConnectionCount();
134 private:
struct Hasher
143 private:
struct EqualTo
145 bool operator()(TypeInfoRef _lhs, TypeInfoRef _rhs)
const
147 return _lhs.get() == _rhs.get() ||
149 _rhs.get().name()) == 0;