#ifndef __Signal14_h__ #define __Signal14_h__ #include "horrible_cast.h" #include "slot_base.h" #include "signal_base.h" //========================================================================================================================================= // Slot tempplate. //========================================================================================================================================= /** * 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); Slot14_function( const FUNCTION_POINTER func ) { // convert and store function pointer in slot_base this->data[0] = safe_horrible_cast(func); } 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: 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); } 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); } }; //========================================================================================================================================= // Signal tempplate. //========================================================================================================================================= 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: //----------------------------------------------------------------------------------------------------------------------------------------- // Execute the Signal: // - Walk the list of Slot nodes. //----------------------------------------------------------------------------------------------------------------------------------------- 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( IsSignalEmitting( ) ) { #if defined( _DEBUG ) printf("WARNING: Signal14<...> @ 0x%p recursive Emit attempt\n", this); #endif return; } BeginEmit( ); list_node* cur = GetFirstNode( ); // iterate through the list while( cur ) { // make the slot_base pointer a Slot14 pointer Slot14* s = static_cast*>(cur->slot); // call the Signal (*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; } EndEmit( ); } //========================================================================================================================================= // Signal connections //========================================================================================================================================= 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); // 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 bind(sNewFunc); } // Object methods //----------------------------------------------------------------------------------------------------------------------------------------- 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 bind(sNewMethod); } //========================================================================================================================================= // Signal Disconnections //========================================================================================================================================= // Functions //----------------------------------------------------------------------------------------------------------------------------------------- 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 unbind(&sTest); } // Object 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 unbind(&sTemp); } }; #endif // __Signal14_h__