31#include "bind_member.h"
48 operator bool()
const {
return static_cast<bool>(impl); }
51 explicit Slot(T impl) : impl(impl) { }
54 std::shared_ptr<SlotImpl> impl;
66 template<
typename SlotImplType>
70 std::vector<std::weak_ptr<SlotImplType>>
slots;
73 template<
typename FuncType>
83 std::shared_ptr<SignalImpl<SlotImplT>> sig =
signal.lock();
86 for (
auto it = sig->slots.begin(); it != sig->slots.end(); ++it)
89 if (it->expired() || it->lock().get() ==
this)
91 it = sig->slots.erase(it);
92 if (it == sig->slots.end())
99 std::weak_ptr<SignalImpl<SlotImplT>>
signal;
103 template<
typename FuncType>
109 template<
typename... Args>
112 std::vector<std::weak_ptr<SlotImplT<FuncType>>> slots = impl->slots;
115 std::shared_ptr<SlotImplT<FuncType>> slot = weak_slot.lock();
118 slot->callback(std::forward<Args>(args)...);
125 auto slot_impl = std::make_shared<SlotImplT<FuncType>>(impl, func);
126 impl->slots.push_back(slot_impl);
127 return Slot(slot_impl);
130 template<
typename InstanceType,
typename MemberFuncType>
137 std::shared_ptr<SignalImpl<SlotImplT<FuncType>>> impl;
143 template<
typename FuncType,
typename InstanceType,
typename MemberFuncType>
146 slots.push_back(signal.
connect(instance, func));
149 template<
typename FuncType,
typename CallbackType>
152 slots.push_back(signal.
connect(func));
156 std::vector<Slot> slots;
std::vector< std::weak_ptr< SlotImplType > > slots
Definition signal.h:70
void operator()(Args &&... args)
Definition signal.h:110
Slot connect(InstanceType instance, MemberFuncType func)
Definition signal.h:131
Slot connect(const std::function< FuncType > &func)
Definition signal.h:123
Signal()
Definition signal.h:107
void connect(Signal< FuncType > &signal, InstanceType instance, MemberFuncType func)
Definition signal.h:144
void connect(Signal< FuncType > &signal, CallbackType func)
Definition signal.h:150
SlotImplT(const std::weak_ptr< SignalImpl< SlotImplT > > &signal, const std::function< FuncType > &callback)
Definition signal.h:77
~SlotImplT() override
Definition signal.h:81
std::weak_ptr< SignalImpl< SlotImplT > > signal
Definition signal.h:99
std::function< FuncType > callback
Definition signal.h:100
SlotImpl(const SlotImpl &)=delete
SlotImpl()
Definition signal.h:60
SlotImpl & operator=(const SlotImpl &)=delete
virtual ~SlotImpl()
Definition signal.h:63
Slot()
Definition signal.h:46
Slot(T impl)
Definition signal.h:51
std::function< R(Args...)> bind_member(T *instance, R(T::*method)(Args...))
Definition bind_member.h:40