31 #include "bind_member.h"
45 operator bool()
const {
return static_cast<bool>(impl); }
48 explicit Slot(T impl) : impl(impl) { }
51 std::shared_ptr<SlotImpl> impl;
63 template<
typename SlotImplType>
67 std::vector<std::weak_ptr<SlotImplType>>
slots;
70 template<
typename FuncType>
80 std::shared_ptr<SignalImpl<SlotImplT>> sig =
signal.lock();
83 for (
auto it = sig->slots.begin(); it != sig->slots.end(); ++it)
86 if (it->expired() || it->lock().get() ==
this)
88 it = sig->slots.erase(it);
89 if (it == sig->slots.end())
96 std::weak_ptr<SignalImpl<SlotImplT>>
signal;
100 template<
typename FuncType>
106 template<
typename... Args>
109 std::vector<std::weak_ptr<SlotImplT<FuncType>>> slots = impl->slots;
112 std::shared_ptr<SlotImplT<FuncType>> slot = weak_slot.lock();
115 slot->callback(std::forward<Args>(args)...);
122 auto slot_impl = std::make_shared<SlotImplT<FuncType>>(impl, func);
123 impl->slots.push_back(slot_impl);
124 return Slot(slot_impl);
127 template<
typename InstanceType,
typename MemberFuncType>
134 std::shared_ptr<SignalImpl<SlotImplT<FuncType>>> impl;
140 template<
typename FuncType,
typename InstanceType,
typename MemberFuncType>
143 slots.push_back(signal.
connect(instance, func));
146 template<
typename FuncType,
typename CallbackType>
149 slots.push_back(signal.
connect(func));
153 std::vector<Slot> slots;
std::weak_ptr< SignalImpl< SlotImplT > > signal
Definition: signal.h:96
Slot connect(InstanceType instance, MemberFuncType func)
Definition: signal.h:128
Slot connect(const std::function< FuncType > &func)
Definition: signal.h:120
SlotImplT(const std::weak_ptr< SignalImpl< SlotImplT >> &signal, const std::function< FuncType > &callback)
Definition: signal.h:74
SlotImpl()
Definition: signal.h:57
std::function< R(Args...)> bind_member(T *instance, R(T::*method)(Args...))
Definition: bind_member.h:37
std::vector< std::weak_ptr< SlotImplType > > slots
Definition: signal.h:67
~SlotImplT()
Definition: signal.h:78
virtual ~SlotImpl()
Definition: signal.h:60
Signal()
Definition: signal.h:104
void connect(Signal< FuncType > &signal, InstanceType instance, MemberFuncType func)
Definition: signal.h:141
Slot()
Definition: signal.h:43
void connect(Signal< FuncType > &signal, CallbackType func)
Definition: signal.h:147
std::function< FuncType > callback
Definition: signal.h:97
void operator()(Args &&...args)
Definition: signal.h:107
Slot(T impl)
Definition: signal.h:48
Definition: Application/application.h:35
SlotImpl & operator=(const SlotImpl &)=delete