From f72c6e4b97afeb69d9ea4d743c0c302d647ea424 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 16 Dec 2009 20:10:58 +0000 Subject: The new signal/slots system is in place, and works from 0-5 parameters right now, I'll probably add more later on... I've also started on the replacement for ParamProc, OptParser. It should do everything that ParamProc did, only with less code, and much better. --- src/signals.h | 592 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 592 insertions(+) create mode 100644 src/signals.h (limited to 'src/signals.h') diff --git a/src/signals.h b/src/signals.h new file mode 100644 index 0000000..722f928 --- /dev/null +++ b/src/signals.h @@ -0,0 +1,592 @@ +#ifndef BU_OBJECT_SIGNALS_H +#define BU_OBJECT_SIGNALS_H + +#include "bu/util.h" + +namespace Bu +{ + // + // 0 Parameters + // + + template + class _Slot0 + { + public: + _Slot0() { } + virtual ~_Slot0() { } + + virtual ret operator()()=0; + + virtual _Slot0 *clone() const=0; + }; + + template + class __Slot0 : public _Slot0 + { + public: + __Slot0( cls *pCls, ret (cls::*pFnc)() ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot0() { } + + virtual ret operator()() + { + return (pCls->*pFnc)(); + } + + virtual _Slot0 *clone() const + { + return new __Slot0( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)(); + }; + + template + class __Slot0F : public _Slot0 + { + public: + __Slot0F( ret (*pFnc)() ) : + pFnc( pFnc ) { } + virtual ~__Slot0F() { } + + virtual ret operator()() + { + return (*pFnc)(); + } + + virtual _Slot0 *clone() const + { + return new __Slot0F( pFnc ); + } + + private: + ret (*pFnc)(); + }; + + template + class Signal0 + { + public: + Signal0() : pCb( NULL ) { } + Signal0( _Slot0 *pCb ) : pCb( pCb ) { } + Signal0( const Signal0 &rSrc ) : + pCb( rSrc.pCb->clone() ) { } + + virtual ~Signal0() { delete pCb; pCb = NULL; } + + ret operator()() + { + return (*pCb)(); + } + + private: + _Slot0 *pCb; + }; + + template + Signal0 slot( cls *pCls, ret (cls::*pFnc)() ) + { + return Signal0( + new __Slot0( pCls, pFnc ) + ); + } + + template + Signal0 slot( ret (*pFnc)() ) + { + return Signal0( + new __Slot0F( pFnc ) + ); + } + + // + // 1 Parameter + // + + template + class _Slot1 + { + public: + _Slot1() { } + virtual ~_Slot1() { } + + virtual ret operator()( p1t p1 )=0; + + virtual _Slot1 *clone() const=0; + }; + + template + class __Slot1 : public _Slot1 + { + public: + __Slot1( cls *pCls, ret (cls::*pFnc)( p1t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot1() { } + + virtual ret operator()( p1t p1 ) + { + return (pCls->*pFnc)( p1 ); + } + + virtual _Slot1 *clone() const + { + return new __Slot1( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t ); + }; + + template + class __Slot1F : public _Slot1 + { + public: + __Slot1F( ret (*pFnc)( p1t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot1F() { } + + virtual ret operator()( p1t p1 ) + { + return (*pFnc)( p1 ); + } + + virtual _Slot1 *clone() const + { + return new __Slot1F( pFnc ); + } + + private: + ret (*pFnc)( p1t p1 ); + }; + + template + class Signal1 + { + public: + Signal1() : pCb( NULL ) { } + Signal1( _Slot1 *pCb ) : pCb( pCb ) { } + Signal1( const Signal1 &rSrc ) : + pCb( rSrc.pCb->clone() ) { } + + virtual ~Signal1() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1 ) + { + return (*pCb)( p1 ); + } + + private: + _Slot1 *pCb; + }; + + template + Signal1 slot( cls *pCls, ret (cls::*pFnc)( p1t ) ) + { + return Signal1( + new __Slot1( pCls, pFnc ) + ); + } + + template + Signal1 slot( ret (*pFnc)( p1t ) ) + { + return Signal1( + new __Slot1F( pFnc ) + ); + } + + // + // 2 Parameters + // + + template + class _Slot2 + { + public: + _Slot2() { } + virtual ~_Slot2() { } + + virtual ret operator()( p1t p1, p2t p2 )=0; + + virtual _Slot2 *clone() const=0; + }; + + template + class __Slot2 : public _Slot2 + { + public: + __Slot2( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot2() { } + + virtual ret operator()( p1t p1, p2t p2 ) + { + return (pCls->*pFnc)( p1, p2 ); + } + + virtual _Slot2 *clone() const + { + return new __Slot2( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t ); + }; + + template + class __Slot2F : public _Slot2 + { + public: + __Slot2F( ret (*pFnc)( p1t, p2t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot2F() { } + + virtual ret operator()( p1t p1, p2t p2 ) + { + return (*pFnc)( p1, p2 ); + } + + virtual _Slot2 *clone() const + { + return new __Slot2F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t ); + }; + + template + class Signal2 + { + public: + Signal2() : pCb( NULL ) { } + Signal2( _Slot2 *pCb ) : pCb( pCb ) { } + Signal2( const Signal2 &rSrc ) : + pCb( rSrc.pCb->clone() ) { } + + virtual ~Signal2() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2 ) + { + return (*pCb)( p1, p2 ); + } + + private: + _Slot2 *pCb; + }; + + template + Signal2 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) ) + { + return Signal2( + new __Slot2( pCls, pFnc ) + ); + } + + template + Signal2 slot( ret (*pFnc)( p1t, p2t ) ) + { + return Signal2( + new __Slot2F( pFnc ) + ); + } + + // + // 3 Parameters + // + + template + class _Slot3 + { + public: + _Slot3() { } + virtual ~_Slot3() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3 )=0; + + virtual _Slot3 *clone() const=0; + }; + + template + class __Slot3 : public _Slot3 + { + public: + __Slot3( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot3() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3 ) + { + return (pCls->*pFnc)( p1, p2, p3 ); + } + + virtual _Slot3 *clone() const + { + return new __Slot3( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t ); + }; + + template + class __Slot3F : public _Slot3 + { + public: + __Slot3F( ret (*pFnc)( p1t, p2t, p3t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot3F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3 ) + { + return (*pFnc)( p1, p2, p3 ); + } + + virtual _Slot3 *clone() const + { + return new __Slot3F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t ); + }; + + template + class Signal3 + { + public: + Signal3() : pCb( NULL ) { } + Signal3( _Slot3 *pCb ) : pCb( pCb ) { } + Signal3( const Signal3 &rSrc ) : + pCb( rSrc.pCb->clone() ) { } + + virtual ~Signal3() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3 ) + { + return (*pCb)( p1, p2, p3 ); + } + + private: + _Slot3 *pCb; + }; + + template + Signal3 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) ) + { + return Signal3( + new __Slot3( pCls, pFnc ) + ); + } + + template + Signal3 slot( ret (*pFnc)( p1t, p2t, p3t ) ) + { + return Signal3( + new __Slot3F( pFnc ) + ); + } + + // + // 4 Parameters + // + + template + class _Slot4 + { + public: + _Slot4() { } + virtual ~_Slot4() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )=0; + + virtual _Slot4 *clone() const=0; + }; + + template + class __Slot4 : public _Slot4 + { + public: + __Slot4( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot4() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4 ); + } + + virtual _Slot4 *clone() const + { + return new __Slot4( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t ); + }; + + template + class __Slot4F : public _Slot4 + { + public: + __Slot4F( ret (*pFnc)( p1t, p2t, p3t, p4t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot4F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) + { + return (*pFnc)( p1, p2, p3, p4 ); + } + + virtual _Slot4 *clone() const + { + return new __Slot4F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t ); + }; + + template + class Signal4 + { + public: + Signal4() : pCb( NULL ) { } + Signal4( _Slot4 *pCb ) : pCb( pCb ) { } + Signal4( const Signal4 &rSrc ) : + pCb( rSrc.pCb->clone() ) { } + + virtual ~Signal4() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 ) + { + return (*pCb)( p1, p2, p3, p4 ); + } + + private: + _Slot4 *pCb; + }; + + template + Signal4 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) ) + { + return Signal4( + new __Slot4( pCls, pFnc ) + ); + } + + template + Signal4 slot( ret (*pFnc)( p1t, p2t, p3t, p4t ) ) + { + return Signal4( + new __Slot4F( pFnc ) + ); + } + + // + // 5 Parameters + // + + template + class _Slot5 + { + public: + _Slot5() { } + virtual ~_Slot5() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )=0; + + virtual _Slot5 *clone() const=0; + }; + + template + class __Slot5 : public _Slot5 + { + public: + __Slot5( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) : + pCls( pCls ), pFnc( pFnc ) { } + virtual ~__Slot5() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) + { + return (pCls->*pFnc)( p1, p2, p3, p4, p5 ); + } + + virtual _Slot5 *clone() const + { + return new __Slot5( pCls, pFnc ); + } + + private: + cls *pCls; + ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ); + }; + + template + class __Slot5F : public _Slot5 + { + public: + __Slot5F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) : + pFnc( pFnc ) { } + virtual ~__Slot5F() { } + + virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) + { + return (*pFnc)( p1, p2, p3, p4, p5 ); + } + + virtual _Slot5 *clone() const + { + return new __Slot5F( pFnc ); + } + + private: + ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ); + }; + + template + class Signal5 + { + public: + Signal5() : pCb( NULL ) { } + Signal5( _Slot5 *pCb ) : pCb( pCb ) { } + Signal5( const Signal5 &rSrc ) : + pCb( rSrc.pCb->clone() ) { } + + virtual ~Signal5() { delete pCb; pCb = NULL; } + + ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 ) + { + return (*pCb)( p1, p2, p3, p4, p5 ); + } + + private: + _Slot5 *pCb; + }; + + template + Signal5 slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) + { + return Signal5( + new __Slot5( pCls, pFnc ) + ); + } + + template + Signal5 slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) + { + return Signal5( + new __Slot5F( pFnc ) + ); + } + +}; + +#endif -- cgit v1.2.3