diff --git a/generate.rb b/generate.rb index 091daf4..a676a0a 100755 --- a/generate.rb +++ b/generate.rb @@ -1,10 +1,49 @@ #!/usr/bin/env ruby ############################################################## -# script to generate signal*.h files from signal_template.h +# script to generate signal.h files from signalx.h.tpl, etc. # ############################################################## -def make_header_file(nargs) +# +# configuration +# + +# maximum size signal/slot (in parameters) to generate +MaxParameters = 6 + +# +# some templates +# +Header = < -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 "horrible_cast.h" +#include "slot_base.h" +#include "signal_base.h" + + +/* + * Begin signal[X] definitions + */ + + +#ifndef __signal0_h__ +#define __signal0_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 __signal1_h__ +#define __signal1_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 __signal2_h__ +#define __signal2_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 __signal3_h__ +#define __signal3_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 __signal4_h__ +#define __signal4_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 __signal5_h__ +#define __signal5_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 __signal6_h__ +#define __signal6_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__ + +/* + * Begin signal template definitions and specilizations + */ + +struct nilarg; + +// full template for signal<> (signal<> inherits signal6<>) +template +class signal: public signal6 with 5 parameters (signal<> inherits signal5<>) +template +class signal: public signal5 { /* empty class */ }; + +// partial specialization for signal<> with 4 parameters (signal<> inherits signal4<>) +template +class signal: public signal4 { /* empty class */ }; + +// partial specialization for signal<> with 3 parameters (signal<> inherits signal3<>) +template +class signal: public signal3 { /* empty class */ }; + +// partial specialization for signal<> with 2 parameters (signal<> inherits signal2<>) +template +class signal: public signal2 { /* empty class */ }; + +// partial specialization for signal<> with 1 parameters (signal<> inherits signal1<>) +template +class signal: public signal1 { /* empty class */ }; + +// partial specialization for signal<> with 0 parameters (signal<> inherits signal0<>) +template +class signal: public signal0 { /* empty class */ }; + +#endif // __signal_h__ diff --git a/signal0.h b/signal0.h deleted file mode 100644 index b0c088a..0000000 --- a/signal0.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 7f42c14..0000000 --- a/signal1.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index f4e8ddf..0000000 --- a/signal10.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index c63cefc..0000000 --- a/signal11.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 0b984ab..0000000 --- a/signal12.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 1d0e937..0000000 --- a/signal13.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 8227c05..0000000 --- a/signal14.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 70d03e6..0000000 --- a/signal15.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 3d7b681..0000000 --- a/signal16.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index b9c7133..0000000 --- a/signal2.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index be75060..0000000 --- a/signal3.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index eda0548..0000000 --- a/signal4.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 907a097..0000000 --- a/signal5.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 62063f4..0000000 --- a/signal6.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index 8ea1987..0000000 --- a/signal7.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index fd6755c..0000000 --- a/signal8.h +++ /dev/null @@ -1,214 +0,0 @@ -#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 deleted file mode 100644 index b8de45d..0000000 --- a/signal9.h +++ /dev/null @@ -1,214 +0,0 @@ -#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_template.h b/signalx.h.tpl similarity index 98% rename from signal_template.h rename to signalx.h.tpl index aaaabb0..fcb04b8 100644 --- a/signal_template.h +++ b/signalx.h.tpl @@ -1,12 +1,7 @@ + #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 // @@ -212,3 +207,4 @@ class signal===NARG===: public signal_base }; #endif // __signal===NARG===_h__ +