33 #ifndef DART_COMMON_DETAIL_SIGNAL_HPP_
34 #define DART_COMMON_DETAIL_SIGNAL_HPP_
42 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
49 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
50 Signal<_Res(_ArgTypes...), Combiner>::~Signal()
56 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
59 auto newConnectionBody = std::make_shared<ConnectionBodyType>(*
this, _slot);
60 mConnectionBodies.insert(newConnectionBody);
62 return Connection(std::move(newConnectionBody));
66 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
69 auto newConnectionBody = std::make_shared<ConnectionBodyType>(
70 *
this, std::forward<SlotType>(_slot));
71 mConnectionBodies.insert(newConnectionBody);
73 return Connection(std::move(newConnectionBody));
77 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
78 void Signal<_Res(_ArgTypes...), Combiner>::disconnect(
85 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
86 void Signal<_Res(_ArgTypes...), Combiner>::disconnect(
87 const std::shared_ptr<Signal::ConnectionBodyType>& connectionBody)
89 mConnectionBodies.erase(connectionBody);
93 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
94 void Signal<_Res(_ArgTypes...), Combiner>::disconnectAll()
96 mConnectionBodies.clear();
100 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
101 void Signal<_Res(_ArgTypes...), Combiner>::cleanupConnections()
107 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
108 std::size_t
Signal<_Res(_ArgTypes...), Combiner>::getNumConnections()
const
110 return mConnectionBodies.size();
114 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
115 template <
typename... ArgTypes>
116 _Res
Signal<_Res(_ArgTypes...), Combiner>::raise(ArgTypes&&... _args)
118 std::vector<ResultType> res(mConnectionBodies.size());
119 auto resIt = res.begin();
121 for (
const auto& connectionBody : mConnectionBodies)
123 *(resIt++) = connectionBody->getSlot()(std::forward<ArgTypes>(_args)...);
126 return Combiner<ResultType>::process(res.begin(), resIt);
130 template <
typename _Res,
typename... _ArgTypes,
template <
class>
class Combiner>
131 template <
typename... ArgTypes>
132 _Res
Signal<_Res(_ArgTypes...), Combiner>::operator()(ArgTypes&&... _args)
134 return raise(std::forward<ArgTypes>(_args)...);
138 template <
typename... _ArgTypes>
145 template <
typename... _ArgTypes>
152 template <
typename... _ArgTypes>
155 auto newConnectionBody = std::make_shared<ConnectionBodyType>(*
this, _slot);
156 mConnectionBodies.insert(newConnectionBody);
158 return Connection(std::move(newConnectionBody));
162 template <
typename... _ArgTypes>
165 auto newConnectionBody = std::make_shared<ConnectionBodyType>(
166 *
this, std::forward<SlotType>(_slot));
167 mConnectionBodies.insert(newConnectionBody);
169 return Connection(std::move(newConnectionBody));
173 template <
typename... _ArgTypes>
180 template <
typename... _ArgTypes>
181 void Signal<void(_ArgTypes...)>::disconnect(
182 const std::shared_ptr<Signal::ConnectionBodyType>& connectionBody)
184 mConnectionBodies.erase(connectionBody);
188 template <
typename... _ArgTypes>
189 void Signal<void(_ArgTypes...)>::disconnectAll()
191 mConnectionBodies.clear();
195 template <
typename... _ArgTypes>
196 void Signal<void(_ArgTypes...)>::cleanupConnections()
202 template <
typename... _ArgTypes>
203 std::size_t
Signal<void(_ArgTypes...)>::getNumConnections()
const
205 return mConnectionBodies.size();
209 template <
typename... _ArgTypes>
210 template <
typename... ArgTypes>
211 void Signal<void(_ArgTypes...)>::raise(ArgTypes&&... _args)
213 for (
const auto& connectionBody : mConnectionBodies)
215 connectionBody->getSlot()(std::forward<ArgTypes>(_args)...);
220 template <
typename... _ArgTypes>
221 template <
typename... ArgTypes>
222 void Signal<void(_ArgTypes...)>::operator()(ArgTypes&&... _args)
224 raise(std::forward<ArgTypes>(_args)...);
228 template <
typename T>
236 template <
typename T>
239 return mSignal.connect(_slot);
class Connection
Definition: Signal.hpp:48
void disconnect() const
Disconnect the connection.
Definition: Signal.cpp:101
std::function< ResultType(_ArgTypes...)> SlotType
Definition: Signal.hpp:117
std::function< void(_ArgTypes...)> SlotType
Definition: Signal.hpp:173
Definition: Signal.hpp:109
SlotRegister(typename T::SignalType &_signal)
Constructor given signal.
Definition: Signal.hpp:229
typename T::SlotType SlotType
Definition: Signal.hpp:231
Connection connect(const SlotType &_slot)
Connect a slot to the signal.
Definition: Signal.hpp:237
Definition: BulletCollisionDetector.cpp:65