From 1ee19a654d0f6ff7f151a9d26be47f8b697d3dd6 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 4 Oct 2010 21:48:02 -0700 Subject: [PATCH] convert all line-endings to unix. remove slot.h. --- example.cpp | 122 ++++++------- horrible_cast.h | 112 ++++++------ signal.h | 262 +++++++++++++------------- signal0.h | 428 +++++++++++++++++++++---------------------- signal1.h | 428 +++++++++++++++++++++---------------------- signal10.h | 428 +++++++++++++++++++++---------------------- signal11.h | 428 +++++++++++++++++++++---------------------- signal12.h | 428 +++++++++++++++++++++---------------------- signal13.h | 428 +++++++++++++++++++++---------------------- signal14.h | 428 +++++++++++++++++++++---------------------- signal15.h | 428 +++++++++++++++++++++---------------------- signal16.h | 428 +++++++++++++++++++++---------------------- signal2.h | 428 +++++++++++++++++++++---------------------- signal3.h | 428 +++++++++++++++++++++---------------------- signal4.h | 428 +++++++++++++++++++++---------------------- signal5.h | 428 +++++++++++++++++++++---------------------- signal6.h | 428 +++++++++++++++++++++---------------------- signal7.h | 428 +++++++++++++++++++++---------------------- signal8.h | 428 +++++++++++++++++++++---------------------- signal9.h | 428 +++++++++++++++++++++---------------------- signal_base.cpp | 456 +++++++++++++++++++++++----------------------- signal_base.h | 234 ++++++++++++------------ signal_template.h | 428 +++++++++++++++++++++---------------------- slot.h | 86 --------- slot_base.cpp | 106 +++++------ slot_base.h | 86 ++++----- 26 files changed, 4541 insertions(+), 4627 deletions(-) delete mode 100644 slot.h diff --git a/example.cpp b/example.cpp index abcbdda..cd0935b 100644 --- a/example.cpp +++ b/example.cpp @@ -1,62 +1,62 @@ -#include -#include - - -#include "signal.h" - -class ParentFoo -{ -public: - virtual bool Bar() - { - printf("ParentFoo::Bar!\n"); - return false; - } - - virtual ~ParentFoo() - { - // empty - } -}; - -class Foo: public ParentFoo -{ -public: - bool Bar() - { - printf("Foo::Bar!\n"); - return true; - } - - virtual ~Foo() - { - // empty - } -}; - -bool somefunc() -{ - printf("some func\n"); - return true; -} - -void anotherfunc(int x) -{ - printf("got %d\n",x); -} - -int main(int argc, char** argv) -{ - Foo f; - - signal sig; - sig.connect(&f,&Foo::Bar); - sig.connect(&f,&ParentFoo::Bar); - sig.connect(&somefunc); - sig(); - - signal sigx; - sigx.connect(&anotherfunc); - sigx(12); - sigx(999); +#include +#include + + +#include "signal.h" + +class ParentFoo +{ +public: + virtual bool Bar() + { + printf("ParentFoo::Bar!\n"); + return false; + } + + virtual ~ParentFoo() + { + // empty + } +}; + +class Foo: public ParentFoo +{ +public: + bool Bar() + { + printf("Foo::Bar!\n"); + return true; + } + + virtual ~Foo() + { + // empty + } +}; + +bool somefunc() +{ + printf("some func\n"); + return true; +} + +void anotherfunc(int x) +{ + printf("got %d\n",x); +} + +int main(int argc, char** argv) +{ + Foo f; + + signal sig; + sig.connect(&f,&Foo::Bar); + sig.connect(&f,&ParentFoo::Bar); + sig.connect(&somefunc); + sig(); + + signal sigx; + sigx.connect(&anotherfunc); + sigx(12); + sigx(999); } \ No newline at end of file diff --git a/horrible_cast.h b/horrible_cast.h index b24e42e..94308c1 100644 --- a/horrible_cast.h +++ b/horrible_cast.h @@ -1,56 +1,56 @@ -#ifndef __horrible_cast_h__ -#define __horrible_cast_h__ - - -//horrible_union is used by {safe|dangerous}_horrible_cast to copy one arbitrary type to another -template -union horrible_union -{ - t_in in; - t_out out; -}; - - -// dangerous_horrible_cast uses horrible_union to blindly copy one arbitrary type to another -// -// the data is zeroed out (via memset) before copying, in the case that he input type is smaller -// than the output type -template -inline t_out dangerous_horrible_cast(t_in in) -{ - // instance the union - horrible_union data; - - // zero out the output part of the union (only if the input is actually smaller than the output) - if ( sizeof(t_in) < sizeof(t_out) ) - { - memset(&data.out,0,sizeof(data.out)); - } - - // copy the input into the union - data.in = in; - - // return the output part out of the union - return data.out; -} - - -// safe_horrible_cast is exactly like dangerous_horrible_cast, except it statically checks to make -// certain that the output type (t_out) is at least large enough (in size) to store an instance of -// the input type (t_in) -// -// note: if you use safe_horrible_cast to copy an instance of A to B, then you may safely use -// dangerous_horrible_cast to copy an instance of B back to A. -template -inline t_out safe_horrible_cast(t_in in) -{ - // statically (compile-time) test if t_out is at least as big as t_in - typedef int ERROR___horrible_union_is_too_small_to_store_input_type[(sizeof(t_in) <= sizeof(t_out)) ? 1 : -1]; - - // now just do the regular horrible_cast - return dangerous_horrible_cast(in); -} - - -#endif // __horrible_cast_h__ - +#ifndef __horrible_cast_h__ +#define __horrible_cast_h__ + + +//horrible_union is used by {safe|dangerous}_horrible_cast to copy one arbitrary type to another +template +union horrible_union +{ + t_in in; + t_out out; +}; + + +// dangerous_horrible_cast uses horrible_union to blindly copy one arbitrary type to another +// +// the data is zeroed out (via memset) before copying, in the case that he input type is smaller +// than the output type +template +inline t_out dangerous_horrible_cast(t_in in) +{ + // instance the union + horrible_union data; + + // zero out the output part of the union (only if the input is actually smaller than the output) + if ( sizeof(t_in) < sizeof(t_out) ) + { + memset(&data.out,0,sizeof(data.out)); + } + + // copy the input into the union + data.in = in; + + // return the output part out of the union + return data.out; +} + + +// safe_horrible_cast is exactly like dangerous_horrible_cast, except it statically checks to make +// certain that the output type (t_out) is at least large enough (in size) to store an instance of +// the input type (t_in) +// +// note: if you use safe_horrible_cast to copy an instance of A to B, then you may safely use +// dangerous_horrible_cast to copy an instance of B back to A. +template +inline t_out safe_horrible_cast(t_in in) +{ + // statically (compile-time) test if t_out is at least as big as t_in + typedef int ERROR___horrible_union_is_too_small_to_store_input_type[(sizeof(t_in) <= sizeof(t_out)) ? 1 : -1]; + + // now just do the regular horrible_cast + return dangerous_horrible_cast(in); +} + + +#endif // __horrible_cast_h__ + diff --git a/signal.h b/signal.h index 6cea138..8677d0e 100644 --- a/signal.h +++ b/signal.h @@ -1,131 +1,131 @@ -#ifndef __signal_h__ -#define __signal_h__ - - - -#include "signal0.h" -#include "signal1.h" -#include "signal2.h" -#include "signal3.h" -#include "signal4.h" -#include "signal5.h" -#include "signal6.h" -#include "signal7.h" -#include "signal8.h" -#include "signal9.h" -#include "signal10.h" -#include "signal11.h" -#include "signal12.h" -#include "signal13.h" -#include "signal14.h" -#include "signal15.h" -#include "signal16.h" - - - -struct nilarg; - -template -class signal : - public signal16 -{ -}; - -template -class signal : - public signal15 -{ -}; - -template -class signal : - public signal14 -{ -}; - -template -class signal : - public signal13 -{ -}; - -template -class signal : - public signal12 -{ -}; - -template -class signal : - public signal11 -{ -}; - -template -class signal : - public signal10 -{ -}; - -template -class signal : - public signal9 -{ -}; - -template -class signal : - public signal8 -{ -}; - -template -class signal : - public signal7 -{ -}; - -template -class signal : - public signal6 -{ -}; - -template -class signal : - public signal5 -{ -}; - -template -class signal : - public signal4 -{ -}; - -template -class signal : - public signal3 -{ -}; - -template -class signal : - public signal2 -{ -}; - -template -class signal : - public signal1 -{ -}; - -template -class signal : - public signal0 -{ -}; - - -#endif // __signal_h__ +#ifndef __signal_h__ +#define __signal_h__ + + + +#include "signal0.h" +#include "signal1.h" +#include "signal2.h" +#include "signal3.h" +#include "signal4.h" +#include "signal5.h" +#include "signal6.h" +#include "signal7.h" +#include "signal8.h" +#include "signal9.h" +#include "signal10.h" +#include "signal11.h" +#include "signal12.h" +#include "signal13.h" +#include "signal14.h" +#include "signal15.h" +#include "signal16.h" + + + +struct nilarg; + +template +class signal : + public signal16 +{ +}; + +template +class signal : + public signal15 +{ +}; + +template +class signal : + public signal14 +{ +}; + +template +class signal : + public signal13 +{ +}; + +template +class signal : + public signal12 +{ +}; + +template +class signal : + public signal11 +{ +}; + +template +class signal : + public signal10 +{ +}; + +template +class signal : + public signal9 +{ +}; + +template +class signal : + public signal8 +{ +}; + +template +class signal : + public signal7 +{ +}; + +template +class signal : + public signal6 +{ +}; + +template +class signal : + public signal5 +{ +}; + +template +class signal : + public signal4 +{ +}; + +template +class signal : + public signal3 +{ +}; + +template +class signal : + public signal2 +{ +}; + +template +class signal : + public signal1 +{ +}; + +template +class signal : + public signal0 +{ +}; + + +#endif // __signal_h__ diff --git a/signal0.h b/signal0.h index 0d55164..b0c088a 100644 --- a/signal0.h +++ b/signal0.h @@ -1,214 +1,214 @@ -#ifndef __signal0_h__ -#define __signal0_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot0, slot0_function, and slot0_method -// - -// -// Abstract base class for slots with 0 parameter(s). -// -template -class slot0: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() () const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot0_function: public slot0 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot0_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() () const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot0_method: public slot0 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot0_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() () const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(); - } -}; - - - -// -// class signal0 -// -template< typename T_return > -class signal0: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() () - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal0<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot0 pointer (converts from raw memory to pointer again) - slot0* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot0* sNewFunc = new slot0_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot0* sNewMethod = new slot0_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot0_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot0_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal0_h__ +#ifndef __signal0_h__ +#define __signal0_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot0, slot0_function, and slot0_method +// + +// +// Abstract base class for slots with 0 parameter(s). +// +template +class slot0: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() () const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot0_function: public slot0 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot0_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() () const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot0_method: public slot0 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot0_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() () const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(); + } +}; + + + +// +// class signal0 +// +template< typename T_return > +class signal0: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() () + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal0<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot0 pointer (converts from raw memory to pointer again) + slot0* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot0* sNewFunc = new slot0_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot0* sNewMethod = new slot0_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot0_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot0_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal0_h__ diff --git a/signal1.h b/signal1.h index ad250d2..7f42c14 100644 --- a/signal1.h +++ b/signal1.h @@ -1,214 +1,214 @@ -#ifndef __signal1_h__ -#define __signal1_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot1, slot1_function, and slot1_method -// - -// -// Abstract base class for slots with 1 parameter(s). -// -template -class slot1: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot1_function: public slot1 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot1_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot1_method: public slot1 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot1_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0); - } -}; - - - -// -// class signal1 -// -template< typename T_return, typename T_arg0 > -class signal1: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal1<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot1 pointer (converts from raw memory to pointer again) - slot1* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot1* sNewFunc = new slot1_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot1* sNewMethod = new slot1_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot1_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot1_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal1_h__ +#ifndef __signal1_h__ +#define __signal1_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot1, slot1_function, and slot1_method +// + +// +// Abstract base class for slots with 1 parameter(s). +// +template +class slot1: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot1_function: public slot1 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot1_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot1_method: public slot1 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot1_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0); + } +}; + + + +// +// class signal1 +// +template< typename T_return, typename T_arg0 > +class signal1: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal1<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot1 pointer (converts from raw memory to pointer again) + slot1* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot1* sNewFunc = new slot1_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot1* sNewMethod = new slot1_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot1_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot1_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal1_h__ diff --git a/signal10.h b/signal10.h index 7a11acc..f4e8ddf 100644 --- a/signal10.h +++ b/signal10.h @@ -1,214 +1,214 @@ -#ifndef __signal10_h__ -#define __signal10_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot10, slot10_function, and slot10_method -// - -// -// Abstract base class for slots with 10 parameter(s). -// -template -class slot10: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot10_function: public slot10 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot10_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot10_method: public slot10 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot10_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); - } -}; - - - -// -// class signal10 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9 > -class signal10: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal10<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot10 pointer (converts from raw memory to pointer again) - slot10* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot10* sNewFunc = new slot10_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot10* sNewMethod = new slot10_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot10_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot10_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal10_h__ +#ifndef __signal10_h__ +#define __signal10_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot10, slot10_function, and slot10_method +// + +// +// Abstract base class for slots with 10 parameter(s). +// +template +class slot10: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot10_function: public slot10 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot10_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot10_method: public slot10 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot10_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + } +}; + + + +// +// class signal10 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9 > +class signal10: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal10<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot10 pointer (converts from raw memory to pointer again) + slot10* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot10* sNewFunc = new slot10_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot10* sNewMethod = new slot10_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot10_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot10_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal10_h__ diff --git a/signal11.h b/signal11.h index 8b9063e..c63cefc 100644 --- a/signal11.h +++ b/signal11.h @@ -1,214 +1,214 @@ -#ifndef __signal11_h__ -#define __signal11_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot11, slot11_function, and slot11_method -// - -// -// Abstract base class for slots with 11 parameter(s). -// -template -class slot11: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot11_function: public slot11 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot11_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot11_method: public slot11 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot11_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); - } -}; - - - -// -// class signal11 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10 > -class signal11: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal11<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot11 pointer (converts from raw memory to pointer again) - slot11* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot11* sNewFunc = new slot11_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot11* sNewMethod = new slot11_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot11_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot11_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal11_h__ +#ifndef __signal11_h__ +#define __signal11_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot11, slot11_function, and slot11_method +// + +// +// Abstract base class for slots with 11 parameter(s). +// +template +class slot11: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot11_function: public slot11 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot11_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot11_method: public slot11 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot11_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + } +}; + + + +// +// class signal11 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10 > +class signal11: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal11<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot11 pointer (converts from raw memory to pointer again) + slot11* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot11* sNewFunc = new slot11_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot11* sNewMethod = new slot11_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot11_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot11_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal11_h__ diff --git a/signal12.h b/signal12.h index ee20e26..0b984ab 100644 --- a/signal12.h +++ b/signal12.h @@ -1,214 +1,214 @@ -#ifndef __signal12_h__ -#define __signal12_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot12, slot12_function, and slot12_method -// - -// -// Abstract base class for slots with 12 parameter(s). -// -template -class slot12: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot12_function: public slot12 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot12_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot12_method: public slot12 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot12_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); - } -}; - - - -// -// class signal12 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11 > -class signal12: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal12<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot12 pointer (converts from raw memory to pointer again) - slot12* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot12* sNewFunc = new slot12_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot12* sNewMethod = new slot12_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot12_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot12_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal12_h__ +#ifndef __signal12_h__ +#define __signal12_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot12, slot12_function, and slot12_method +// + +// +// Abstract base class for slots with 12 parameter(s). +// +template +class slot12: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot12_function: public slot12 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot12_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot12_method: public slot12 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot12_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); + } +}; + + + +// +// class signal12 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11 > +class signal12: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal12<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot12 pointer (converts from raw memory to pointer again) + slot12* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot12* sNewFunc = new slot12_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot12* sNewMethod = new slot12_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot12_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot12_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal12_h__ diff --git a/signal13.h b/signal13.h index 84c8c0f..1d0e937 100644 --- a/signal13.h +++ b/signal13.h @@ -1,214 +1,214 @@ -#ifndef __signal13_h__ -#define __signal13_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot13, slot13_function, and slot13_method -// - -// -// Abstract base class for slots with 13 parameter(s). -// -template -class slot13: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot13_function: public slot13 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot13_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot13_method: public slot13 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot13_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); - } -}; - - - -// -// class signal13 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12 > -class signal13: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal13<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot13 pointer (converts from raw memory to pointer again) - slot13* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot13* sNewFunc = new slot13_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot13* sNewMethod = new slot13_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot13_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot13_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal13_h__ +#ifndef __signal13_h__ +#define __signal13_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot13, slot13_function, and slot13_method +// + +// +// Abstract base class for slots with 13 parameter(s). +// +template +class slot13: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot13_function: public slot13 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot13_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot13_method: public slot13 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot13_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); + } +}; + + + +// +// class signal13 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12 > +class signal13: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal13<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot13 pointer (converts from raw memory to pointer again) + slot13* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot13* sNewFunc = new slot13_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot13* sNewMethod = new slot13_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot13_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot13_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal13_h__ diff --git a/signal14.h b/signal14.h index 4bf146a..8227c05 100644 --- a/signal14.h +++ b/signal14.h @@ -1,214 +1,214 @@ -#ifndef __signal14_h__ -#define __signal14_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot14, slot14_function, and slot14_method -// - -// -// Abstract base class for slots with 14 parameter(s). -// -template -class slot14: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot14_function: public slot14 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot14_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot14_method: public slot14 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot14_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); - } -}; - - - -// -// class signal14 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12, typename T_arg13 > -class signal14: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal14<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot14 pointer (converts from raw memory to pointer again) - slot14* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot14* sNewFunc = new slot14_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot14* sNewMethod = new slot14_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot14_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot14_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal14_h__ +#ifndef __signal14_h__ +#define __signal14_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot14, slot14_function, and slot14_method +// + +// +// Abstract base class for slots with 14 parameter(s). +// +template +class slot14: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot14_function: public slot14 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot14_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot14_method: public slot14 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot14_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); + } +}; + + + +// +// class signal14 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12, typename T_arg13 > +class signal14: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal14<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot14 pointer (converts from raw memory to pointer again) + slot14* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot14* sNewFunc = new slot14_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot14* sNewMethod = new slot14_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot14_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot14_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal14_h__ diff --git a/signal15.h b/signal15.h index a2c1f7a..70d03e6 100644 --- a/signal15.h +++ b/signal15.h @@ -1,214 +1,214 @@ -#ifndef __signal15_h__ -#define __signal15_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot15, slot15_function, and slot15_method -// - -// -// Abstract base class for slots with 15 parameter(s). -// -template -class slot15: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot15_function: public slot15 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot15_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot15_method: public slot15 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot15_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); - } -}; - - - -// -// class signal15 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12, typename T_arg13, typename T_arg14 > -class signal15: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal15<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot15 pointer (converts from raw memory to pointer again) - slot15* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot15* sNewFunc = new slot15_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot15* sNewMethod = new slot15_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot15_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot15_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal15_h__ +#ifndef __signal15_h__ +#define __signal15_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot15, slot15_function, and slot15_method +// + +// +// Abstract base class for slots with 15 parameter(s). +// +template +class slot15: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot15_function: public slot15 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot15_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot15_method: public slot15 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot15_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); + } +}; + + + +// +// class signal15 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12, typename T_arg13, typename T_arg14 > +class signal15: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal15<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot15 pointer (converts from raw memory to pointer again) + slot15* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot15* sNewFunc = new slot15_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot15* sNewMethod = new slot15_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot15_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot15_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal15_h__ diff --git a/signal16.h b/signal16.h index 85e11b5..3d7b681 100644 --- a/signal16.h +++ b/signal16.h @@ -1,214 +1,214 @@ -#ifndef __signal16_h__ -#define __signal16_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot16, slot16_function, and slot16_method -// - -// -// Abstract base class for slots with 16 parameter(s). -// -template -class slot16: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot16_function: public slot16 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot16_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot16_method: public slot16 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot16_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); - } -}; - - - -// -// class signal16 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12, typename T_arg13, typename T_arg14, typename T_arg15 > -class signal16: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal16<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot16 pointer (converts from raw memory to pointer again) - slot16* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot16* sNewFunc = new slot16_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot16* sNewMethod = new slot16_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot16_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot16_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal16_h__ +#ifndef __signal16_h__ +#define __signal16_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot16, slot16_function, and slot16_method +// + +// +// Abstract base class for slots with 16 parameter(s). +// +template +class slot16: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot16_function: public slot16 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot16_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot16_method: public slot16 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot16_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); + } +}; + + + +// +// class signal16 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8, typename T_arg9, typename T_arg10, typename T_arg11, typename T_arg12, typename T_arg13, typename T_arg14, typename T_arg15 > +class signal16: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal16<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot16 pointer (converts from raw memory to pointer again) + slot16* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8, T_arg9 a9, T_arg10 a10, T_arg11 a11, T_arg12 a12, T_arg13 a13, T_arg14 a14, T_arg15 a15); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot16* sNewFunc = new slot16_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot16* sNewMethod = new slot16_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot16_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot16_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal16_h__ diff --git a/signal2.h b/signal2.h index 4e9ab8c..b9c7133 100644 --- a/signal2.h +++ b/signal2.h @@ -1,214 +1,214 @@ -#ifndef __signal2_h__ -#define __signal2_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot2, slot2_function, and slot2_method -// - -// -// Abstract base class for slots with 2 parameter(s). -// -template -class slot2: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot2_function: public slot2 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot2_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot2_method: public slot2 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot2_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1); - } -}; - - - -// -// class signal2 -// -template< typename T_return, typename T_arg0, typename T_arg1 > -class signal2: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal2<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot2 pointer (converts from raw memory to pointer again) - slot2* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot2* sNewFunc = new slot2_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot2* sNewMethod = new slot2_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot2_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot2_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal2_h__ +#ifndef __signal2_h__ +#define __signal2_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot2, slot2_function, and slot2_method +// + +// +// Abstract base class for slots with 2 parameter(s). +// +template +class slot2: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot2_function: public slot2 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot2_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot2_method: public slot2 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot2_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1); + } +}; + + + +// +// class signal2 +// +template< typename T_return, typename T_arg0, typename T_arg1 > +class signal2: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal2<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot2 pointer (converts from raw memory to pointer again) + slot2* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot2* sNewFunc = new slot2_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot2* sNewMethod = new slot2_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot2_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot2_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal2_h__ diff --git a/signal3.h b/signal3.h index d18a84a..be75060 100644 --- a/signal3.h +++ b/signal3.h @@ -1,214 +1,214 @@ -#ifndef __signal3_h__ -#define __signal3_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot3, slot3_function, and slot3_method -// - -// -// Abstract base class for slots with 3 parameter(s). -// -template -class slot3: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot3_function: public slot3 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot3_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot3_method: public slot3 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot3_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2); - } -}; - - - -// -// class signal3 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2 > -class signal3: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal3<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot3 pointer (converts from raw memory to pointer again) - slot3* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot3* sNewFunc = new slot3_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot3* sNewMethod = new slot3_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot3_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot3_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal3_h__ +#ifndef __signal3_h__ +#define __signal3_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot3, slot3_function, and slot3_method +// + +// +// Abstract base class for slots with 3 parameter(s). +// +template +class slot3: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot3_function: public slot3 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot3_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot3_method: public slot3 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot3_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2); + } +}; + + + +// +// class signal3 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2 > +class signal3: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal3<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot3 pointer (converts from raw memory to pointer again) + slot3* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot3* sNewFunc = new slot3_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot3* sNewMethod = new slot3_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot3_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot3_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal3_h__ diff --git a/signal4.h b/signal4.h index e1d049d..eda0548 100644 --- a/signal4.h +++ b/signal4.h @@ -1,214 +1,214 @@ -#ifndef __signal4_h__ -#define __signal4_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot4, slot4_function, and slot4_method -// - -// -// Abstract base class for slots with 4 parameter(s). -// -template -class slot4: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot4_function: public slot4 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot4_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot4_method: public slot4 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot4_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3); - } -}; - - - -// -// class signal4 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3 > -class signal4: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal4<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot4 pointer (converts from raw memory to pointer again) - slot4* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot4* sNewFunc = new slot4_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot4* sNewMethod = new slot4_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot4_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot4_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal4_h__ +#ifndef __signal4_h__ +#define __signal4_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot4, slot4_function, and slot4_method +// + +// +// Abstract base class for slots with 4 parameter(s). +// +template +class slot4: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot4_function: public slot4 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot4_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot4_method: public slot4 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot4_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3); + } +}; + + + +// +// class signal4 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3 > +class signal4: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal4<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot4 pointer (converts from raw memory to pointer again) + slot4* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot4* sNewFunc = new slot4_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot4* sNewMethod = new slot4_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot4_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot4_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal4_h__ diff --git a/signal5.h b/signal5.h index a25900a..907a097 100644 --- a/signal5.h +++ b/signal5.h @@ -1,214 +1,214 @@ -#ifndef __signal5_h__ -#define __signal5_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot5, slot5_function, and slot5_method -// - -// -// Abstract base class for slots with 5 parameter(s). -// -template -class slot5: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot5_function: public slot5 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot5_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot5_method: public slot5 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot5_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4); - } -}; - - - -// -// class signal5 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 > -class signal5: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal5<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot5 pointer (converts from raw memory to pointer again) - slot5* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot5* sNewFunc = new slot5_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot5* sNewMethod = new slot5_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot5_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot5_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal5_h__ +#ifndef __signal5_h__ +#define __signal5_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot5, slot5_function, and slot5_method +// + +// +// Abstract base class for slots with 5 parameter(s). +// +template +class slot5: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot5_function: public slot5 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot5_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot5_method: public slot5 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot5_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4); + } +}; + + + +// +// class signal5 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4 > +class signal5: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal5<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot5 pointer (converts from raw memory to pointer again) + slot5* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot5* sNewFunc = new slot5_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot5* sNewMethod = new slot5_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot5_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot5_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal5_h__ diff --git a/signal6.h b/signal6.h index fdf6b0c..62063f4 100644 --- a/signal6.h +++ b/signal6.h @@ -1,214 +1,214 @@ -#ifndef __signal6_h__ -#define __signal6_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot6, slot6_function, and slot6_method -// - -// -// Abstract base class for slots with 6 parameter(s). -// -template -class slot6: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot6_function: public slot6 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot6_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot6_method: public slot6 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot6_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5); - } -}; - - - -// -// class signal6 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 > -class signal6: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal6<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot6 pointer (converts from raw memory to pointer again) - slot6* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot6* sNewFunc = new slot6_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot6* sNewMethod = new slot6_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot6_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot6_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal6_h__ +#ifndef __signal6_h__ +#define __signal6_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot6, slot6_function, and slot6_method +// + +// +// Abstract base class for slots with 6 parameter(s). +// +template +class slot6: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot6_function: public slot6 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot6_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot6_method: public slot6 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot6_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5); + } +}; + + + +// +// class signal6 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5 > +class signal6: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal6<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot6 pointer (converts from raw memory to pointer again) + slot6* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot6* sNewFunc = new slot6_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot6* sNewMethod = new slot6_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot6_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot6_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal6_h__ diff --git a/signal7.h b/signal7.h index c959b10..8ea1987 100644 --- a/signal7.h +++ b/signal7.h @@ -1,214 +1,214 @@ -#ifndef __signal7_h__ -#define __signal7_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot7, slot7_function, and slot7_method -// - -// -// Abstract base class for slots with 7 parameter(s). -// -template -class slot7: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot7_function: public slot7 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot7_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot7_method: public slot7 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot7_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6); - } -}; - - - -// -// class signal7 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 > -class signal7: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal7<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot7 pointer (converts from raw memory to pointer again) - slot7* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot7* sNewFunc = new slot7_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot7* sNewMethod = new slot7_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot7_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot7_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal7_h__ +#ifndef __signal7_h__ +#define __signal7_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot7, slot7_function, and slot7_method +// + +// +// Abstract base class for slots with 7 parameter(s). +// +template +class slot7: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot7_function: public slot7 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot7_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot7_method: public slot7 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot7_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6); + } +}; + + + +// +// class signal7 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6 > +class signal7: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal7<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot7 pointer (converts from raw memory to pointer again) + slot7* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot7* sNewFunc = new slot7_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot7* sNewMethod = new slot7_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot7_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot7_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal7_h__ diff --git a/signal8.h b/signal8.h index 2ba0f08..fd6755c 100644 --- a/signal8.h +++ b/signal8.h @@ -1,214 +1,214 @@ -#ifndef __signal8_h__ -#define __signal8_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot8, slot8_function, and slot8_method -// - -// -// Abstract base class for slots with 8 parameter(s). -// -template -class slot8: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot8_function: public slot8 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot8_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot8_method: public slot8 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot8_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7); - } -}; - - - -// -// class signal8 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 > -class signal8: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal8<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot8 pointer (converts from raw memory to pointer again) - slot8* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot8* sNewFunc = new slot8_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot8* sNewMethod = new slot8_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot8_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot8_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal8_h__ +#ifndef __signal8_h__ +#define __signal8_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot8, slot8_function, and slot8_method +// + +// +// Abstract base class for slots with 8 parameter(s). +// +template +class slot8: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot8_function: public slot8 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot8_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot8_method: public slot8 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot8_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7); + } +}; + + + +// +// class signal8 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7 > +class signal8: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal8<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot8 pointer (converts from raw memory to pointer again) + slot8* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot8* sNewFunc = new slot8_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot8* sNewMethod = new slot8_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot8_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot8_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal8_h__ diff --git a/signal9.h b/signal9.h index d1f5cfe..b8de45d 100644 --- a/signal9.h +++ b/signal9.h @@ -1,214 +1,214 @@ -#ifndef __signal9_h__ -#define __signal9_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot9, slot9_function, and slot9_method -// - -// -// Abstract base class for slots with 9 parameter(s). -// -template -class slot9: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot9_function: public slot9 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot9_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(a0, a1, a2, a3, a4, a5, a6, a7, a8); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot9_method: public slot9 -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot9_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8); - } -}; - - - -// -// class signal9 -// -template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8 > -class signal9: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal9<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot9 pointer (converts from raw memory to pointer again) - slot9* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot9* sNewFunc = new slot9_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot9* sNewMethod = new slot9_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot9_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot9_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal9_h__ +#ifndef __signal9_h__ +#define __signal9_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot9, slot9_function, and slot9_method +// + +// +// Abstract base class for slots with 9 parameter(s). +// +template +class slot9: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot9_function: public slot9 +{ + public: + + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot9_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(a0, a1, a2, a3, a4, a5, a6, a7, a8); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot9_method: public slot9 +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot9_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(a0, a1, a2, a3, a4, a5, a6, a7, a8); + } +}; + + + +// +// class signal9 +// +template< typename T_return, typename T_arg0, typename T_arg1, typename T_arg2, typename T_arg3, typename T_arg4, typename T_arg5, typename T_arg6, typename T_arg7, typename T_arg8 > +class signal9: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal9<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot9 pointer (converts from raw memory to pointer again) + slot9* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(a0, a1, a2, a3, a4, a5, a6, a7, a8); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(T_arg0 a0, T_arg1 a1, T_arg2 a2, T_arg3 a3, T_arg4 a4, T_arg5 a5, T_arg6 a6, T_arg7 a7, T_arg8 a8); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot9* sNewFunc = new slot9_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot9* sNewMethod = new slot9_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot9_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot9_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal9_h__ diff --git a/signal_base.cpp b/signal_base.cpp index 3432518..e8f91f4 100644 --- a/signal_base.cpp +++ b/signal_base.cpp @@ -1,228 +1,228 @@ -#include -#include "signal_base.h" - - -signal_base::signal_base() : head(0), tail(0), emitting(false) -{ - // empty -} - -signal_base::~signal_base() -{ - // clear the list - clear_list(); -} - -signal_base::signal_base( const signal_base& rSource ) : head(0), tail(0), emitting(false) -{ - // Set an assert to let the user know that we don't support signal copying. - // There are too many places where the signals are directly connected to objects, - // where copying them would create a disconnect between the signal and the objects - // that want to react to the signal execution. - assert( 0 ); -} - -signal_base& signal_base::operator=( const signal_base& rSource ) -{ - // Set an assert to let the user know that we don't support signal copying. - // There are too many places where the signals are directly connected to objects, - // where copying them would create a disconnect between the signal and the objects - // that want to react to the signal execution. - assert( 0 ); - return *this; -} - -int signal_base::count( void ) -{ - int count = 0; - list_node* cur = head; - - while( cur ) - { - cur = cur->next; - count++; - } - - return count; -} - -bool signal_base::bind(slot_base* slot) -{ - // add it to our signal list - return add_to_list(slot); -} - -bool signal_base::unbind(slot_base* slot) -{ - // look for corresponding list_node in list - list_node* n = find_in_list(slot); - - // see if we found a match - if( n ) - { - // If we are not processing a signal emit sequence, then release the node. - if( !emitting ) - { - // take it out of the linked list - remove_from_list(n); - - // found a match, return success - return true; - } - // Otherwise mark it for removal. - else - { - n->deleted = true; - return true; - } - } - - // no match - return false; -} - -signal_base::list_node::list_node(slot_base* s) : slot(s), prev(0), next(0), deleted(false) -{ - // empty -} - -signal_base::list_node::~list_node() -{ - // release the slot - delete slot; -} - - -void signal_base::clear_list() -{ - // start at head - list_node* cur = head; - - // iterate - while ( cur ) - { - // save off next so we can safely delete - list_node* next = cur->next; - - // free - delete cur; - - // advance - cur = next; - } - - // reset head & tail - head = tail = 0; -} - -signal_base::list_node* signal_base::find_in_list(slot_base* slot) const -{ - // start search at head of list - list_node* cur = head; - - // search list for slot - while ( cur ) - { - // see if this is a match - if ( *(cur->slot) == *(slot) ) // note comparing values, not addresses !!! - { - // we have a match, return it - return cur; - } - - // advance to next in list - cur = cur->next; - } - - // no match - return 0; -} - -bool signal_base::add_to_list(slot_base* slot) -{ - // a sanity check - assert((head && tail) || (!head && !tail)); - - // make a new list_node to hold this slot in the list - // and initialize with this slot pointer - list_node* node = new list_node(slot); - assert(node); - if ( !node ) - { - return false; - } - - // setup new list_node - node->prev = tail; // prev is tail because we'll put this list_node behind it (i.e. the new tail) - node->next = 0; // next is 0 because we'll put this list_node on the tail - - // add to tail - if ( tail ) - { - // tail exists, just append - tail->next = node; // insert item after current tail - tail = node; // now have a new tail - } - else - { - // list is currently empty, add this new list_node - head = tail = node; // now have a single list_node, which is also both the head and tail - } - - return true; -} - -void signal_base::remove_from_list(list_node* n) -{ - // do a little sanity checking - assert((head && tail) || (!head && !tail)); - assert(n->prev == 0 || n->prev->next == n); - assert(n->next == 0 || n->next->prev == n); - - // if this is the head, set the new head - if ( n == head ) - { - head = n->next; - } - - // if this is the tail, set the new tail - if ( n == tail ) - { - tail = n->prev; - } - - // set list to skip over this list_node - if ( n->prev ) - { - n->prev->next = n->next; - } - if ( n->next ) - { - n->next->prev = n->prev; - } - - // finally, destroy the node - delete n; -} - -void signal_base::remove_pending_nodes( void ) -{ - list_node* cur = head; - list_node* next; - - while( cur ) - { - // Prepare the next link in the list the removal stage. - next = cur->next; - - // Do we need to remove this link. - if( cur->deleted ) - { - remove_from_list( cur ); - } - - // Go to the next item. - cur = next; - } -} - +#include +#include "signal_base.h" + + +signal_base::signal_base() : head(0), tail(0), emitting(false) +{ + // empty +} + +signal_base::~signal_base() +{ + // clear the list + clear_list(); +} + +signal_base::signal_base( const signal_base& rSource ) : head(0), tail(0), emitting(false) +{ + // Set an assert to let the user know that we don't support signal copying. + // There are too many places where the signals are directly connected to objects, + // where copying them would create a disconnect between the signal and the objects + // that want to react to the signal execution. + assert( 0 ); +} + +signal_base& signal_base::operator=( const signal_base& rSource ) +{ + // Set an assert to let the user know that we don't support signal copying. + // There are too many places where the signals are directly connected to objects, + // where copying them would create a disconnect between the signal and the objects + // that want to react to the signal execution. + assert( 0 ); + return *this; +} + +int signal_base::count( void ) +{ + int count = 0; + list_node* cur = head; + + while( cur ) + { + cur = cur->next; + count++; + } + + return count; +} + +bool signal_base::bind(slot_base* slot) +{ + // add it to our signal list + return add_to_list(slot); +} + +bool signal_base::unbind(slot_base* slot) +{ + // look for corresponding list_node in list + list_node* n = find_in_list(slot); + + // see if we found a match + if( n ) + { + // If we are not processing a signal emit sequence, then release the node. + if( !emitting ) + { + // take it out of the linked list + remove_from_list(n); + + // found a match, return success + return true; + } + // Otherwise mark it for removal. + else + { + n->deleted = true; + return true; + } + } + + // no match + return false; +} + +signal_base::list_node::list_node(slot_base* s) : slot(s), prev(0), next(0), deleted(false) +{ + // empty +} + +signal_base::list_node::~list_node() +{ + // release the slot + delete slot; +} + + +void signal_base::clear_list() +{ + // start at head + list_node* cur = head; + + // iterate + while ( cur ) + { + // save off next so we can safely delete + list_node* next = cur->next; + + // free + delete cur; + + // advance + cur = next; + } + + // reset head & tail + head = tail = 0; +} + +signal_base::list_node* signal_base::find_in_list(slot_base* slot) const +{ + // start search at head of list + list_node* cur = head; + + // search list for slot + while ( cur ) + { + // see if this is a match + if ( *(cur->slot) == *(slot) ) // note comparing values, not addresses !!! + { + // we have a match, return it + return cur; + } + + // advance to next in list + cur = cur->next; + } + + // no match + return 0; +} + +bool signal_base::add_to_list(slot_base* slot) +{ + // a sanity check + assert((head && tail) || (!head && !tail)); + + // make a new list_node to hold this slot in the list + // and initialize with this slot pointer + list_node* node = new list_node(slot); + assert(node); + if ( !node ) + { + return false; + } + + // setup new list_node + node->prev = tail; // prev is tail because we'll put this list_node behind it (i.e. the new tail) + node->next = 0; // next is 0 because we'll put this list_node on the tail + + // add to tail + if ( tail ) + { + // tail exists, just append + tail->next = node; // insert item after current tail + tail = node; // now have a new tail + } + else + { + // list is currently empty, add this new list_node + head = tail = node; // now have a single list_node, which is also both the head and tail + } + + return true; +} + +void signal_base::remove_from_list(list_node* n) +{ + // do a little sanity checking + assert((head && tail) || (!head && !tail)); + assert(n->prev == 0 || n->prev->next == n); + assert(n->next == 0 || n->next->prev == n); + + // if this is the head, set the new head + if ( n == head ) + { + head = n->next; + } + + // if this is the tail, set the new tail + if ( n == tail ) + { + tail = n->prev; + } + + // set list to skip over this list_node + if ( n->prev ) + { + n->prev->next = n->next; + } + if ( n->next ) + { + n->next->prev = n->prev; + } + + // finally, destroy the node + delete n; +} + +void signal_base::remove_pending_nodes( void ) +{ + list_node* cur = head; + list_node* next; + + while( cur ) + { + // Prepare the next link in the list the removal stage. + next = cur->next; + + // Do we need to remove this link. + if( cur->deleted ) + { + remove_from_list( cur ); + } + + // Go to the next item. + cur = next; + } +} + diff --git a/signal_base.h b/signal_base.h index b0f2d13..cc6f42e 100644 --- a/signal_base.h +++ b/signal_base.h @@ -1,117 +1,117 @@ -#ifndef __signal_base_h__ -#define __signal_base_h__ - -#include "slot_base.h" - - -/** - * ----------------------------------------------------------------------------------------------------------------------------------------- - * Signals - An elegant system of that manages software events and the callbacks that respond to them. - * ----------------------------------------------------------------------------------------------------------------------------------------- - * - * Each discrete signal represents a moment within your application that might require some reaction. A signal might represent a - * basketball going through the basket, or hitting the ground. Another signal might identify when a bullet was fired out of a gun. - * There is no limit to what the signal represents. - * - * The reactions that need to be processed through the signal system are called "Slots". Slots are nothing more than a common interface - * that the Signal can use to call many variations of callbacks with a single interface. Some have labelled slots as "Delegates" as they are - * not the actual code that performs the reaction, but instead are used to translate the common reaction request into the actual callback that - * is desired. Please see slot_base.h for more information. - * - */ -class signal_base -{ - public: - - signal_base(); - virtual ~signal_base(); - - signal_base( const signal_base& rSource ); - signal_base& operator=( const signal_base& rSource ); - - /** - * Determines the number of slots that are connected to the signal. - */ - int count( void ); - - protected: - // linked list data structure - // used to maintain a list of pointers to slot_base.. no memory management is - // performed on the slot_base data - derived class should take care of this. - struct list_node - { - list_node(slot_base* s); - ~list_node(); - - slot_base* slot; - list_node* prev; - list_node* next; - - bool deleted; - }; - - /** - * Request to add a slot to the signals reaction list that is processed when a signal is executed. - * - * @param slot A pointer to a slot base class that contains the required callback mechanism. - * - * @return true if the signal is able to add the slot. - * false if the signal could NOT add the slot. - */ - bool bind(slot_base* slot); - - /** - * Request to remove a slot from the signals reaction list. - * - * @param slot A pointer to a slot base class that contains the required callback mechanism. - * - * @return true if the signal is able to remove the slot. - * false if the signal could NOT remove the slot. - */ - bool unbind(slot_base* slot); - - /** - * Functions used to maintain the status of a signal. When a signal is active it means that it is "Emitting". During the emitting - * stage, we are walking the list of slots to allow each slot to react to the signal. There are special considerations that - * must be made when walking the list, such as adding or removing slots during the emit stage. - */ - - private: - /** - * Removes all slots that are connected to the signal - */ - void clear_list( ); - - /** - * Searches the slot list to find a slot that contains the same components. The location within the list is returned. - */ - list_node* find_in_list(slot_base* slot) const; - - /** - * Performs the actual operation of adding the slot to signal's internal list. - */ - bool add_to_list(slot_base* slot); - - /** - * Performs the actual operation of removing the slot from the signal's internal list. - */ - void remove_from_list(list_node* n); - - protected: - - /** - * Removes any nodes that were tagged for deletion during the signal emit sequence - */ - void remove_pending_nodes( void ); - - //----------------------------------------------------------------------------------------------------------------------------------------- - protected: - - list_node* head; - list_node* tail; - - bool emitting; -}; - -#endif // __signal_base_h__ - +#ifndef __signal_base_h__ +#define __signal_base_h__ + +#include "slot_base.h" + + +/** + * ----------------------------------------------------------------------------------------------------------------------------------------- + * Signals - An elegant system of that manages software events and the callbacks that respond to them. + * ----------------------------------------------------------------------------------------------------------------------------------------- + * + * Each discrete signal represents a moment within your application that might require some reaction. A signal might represent a + * basketball going through the basket, or hitting the ground. Another signal might identify when a bullet was fired out of a gun. + * There is no limit to what the signal represents. + * + * The reactions that need to be processed through the signal system are called "Slots". Slots are nothing more than a common interface + * that the Signal can use to call many variations of callbacks with a single interface. Some have labelled slots as "Delegates" as they are + * not the actual code that performs the reaction, but instead are used to translate the common reaction request into the actual callback that + * is desired. Please see slot_base.h for more information. + * + */ +class signal_base +{ + public: + + signal_base(); + virtual ~signal_base(); + + signal_base( const signal_base& rSource ); + signal_base& operator=( const signal_base& rSource ); + + /** + * Determines the number of slots that are connected to the signal. + */ + int count( void ); + + protected: + // linked list data structure + // used to maintain a list of pointers to slot_base.. no memory management is + // performed on the slot_base data - derived class should take care of this. + struct list_node + { + list_node(slot_base* s); + ~list_node(); + + slot_base* slot; + list_node* prev; + list_node* next; + + bool deleted; + }; + + /** + * Request to add a slot to the signals reaction list that is processed when a signal is executed. + * + * @param slot A pointer to a slot base class that contains the required callback mechanism. + * + * @return true if the signal is able to add the slot. + * false if the signal could NOT add the slot. + */ + bool bind(slot_base* slot); + + /** + * Request to remove a slot from the signals reaction list. + * + * @param slot A pointer to a slot base class that contains the required callback mechanism. + * + * @return true if the signal is able to remove the slot. + * false if the signal could NOT remove the slot. + */ + bool unbind(slot_base* slot); + + /** + * Functions used to maintain the status of a signal. When a signal is active it means that it is "Emitting". During the emitting + * stage, we are walking the list of slots to allow each slot to react to the signal. There are special considerations that + * must be made when walking the list, such as adding or removing slots during the emit stage. + */ + + private: + /** + * Removes all slots that are connected to the signal + */ + void clear_list( ); + + /** + * Searches the slot list to find a slot that contains the same components. The location within the list is returned. + */ + list_node* find_in_list(slot_base* slot) const; + + /** + * Performs the actual operation of adding the slot to signal's internal list. + */ + bool add_to_list(slot_base* slot); + + /** + * Performs the actual operation of removing the slot from the signal's internal list. + */ + void remove_from_list(list_node* n); + + protected: + + /** + * Removes any nodes that were tagged for deletion during the signal emit sequence + */ + void remove_pending_nodes( void ); + + //----------------------------------------------------------------------------------------------------------------------------------------- + protected: + + list_node* head; + list_node* tail; + + bool emitting; +}; + +#endif // __signal_base_h__ + diff --git a/signal_template.h b/signal_template.h index 0f64345..aaaabb0 100644 --- a/signal_template.h +++ b/signal_template.h @@ -1,214 +1,214 @@ -#ifndef __signal===NARG===_h__ -#define __signal===NARG===_h__ - -#include "horrible_cast.h" -#include "slot_base.h" -#include "signal_base.h" - - - -// -// classes slot===NARG===, slot===NARG===_function, and slot===NARG===_method -// - -// -// Abstract base class for slots with ===NARG=== parameter(s). -// -template -class slot===NARG===: public slot_base -{ - public: - /** - * Method which performs the actual callback. Must be overridden. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - virtual T_return operator() (===FORMAL_ARG_DECL===) const = 0; -}; - -// -// A concrete slot class for a normal function. -// -template -class slot===NARG===_function: public slot===NARG=== -{ - public: - - typedef T_return (*FUNCTION_POINTER)(===FORMAL_ARG_DECL===); // convenience typedef - - /** - * Constructor. - * - * Converts a function pointer into raw data. - */ - slot===NARG===_function( const FUNCTION_POINTER func ) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - /** - * Perform callback. - * - * Converts raw data back into a function pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (===FORMAL_ARG_DECL===) const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - return func(===FORMAL_ARG===); - } -}; - -// -// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). -// -template -class slot===NARG===_method: public slot===NARG=== -{ - public: - - /** - * Constructor. - * - * Converts an object and method pointer into raw data. - */ - slot===NARG===_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - /** - * Perform callback. - * - * Converts raw data back into a method pointer, and calls it. - * - * @return Returns an object of type T_return; the result of the user callback. - */ - T_return operator() (===FORMAL_ARG_DECL===) const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - return (p_object->*p_member)(===FORMAL_ARG===); - } -}; - - - -// -// class signal===NARG=== -// -template< typename T_return===TEMPLATE_ARG_DECL=== > -class signal===NARG===: public signal_base -{ - public: - - /** - * Emit the signal. - * - * Iterate through the list of slots, and call each one. - */ - void operator() (===FORMAL_ARG_DECL===) - { - // if we're already emitting, return (i.e. no re-entrancy allowed) - if( signal_base::emitting ) - { -#if defined( _DEBUG ) - printf("WARNING: signal===NARG===<...> @ 0x%p recursive emit attempt\n", this); -#endif - return; - } - - // set emitting flag - signal_base::emitting = true; - - // iterate through the list - signal_base::list_node* cur = signal_base::head; - while( cur ) - { - // cast the slot_base pointer to a slot===NARG=== pointer (converts from raw memory to pointer again) - slot===NARG===* s = static_cast*>(cur->slot); - - // call the signal as long as it's still valid - if ( !cur->deleted ) - { - (*s)(===FORMAL_ARG===); - } - - // move to next slot in the list. - cur = cur->next; - } - - // delete any pending slot deletions - signal_base::remove_pending_nodes( ); - - // clear emitting flag - signal_base::emitting = false; - } - - - // - // signal connections to slots - // - - // convenience typedef - typedef T_return (*FUNCTION_POINTER)(===FORMAL_ARG_DECL===); - - // connect to normal functions - bool connect( FUNCTION_POINTER func ) - { - // make a copy of the slot to store in our list - slot===NARG===* sNewFunc = new slot===NARG===_function( func ); - - // add it to the end of our linked list - return signal_base::bind(sNewFunc); - } - - // connect to an object's method - template - bool connect(T_object* p_object, T_member p_member) - { - // make a copy of the slot to store in our list - slot===NARG===* sNewMethod = new slot===NARG===_method( p_object, p_member ); - - // add it to the end of our linked list - return signal_base::bind(sNewMethod); - } - - - // - // signal disconnections from slots - // - - // disconnect from a normal function - bool disconnect( FUNCTION_POINTER func ) - { - // make a temporary slot we can use to find a match in the list - slot===NARG===_function sTest( func ); - - // search and remove it - return signal_base::unbind(&sTest); - } - - // disconnect from an object's method - template - bool disconnect(T_object* p_object, T_member p_member) - { - // make a temporary slot we can use to find a match in the list - slot===NARG===_method sTemp(p_object,p_member); - - // search and remove it - return signal_base::unbind(&sTemp); - } -}; - -#endif // __signal===NARG===_h__ +#ifndef __signal===NARG===_h__ +#define __signal===NARG===_h__ + +#include "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + + +// +// classes slot===NARG===, slot===NARG===_function, and slot===NARG===_method +// + +// +// Abstract base class for slots with ===NARG=== parameter(s). +// +template +class slot===NARG===: public slot_base +{ + public: + /** + * Method which performs the actual callback. Must be overridden. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + virtual T_return operator() (===FORMAL_ARG_DECL===) const = 0; +}; + +// +// A concrete slot class for a normal function. +// +template +class slot===NARG===_function: public slot===NARG=== +{ + public: + + typedef T_return (*FUNCTION_POINTER)(===FORMAL_ARG_DECL===); // convenience typedef + + /** + * Constructor. + * + * Converts a function pointer into raw data. + */ + slot===NARG===_function( const FUNCTION_POINTER func ) + { + // convert and store function pointer in slot_base + this->data[0] = safe_horrible_cast(func); + } + + /** + * Perform callback. + * + * Converts raw data back into a function pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (===FORMAL_ARG_DECL===) const + { + // retrieve data from slot_base and convert back to a function pointer + FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); + + // call function + return func(===FORMAL_ARG===); + } +}; + +// +// A concrete slot class for an object pointer and method (usually 'this' and 'Class::Method'). +// +template +class slot===NARG===_method: public slot===NARG=== +{ + public: + + /** + * Constructor. + * + * Converts an object and method pointer into raw data. + */ + slot===NARG===_method(const T_object* p_object, const T_member p_member) + { + // convert and store object pointer and member function pointer in slot_base + this->data[0] = safe_horrible_cast(p_object); + this->data[1] = safe_horrible_cast(p_member); + } + + /** + * Perform callback. + * + * Converts raw data back into a method pointer, and calls it. + * + * @return Returns an object of type T_return; the result of the user callback. + */ + T_return operator() (===FORMAL_ARG_DECL===) const + { + // retrieve data from slot_base and convert back to an object pointer and member function pointer + T_object* p_object = dangerous_horrible_cast(this->data[0]); + T_member p_member = dangerous_horrible_cast (this->data[1]); + + // call member function + return (p_object->*p_member)(===FORMAL_ARG===); + } +}; + + + +// +// class signal===NARG=== +// +template< typename T_return===TEMPLATE_ARG_DECL=== > +class signal===NARG===: public signal_base +{ + public: + + /** + * Emit the signal. + * + * Iterate through the list of slots, and call each one. + */ + void operator() (===FORMAL_ARG_DECL===) + { + // if we're already emitting, return (i.e. no re-entrancy allowed) + if( signal_base::emitting ) + { +#if defined( _DEBUG ) + printf("WARNING: signal===NARG===<...> @ 0x%p recursive emit attempt\n", this); +#endif + return; + } + + // set emitting flag + signal_base::emitting = true; + + // iterate through the list + signal_base::list_node* cur = signal_base::head; + while( cur ) + { + // cast the slot_base pointer to a slot===NARG=== pointer (converts from raw memory to pointer again) + slot===NARG===* s = static_cast*>(cur->slot); + + // call the signal as long as it's still valid + if ( !cur->deleted ) + { + (*s)(===FORMAL_ARG===); + } + + // move to next slot in the list. + cur = cur->next; + } + + // delete any pending slot deletions + signal_base::remove_pending_nodes( ); + + // clear emitting flag + signal_base::emitting = false; + } + + + // + // signal connections to slots + // + + // convenience typedef + typedef T_return (*FUNCTION_POINTER)(===FORMAL_ARG_DECL===); + + // connect to normal functions + bool connect( FUNCTION_POINTER func ) + { + // make a copy of the slot to store in our list + slot===NARG===* sNewFunc = new slot===NARG===_function( func ); + + // add it to the end of our linked list + return signal_base::bind(sNewFunc); + } + + // connect to an object's method + template + bool connect(T_object* p_object, T_member p_member) + { + // make a copy of the slot to store in our list + slot===NARG===* sNewMethod = new slot===NARG===_method( p_object, p_member ); + + // add it to the end of our linked list + return signal_base::bind(sNewMethod); + } + + + // + // signal disconnections from slots + // + + // disconnect from a normal function + bool disconnect( FUNCTION_POINTER func ) + { + // make a temporary slot we can use to find a match in the list + slot===NARG===_function sTest( func ); + + // search and remove it + return signal_base::unbind(&sTest); + } + + // disconnect from an object's method + template + bool disconnect(T_object* p_object, T_member p_member) + { + // make a temporary slot we can use to find a match in the list + slot===NARG===_method sTemp(p_object,p_member); + + // search and remove it + return signal_base::unbind(&sTemp); + } +}; + +#endif // __signal===NARG===_h__ diff --git a/slot.h b/slot.h deleted file mode 100644 index d1d49c4..0000000 --- a/slot.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef __slot_h__ -#define __slot_h__ - - -#include "slot_base.h" -#include "horrible_cast.h" - - -// TODO: do return types really matter??? -// if we get rid of them, slot0 untemplates, making signal completely untemplate as well! -// maybe signal::Emit() should simply return the number of signals it emits? - - -// -// abstract base class for a slot taking 0 arguments -// -// this is basically just slot_base with the pure virtual "operator(...)" added -// -// each derivative of this should have NO storage of its own. Instead it should -// store data in the slot_base (parent class) members 'data[]'. Use horrible_cast<>() -// to subvert C++'s type system. -// -class slot0: public slot_base -{ - public: - - virtual void operator() () const = 0; -}; - - -// -// a concrete slot class for a normal function -// -template -class slot0_function: public slot0 -{ - public: - - typedef T_return (*FUNCTION_POINTER)(); - - slot0_function(const FUNCTION_POINTER func) - { - // convert and store function pointer in slot_base - this->data[0] = safe_horrible_cast(func); - } - - void operator() () const - { - // retrieve data from slot_base and convert back to a function pointer - FUNCTION_POINTER func = dangerous_horrible_cast(this->data[0]); - - // call function - func(); - } -}; - - -// -// a concrete slot class for an object pointer and method (usually 'this' and 'Class::Method') -// -template -class slot0_method: public slot0 -{ - public: - - slot0_method(const T_object* p_object, const T_member p_member) - { - // convert and store object pointer and member function pointer in slot_base - this->data[0] = safe_horrible_cast(p_object); - this->data[1] = safe_horrible_cast(p_member); - } - - void operator() () const - { - // retrieve data from slot_base and convert back to an object pointer and member function pointer - T_object* p_object = dangerous_horrible_cast(this->data[0]); - T_member p_member = dangerous_horrible_cast (this->data[1]); - - // call member function - (p_object->*p_member)(); - } -}; - - -#endif // __slot_h__ - diff --git a/slot_base.cpp b/slot_base.cpp index ed28cf9..f916904 100644 --- a/slot_base.cpp +++ b/slot_base.cpp @@ -1,53 +1,53 @@ -#include "slot_base.h" - - -bool slot_base::data_container::operator== (const slot_base::data_container& other) const -{ - // do a wordwise comparison - for (int i=0;idata[i] != other.data[i] ) - { - return false; - } - } - - // must be a perfect match - return true; -} - -void slot_base::data_container::zero() -{ - // do a bytewise zeroing - for (int i=0;idata[i] = 0; - } -} - -slot_base::slot_base () -{ - for (int i=0;idata[i] == other.data[i]) ) - return false; - } - - // all data matched - return true; -} - +#include "slot_base.h" + + +bool slot_base::data_container::operator== (const slot_base::data_container& other) const +{ + // do a wordwise comparison + for (int i=0;idata[i] != other.data[i] ) + { + return false; + } + } + + // must be a perfect match + return true; +} + +void slot_base::data_container::zero() +{ + // do a bytewise zeroing + for (int i=0;idata[i] = 0; + } +} + +slot_base::slot_base () +{ + for (int i=0;idata[i] == other.data[i]) ) + return false; + } + + // all data matched + return true; +} + diff --git a/slot_base.h b/slot_base.h index a3670a0..261d6a9 100644 --- a/slot_base.h +++ b/slot_base.h @@ -1,43 +1,43 @@ -#ifndef __slot_base_h__ -#define __slot_base_h__ - -class slot_base -{ - public: - - slot_base (); // constructor - virtual ~slot_base (); // destructor - - bool operator== (const slot_base& other) const; - - // note: copy constructor, assignment operator not specified. use compiler-generated versions. - - protected: - - // a generic type to hold a chunk of raw data. we use it to store a pointer, virtual method function pointer, etc. - struct data_container - { - // should be at least as large as the largest type you want - // to store in one of these - enum { SIZE_IN_WORDS = 8 }; - enum { SIZE_IN_BYTES = SIZE_IN_WORDS*sizeof(unsigned int) }; - - // the actual storage space - unsigned int data[SIZE_IN_WORDS]; - - // an equality operator - bool operator== (const data_container& other) const; - - // a method to set to empty (zero) - void zero(); - }; - - // number of pointers, etc. we'll track in this class - enum { NUM_DATA_ITEMS = 2 }; - - // storage for function pointers, etc. hoisted out of derivative slots - data_container data[NUM_DATA_ITEMS]; -}; - -#endif // __slot_base_h__ - +#ifndef __slot_base_h__ +#define __slot_base_h__ + +class slot_base +{ + public: + + slot_base (); // constructor + virtual ~slot_base (); // destructor + + bool operator== (const slot_base& other) const; + + // note: copy constructor, assignment operator not specified. use compiler-generated versions. + + protected: + + // a generic type to hold a chunk of raw data. we use it to store a pointer, virtual method function pointer, etc. + struct data_container + { + // should be at least as large as the largest type you want + // to store in one of these + enum { SIZE_IN_WORDS = 8 }; + enum { SIZE_IN_BYTES = SIZE_IN_WORDS*sizeof(unsigned int) }; + + // the actual storage space + unsigned int data[SIZE_IN_WORDS]; + + // an equality operator + bool operator== (const data_container& other) const; + + // a method to set to empty (zero) + void zero(); + }; + + // number of pointers, etc. we'll track in this class + enum { NUM_DATA_ITEMS = 2 }; + + // storage for function pointers, etc. hoisted out of derivative slots + data_container data[NUM_DATA_ITEMS]; +}; + +#endif // __slot_base_h__ +