17 #ifndef GZ_COMMON_EVENT_HH_
18 #define GZ_COMMON_EVENT_HH_
28 #include <gz/common/config.hh>
29 #include <gz/common/events/Export.hh>
38 class GZ_COMMON_EVENTS_VISIBLE
Event
59 private:
bool signaled;
75 public:
int Id()
const;
78 private:
Event *
event =
nullptr;
86 #pragma warning(disable: 4251)
95 public:
template<
typename T,
typename N>
friend class EventT;
102 template<
typename T,
typename N =
void>
107 "Event callback must have void return type");
130 public:
template<
typename ... Args>
133 this->
Signal(std::forward<Args>(args)...);
137 public:
template <
typename ... Args>
143 for (
const auto &iter : this->connections)
146 iter.second->callback(std::forward<Args>(args)...);
153 private:
void Cleanup();
156 private:
class EventConnection
161 : callback(_cb), publicConnection(_publicConn)
169 public: std::atomic_bool on;
185 private: EvtConnectionMap connections;
196 template<
typename T,
typename N>
203 template<
typename T,
typename N>
208 for (
auto &conn : this->connections)
210 auto publicCon = conn.second->publicConnection.lock();
213 publicCon->event =
nullptr;
216 this->connections.clear();
221 template<
typename T,
typename N>
225 if (!this->connections.empty())
227 auto const &iter = this->connections.rbegin();
228 index = iter->first + 1;
231 this->connections[index].reset(
232 new EventConnection(
true, _subscriber, connection));
238 template<
typename T,
typename N>
241 return this->connections.size();
246 template<
typename T,
typename N>
250 auto const &it = this->connections.find(_id);
252 if (it != this->connections.end())
254 it->second->on =
false;
262 it->second->callback =
nullptr;
263 this->connectionsToRemove.push_back(it);
268 template<
typename T,
typename N>
273 for (
auto &conn : this->connectionsToRemove)
274 this->connections.erase(conn);
275 this->connectionsToRemove.clear();