129 unsigned long m_ref_count ;
138 G_EXCEPTION( AlreadyConnected ,
"signal already connected to a slot" ) ;
149 template <
typename T>
153 SlotImp0( T &
object ,
void (T::*fn)() ) : m_object(
object) , m_fn(fn) {}
154 void callback() { (m_object.*m_fn)() ; }
163 template <
typename T>
180 Slot0() : m_imp(0) , m_callback_fn(0) {}
183 void callback() {
if( m_imp ) (*m_callback_fn)( m_imp ) ; }
184 Slot0(
const Slot0 & other ) : m_imp(other.m_imp) , m_callback_fn(other.m_callback_fn) {
if(m_imp) m_imp->
up() ; }
185 void swap(
Slot0 & rhs ) {
using std::swap ; swap(m_imp,rhs.m_imp) ; swap(m_callback_fn,rhs.m_callback_fn) ; }
186 void operator=(
const Slot0 & rhs ) {
Slot0 tmp(rhs) ; swap(tmp) ; }
187 const SlotImpBase * base()
const {
return m_imp ; }
200 explicit Signal0(
bool once =
false ) : m_emitted(
false) , m_once(once) {}
201 void emit() {
if(!m_once||!m_emitted) { m_emitted = true ; m_slot.callback() ; } }
202 void connect(
Slot0 slot ) { SignalImp::check(m_slot.base()) ; m_slot =
slot ; }
203 void disconnect() { m_slot =
Slot0() ; }
204 void reset() { m_emitted = false ; }
208 template <
typename T>
219 template <
typename T,
typename P>
224 void (T::*m_fn)( P ) ;
226 SlotImp1( T &
object ,
void (T::*fn)(P) ) : m_object(
object) , m_fn(fn) {}
227 void callback( P p ) { (m_object.*m_fn)(p) ; }
233 template <
typename T,
typename P>
244 template <
typename P>
251 Slot1() : m_imp(0) , m_callback_fn(0) {}
254 void callback( P p ) {
if( m_imp ) (*m_callback_fn)( m_imp , p ) ; }
255 Slot1(
const Slot1<P> & other ) : m_imp(other.m_imp) , m_callback_fn(other.m_callback_fn) {
if(m_imp) m_imp->
up() ; }
256 void swap(
Slot1<P> & rhs ) {
using std::swap ; swap(m_imp,rhs.m_imp) ; swap(m_callback_fn,rhs.m_callback_fn) ; }
257 void operator=(
const Slot1<P> & rhs ) {
Slot1 tmp(rhs) ; swap(tmp) ; }
258 const SlotImpBase * base()
const {
return m_imp ; }
264 template <
typename P>
272 explicit Signal1(
bool once =
false ) : m_emitted(
false) , m_once(once) {}
273 void emit( P p ) {
if(!m_once||!m_emitted) { m_emitted = true ; m_slot.callback( p ) ; } }
274 void connect(
Slot1<P> slot ) { SignalImp::check(m_slot.base()) ; m_slot =
slot ; }
275 void disconnect() { m_slot =
Slot1<P>() ; }
276 void reset() { m_emitted = false ; }
280 template <
typename T,
typename P>
291 template <
typename T,
typename P1,
typename P2>
296 void (T::*m_fn)( P1 , P2 ) ;
298 SlotImp2( T &
object ,
void (T::*fn)(P1,P2) ) : m_object(
object) , m_fn(fn) {}
299 void callback( P1 p1 , P2 p2 ) { (m_object.*m_fn)(p1,p2) ; }
305 template <
typename T,
typename P1 ,
typename P2>
309 static void callback(
SlotImpBase * imp , P1 p1 , P2 p2 )
316 template <
typename P1,
typename P2>
323 Slot2() : m_imp(0) , m_callback_fn(0) {}
326 void callback( P1 p1 , P2 p2 ) {
if( m_imp ) (*m_callback_fn)( m_imp , p1 , p2 ) ; }
327 Slot2(
const Slot2<P1,P2> & other ) : m_imp(other.m_imp) , m_callback_fn(other.m_callback_fn) {
if(m_imp) m_imp->
up() ; }
328 void swap(
Slot2<P1,P2> & rhs ) {
using std::swap ; swap(m_imp,rhs.m_imp) ; swap(m_callback_fn,rhs.m_callback_fn) ; }
330 const SlotImpBase * base()
const {
return m_imp ; }
336 template <
typename P1,
typename P2>
344 explicit Signal2(
bool once =
false ) : m_emitted(
false) , m_once(once) {}
345 void emit( P1 p1 , P2 p2 ) {
if(!m_once||!m_emitted) { m_emitted = true ; m_slot.callback( p1 , p2 ) ; } }
348 void reset() { m_emitted = false ; }
352 template <
typename T,
typename P1,
typename P2>
363 template <
typename T,
typename P1,
typename P2,
typename P3>
368 void (T::*m_fn)( P1 , P2 , P3 ) ;
370 SlotImp3( T &
object ,
void (T::*fn)(P1,P2,P3) ) : m_object(
object) , m_fn(fn) {}
371 void callback( P1 p1 , P2 p2 , P3 p3 ) { (m_object.*m_fn)(p1,p2,p3) ; }
377 template <
typename T,
typename P1 ,
typename P2,
typename P3>
381 static void callback(
SlotImpBase * imp , P1 p1 , P2 p2 , P3 p3 )
388 template <
typename P1,
typename P2,
typename P3>
393 void (*m_callback_fn)(
SlotImpBase * , P1 , P2 , P3 ) ;
395 Slot3() : m_imp(0) , m_callback_fn(0) {}
398 void callback( P1 p1 , P2 p2 , P3 p3 ) {
if( m_imp ) (*m_callback_fn)( m_imp , p1 , p2 , p3 ) ; }
399 Slot3(
const Slot3<P1,P2,P3> & other ) : m_imp(other.m_imp) , m_callback_fn(other.m_callback_fn) {
if(m_imp) m_imp->
up() ; }
400 void swap(
Slot3<P1,P2,P3> & rhs ) {
using std::swap ; swap(m_imp,rhs.m_imp) ; swap(m_callback_fn,rhs.m_callback_fn) ; }
402 const SlotImpBase * base()
const {
return m_imp ; }
408 template <
typename P1,
typename P2,
typename P3>
416 explicit Signal3(
bool once =
false ) : m_emitted(
false) , m_once(once) {}
417 void emit( P1 p1 , P2 p2 , P3 p3 ) {
if(!m_once||!m_emitted) { m_emitted = true ; m_slot.callback( p1 , p2 , p3 ) ; }}
420 void reset() { m_emitted = false ; }
424 template <
typename T,
typename P1,
typename P2,
typename P3>
427 return Slot3<P1,P2,P3>(
new SlotImp3<T,P1,P2,P3>(object,fn) ,
SlotCallback3<T,P1,P2,P3>::callback ) ;
SlotImpBase()
Default constuctor.
A noncopyable base class (a la boost).
A signal class for two-parameter callbacks.
A slot implementation class for one-parameter callbacks.
A slot class for zero-parameter callbacks.
Used as a base class to all slot implementation classes (such as G::Slot::SlotImp1), allowing them to be used as bodies to the associated slot reference-counting handle class (eg.
A slot implementation class for zero-parameter callbacks.
Provides a function to down-cast from SlotImpBase to SlotImp2.
Slot0 slot(T &object, void(T::*fn)())
A slot factory function overloaded for a zero-parameter callback.
void up()
Increments the reference count.
Provides a function to down-cast from SlotImpBase to SlotImp1.
A slot class for one-parameter callbacks.
A signal class for zero-parameter callbacks.
A static helper class used by G::Slot signal classes.
A slot implementation class for three-parameter callbacks.
Provides a function to down-cast from SlotImpBase to SlotImp0.
A signal class for three-parameter callbacks.
A slot class for two-parameter callbacks.
A signal class for one-parameter callbacks.
virtual ~SlotImpBase()
Destructor.
Provides a function to down-cast from SlotImpBase to SlotImp3.
A slot implementation class for two-parameter callbacks.
A slot class for three-parameter callbacks.
void down()
Decrements the reference count and does "delete this" on zero.