32#error invalid preprocessor definition of 'emit'
116 template <
typename T,
typename... Args>
119 using Mf = void (T::*)(Args...) ;
122 Binder( T * sink , Mf mf ) :
127 void rebind( T * sink )
noexcept
131 void operator()( Args... args )
133 return (m_sink->*m_mf)( args... ) ;
142 template <
typename... Args>
145 std::function<void(Args...)> m_fn ;
146 Slot()
noexcept =
default;
147 template <
typename T>
Slot( T & sink ,
void (T::*mf)(Args...) ) :
151 explicit Slot( std::function<
void(Args...)> fn ) :
155 void invoke( Args... args )
160 template <
typename T>
bool rebind( T & sink )
noexcept
162 using BinderType =
Binder<T,Args...> ;
163 bool rebindable = m_fn && m_fn.template target<BinderType>() ;
165 m_fn.template target<BinderType>()->rebind( &sink ) ;
175 G_EXCEPTION_CLASS( AlreadyConnected ,
tx(
"signal already connected") )
176 SignalImp() = delete ;
182 template <typename... SlotArgs>
185 Slot<SlotArgs...> m_slot ;
187 bool m_emitted {
false} ;
188 explicit Signal(
bool once =
false ) :
194 if( m_slot.m_fn )
throw SignalImp::AlreadyConnected() ;
197 void disconnect()
noexcept
199 m_slot.m_fn = nullptr ;
200 G_ASSERT( !connected() ) ;
202 void emit( SlotArgs... args )
204 if( !m_once || !m_emitted )
208 m_slot.invoke( args... ) ;
211 void reset()
noexcept
215 bool connected()
const
217 return !! m_slot.m_fn ;
219 bool emitted()
const noexcept
223 void emitted(
bool emitted )
noexcept
225 m_emitted = emitted ;
227 template <
typename T>
bool rebind( T & sink )
noexcept
229 return m_slot.rebind( sink ) ;
240 template <
typename TSink,
typename... Args>
Slot<Args...>
slot( TSink & sink ,
void (TSink::*method)(Args...) )
243 return Slot<Args...>( sink , method ) ;
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
A functor class template that contains the target object pointer and method pointer,...
A slot holder, with connect() and emit() methods.
A slot class template that is parameterised only on the target method's signature (with an implicit v...