17 #ifndef GZ_COMMON_EVENT_HH_
18 #define GZ_COMMON_EVENT_HH_
29 #include <gz/common/config.hh>
30 #include <gz/common/events/Export.hh>
39 class GZ_COMMON_EVENTS_VISIBLE
Event
60 private:
bool signaled;
76 public:
int Id()
const;
79 private:
Event *
event =
nullptr;
87 #pragma warning(disable: 4251)
96 public:
template<
typename T,
typename N>
friend class EventT;
103 template<
typename T,
typename N =
void>
108 "Event callback must have void return type");
131 public:
template<
typename ... Args>
134 this->
Signal(std::forward<Args>(args)...);
138 public:
template <
typename ... Args>
144 for (
const auto &iter : this->connections)
147 iter.second->callback(std::forward<Args>(args)...);
154 private:
void Cleanup();
157 private:
class EventConnection
162 : callback(_cb), publicConnection(_publicConn)
170 public: std::atomic_bool on;
186 private: EvtConnectionMap connections;
197 template<
typename T,
typename N>
204 template<
typename T,
typename N>
209 for (
auto &conn : this->connections)
211 auto publicCon = conn.second->publicConnection.lock();
214 publicCon->event =
nullptr;
217 this->connections.clear();
222 template<
typename T,
typename N>
226 if (!this->connections.empty())
228 auto const &iter = this->connections.rbegin();
229 index = iter->first + 1;
232 this->connections[index].reset(
233 new EventConnection(
true, _subscriber, connection));
239 template<
typename T,
typename N>
242 return this->connections.size();
247 template<
typename T,
typename N>
251 auto const &it = this->connections.find(_id);
253 if (it != this->connections.end())
255 it->second->on =
false;
263 it->second->callback =
nullptr;
264 this->connectionsToRemove.push_back(it);
269 template<
typename T,
typename N>
274 for (
auto &conn : this->connectionsToRemove)
275 this->connections.erase(conn);
276 this->connectionsToRemove.clear();