22 #ifndef NDN_UTIL_SIGNAL_SIGNAL_HPP 23 #define NDN_UTIL_SIGNAL_SIGNAL_HPP 49 template<
typename Owner,
typename ...TArgs>
55 typedef function<void(
const TArgs&...)>
Handler;
89 operator()(
const TArgs&...args);
98 #if NDN_CXX_HAVE_CXX_FRIEND_TYPENAME 100 #elif NDN_CXX_HAVE_CXX_FRIEND_TYPENAME_WRAPPER 106 friend class TypeWrapper<Owner>::Type;
108 # error "cannot declare Owner as friend" 112 typedef
Signal<Owner, TArgs...> Self;
119 typedef std::list<Slot> SlotList;
138 shared_ptr<function<void()>> disconnect;
160 template<
typename Owner,
typename ...TArgs>
162 : m_isExecuting(false)
166 template<
typename Owner,
typename ...TArgs>
169 BOOST_ASSERT(!m_isExecuting);
172 template<
typename Owner,
typename ...TArgs>
177 it->disconnect = make_shared<function<void()>>(bind(&Self::disconnect,
this, it));
182 template<
typename Owner,
typename ...TArgs>
187 it->disconnect = make_shared<function<void()>>(bind(&Self::disconnect,
this, it));
190 it->handler = [conn, handler] (
const TArgs&... args)
mutable {
198 template<
typename Owner,
typename ...TArgs>
206 BOOST_ASSERT_MSG(it == m_currentSlot,
207 "cannot disconnect another handler from a handler");
208 m_currentSlot = m_slots.end();
213 template<
typename Owner,
typename ...TArgs>
215 Signal<Owner, TArgs...>::isEmpty()
const 217 return !m_isExecuting && m_slots.empty();
220 template<
typename Owner,
typename ...TArgs>
222 Signal<Owner, TArgs...>::operator()(
const TArgs&... args)
224 BOOST_ASSERT_MSG(!m_isExecuting,
"cannot emit signal from a handler");
225 if (m_slots.empty()) {
228 m_isExecuting =
true;
241 m_currentSlot->handler(args...);
245 m_isExecuting =
false;
248 m_isExecuting =
false;
251 template<
typename Owner,
typename ...TArgs>
253 Signal<Owner, TArgs...>::operator()(
const TArgs&... args,
const DummyExtraArg&)
255 this->operator()(args...);
266 #endif // NDN_UTIL_SIGNAL_SIGNAL_HPP Connection connectSingleShot(const Handler &handler)
connects a single-shot handler to the signal
Copyright (c) 2011-2015 Regents of the University of California.
represents a connection to a signal
provides a lightweight signal / event system
Table::const_iterator iterator
Connection connect(const Handler &handler)
connects a handler to the signal
function< void(const TArgs &...)> Handler
represents a function that can connect to the signal