From 8642fe0ba100dee5a66265b07e21e043887a4a92 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 21 Dec 2012 00:06:20 +0000 Subject: Signals (slots really) are now comperable. Building two slots for the same function or same object and method will compare as expected. Also added a -= function to Bu::List which works just like erase. --- gensigs.bld | 26 ++++- pregen/signals.h | 276 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/stable/archive.h | 2 +- src/stable/list.h | 5 + src/tests/signal.cpp | 2 + 5 files changed, 298 insertions(+), 13 deletions(-) diff --git a/gensigs.bld b/gensigs.bld index 6cdd5d5..6bb1e55 100644 --- a/gensigs.bld +++ b/gensigs.bld @@ -16,6 +16,7 @@ function genSigs( outName ) "#ifndef BU_SIGNALS_H\n" "#define BU_SIGNALS_H\n" "\n" + "#include \n" "#include \"bu/util.h\"\n" "#include \"bu/exceptionbase.h\"\n" "#include \"bu/list.h\"\n" @@ -69,6 +70,7 @@ function genSigs( outName ) " virtual ~_Slot${i}() { }\n" " virtual ret operator()( ${funcParams} )=0;\n" " virtual _Slot${i}<${templCallParams}> *clone() const=0;\n" + " virtual bool operator==( const _Slot${i}<${templCallParams}> &rhs ) const=0;\n" " };\n" " \n" " template\n" @@ -89,6 +91,12 @@ function genSigs( outName ) " return new __Slot${i}( pCls, pFnc );\n" " }\n" " \n" + " virtual bool operator==( const _Slot${i}<${templCallParams}> &rhs ) const\n" + " {\n" + " const __Slot${i} &rrhs = (const __Slot${i} &)rhs;\n" + " return pCls == rrhs.pCls && pFnc == rrhs.pFnc;\n" + " }\n" + " \n" " private:\n" " cls *pCls;\n" " ret (cls::*pFnc)( ${funcAnonParams} );\n" @@ -112,6 +120,11 @@ function genSigs( outName ) " return new __Slot${i}F<${templCallParams}>( pFnc );\n" " }\n" " \n" + " virtual bool operator==( const _Slot${i}<${templCallParams}> &rhs ) const\n" + " {\n" + " return pFnc == ((const __Slot${i}F<${templCallParams}> &)rhs).pFnc;\n" + " }\n" + " \n" " private:\n" " ret (*pFnc)( ${funcAnonParams} );\n" " };\n" @@ -141,6 +154,17 @@ function genSigs( outName ) " return *this;\n" " }\n" " \n" + " bool operator==( const Signal${i}<${templCallParams}> &rhs ) const\n" + " {\n" + " if( pCb == rhs.pCb )\n" + " return true;\n" + " if( pCb == NULL || rhs.pCb == NULL )\n" + " return false;\n" + " if( typeid(pCb) != typeid(rhs.pCb) )\n" + " return false;\n" + " return *pCb == *rhs.pCb;\n" + " }\n" + " \n" " private:\n" " _Slot${i}<${templCallParams}> *pCb;\n" " };\n" @@ -187,7 +211,7 @@ function genSigs( outName ) " else\n" " return (*i)( ${funcCallParams} );\n" " }\n" - " throw Bu::ExceptionBase(\"Empty SignalList with non-void return value called.\");\n" + " throw Bu::SignalException(\"Empty SignalList with non-void return value called.\");\n" " }\n" " };\n" " \n" diff --git a/pregen/signals.h b/pregen/signals.h index e8374e3..3435986 100644 --- a/pregen/signals.h +++ b/pregen/signals.h @@ -8,6 +8,7 @@ #ifndef BU_SIGNALS_H #define BU_SIGNALS_H +#include #include "bu/util.h" #include "bu/exceptionbase.h" #include "bu/list.h" @@ -29,6 +30,7 @@ namespace Bu virtual ~_Slot0() { } virtual ret operator()( )=0; virtual _Slot0 *clone() const=0; + virtual bool operator==( const _Slot0 &rhs ) const=0; }; template @@ -49,6 +51,12 @@ namespace Bu return new __Slot0( pCls, pFnc ); } + virtual bool operator==( const _Slot0 &rhs ) const + { + const __Slot0 &rrhs = (const __Slot0 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( ); @@ -72,6 +80,11 @@ namespace Bu return new __Slot0F( pFnc ); } + virtual bool operator==( const _Slot0 &rhs ) const + { + return pFnc == ((const __Slot0F &)rhs).pFnc; + } + private: ret (*pFnc)( ); }; @@ -101,6 +114,17 @@ namespace Bu return *this; } + bool operator==( const Signal0 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot0 *pCb; }; @@ -147,7 +171,7 @@ namespace Bu else return (*i)( ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -184,6 +208,7 @@ namespace Bu virtual ~_Slot1() { } virtual ret operator()( p1t p1 )=0; virtual _Slot1 *clone() const=0; + virtual bool operator==( const _Slot1 &rhs ) const=0; }; template @@ -204,6 +229,12 @@ namespace Bu return new __Slot1( pCls, pFnc ); } + virtual bool operator==( const _Slot1 &rhs ) const + { + const __Slot1 &rrhs = (const __Slot1 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t ); @@ -227,6 +258,11 @@ namespace Bu return new __Slot1F( pFnc ); } + virtual bool operator==( const _Slot1 &rhs ) const + { + return pFnc == ((const __Slot1F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t ); }; @@ -256,6 +292,17 @@ namespace Bu return *this; } + bool operator==( const Signal1 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot1 *pCb; }; @@ -302,7 +349,7 @@ namespace Bu else return (*i)( p1 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -339,6 +386,7 @@ namespace Bu virtual ~_Slot2() { } virtual ret operator()( p1t p1, p2t p2 )=0; virtual _Slot2 *clone() const=0; + virtual bool operator==( const _Slot2 &rhs ) const=0; }; template @@ -359,6 +407,12 @@ namespace Bu return new __Slot2( pCls, pFnc ); } + virtual bool operator==( const _Slot2 &rhs ) const + { + const __Slot2 &rrhs = (const __Slot2 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t ); @@ -382,6 +436,11 @@ namespace Bu return new __Slot2F( pFnc ); } + virtual bool operator==( const _Slot2 &rhs ) const + { + return pFnc == ((const __Slot2F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t ); }; @@ -411,6 +470,17 @@ namespace Bu return *this; } + bool operator==( const Signal2 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot2 *pCb; }; @@ -457,7 +527,7 @@ namespace Bu else return (*i)( p1, p2 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -494,6 +564,7 @@ namespace Bu virtual ~_Slot3() { } virtual ret operator()( p1t p1, p2t p2, p3t p3 )=0; virtual _Slot3 *clone() const=0; + virtual bool operator==( const _Slot3 &rhs ) const=0; }; template @@ -514,6 +585,12 @@ namespace Bu return new __Slot3( pCls, pFnc ); } + virtual bool operator==( const _Slot3 &rhs ) const + { + const __Slot3 &rrhs = (const __Slot3 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t ); @@ -537,6 +614,11 @@ namespace Bu return new __Slot3F( pFnc ); } + virtual bool operator==( const _Slot3 &rhs ) const + { + return pFnc == ((const __Slot3F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t ); }; @@ -566,6 +648,17 @@ namespace Bu return *this; } + bool operator==( const Signal3 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot3 *pCb; }; @@ -612,7 +705,7 @@ namespace Bu else return (*i)( p1, p2, p3 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -649,6 +742,7 @@ namespace Bu virtual ~_Slot4() { } virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )=0; virtual _Slot4 *clone() const=0; + virtual bool operator==( const _Slot4 &rhs ) const=0; }; template @@ -669,6 +763,12 @@ namespace Bu return new __Slot4( pCls, pFnc ); } + virtual bool operator==( const _Slot4 &rhs ) const + { + const __Slot4 &rrhs = (const __Slot4 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t, p4t ); @@ -692,6 +792,11 @@ namespace Bu return new __Slot4F( pFnc ); } + virtual bool operator==( const _Slot4 &rhs ) const + { + return pFnc == ((const __Slot4F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t, p4t ); }; @@ -721,6 +826,17 @@ namespace Bu return *this; } + bool operator==( const Signal4 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot4 *pCb; }; @@ -767,7 +883,7 @@ namespace Bu else return (*i)( p1, p2, p3, p4 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -804,6 +920,7 @@ namespace Bu virtual ~_Slot5() { } virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )=0; virtual _Slot5 *clone() const=0; + virtual bool operator==( const _Slot5 &rhs ) const=0; }; template @@ -824,6 +941,12 @@ namespace Bu return new __Slot5( pCls, pFnc ); } + virtual bool operator==( const _Slot5 &rhs ) const + { + const __Slot5 &rrhs = (const __Slot5 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ); @@ -847,6 +970,11 @@ namespace Bu return new __Slot5F( pFnc ); } + virtual bool operator==( const _Slot5 &rhs ) const + { + return pFnc == ((const __Slot5F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ); }; @@ -876,6 +1004,17 @@ namespace Bu return *this; } + bool operator==( const Signal5 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot5 *pCb; }; @@ -922,7 +1061,7 @@ namespace Bu else return (*i)( p1, p2, p3, p4, p5 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -959,6 +1098,7 @@ namespace Bu virtual ~_Slot6() { } virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6 )=0; virtual _Slot6 *clone() const=0; + virtual bool operator==( const _Slot6 &rhs ) const=0; }; template @@ -979,6 +1119,12 @@ namespace Bu return new __Slot6( pCls, pFnc ); } + virtual bool operator==( const _Slot6 &rhs ) const + { + const __Slot6 &rrhs = (const __Slot6 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ); @@ -1002,6 +1148,11 @@ namespace Bu return new __Slot6F( pFnc ); } + virtual bool operator==( const _Slot6 &rhs ) const + { + return pFnc == ((const __Slot6F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t ); }; @@ -1031,6 +1182,17 @@ namespace Bu return *this; } + bool operator==( const Signal6 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot6 *pCb; }; @@ -1077,7 +1239,7 @@ namespace Bu else return (*i)( p1, p2, p3, p4, p5, p6 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -1114,6 +1276,7 @@ namespace Bu virtual ~_Slot7() { } virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7 )=0; virtual _Slot7 *clone() const=0; + virtual bool operator==( const _Slot7 &rhs ) const=0; }; template @@ -1134,6 +1297,12 @@ namespace Bu return new __Slot7( pCls, pFnc ); } + virtual bool operator==( const _Slot7 &rhs ) const + { + const __Slot7 &rrhs = (const __Slot7 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ); @@ -1157,6 +1326,11 @@ namespace Bu return new __Slot7F( pFnc ); } + virtual bool operator==( const _Slot7 &rhs ) const + { + return pFnc == ((const __Slot7F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t ); }; @@ -1186,6 +1360,17 @@ namespace Bu return *this; } + bool operator==( const Signal7 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot7 *pCb; }; @@ -1232,7 +1417,7 @@ namespace Bu else return (*i)( p1, p2, p3, p4, p5, p6, p7 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -1269,6 +1454,7 @@ namespace Bu virtual ~_Slot8() { } virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8 )=0; virtual _Slot8 *clone() const=0; + virtual bool operator==( const _Slot8 &rhs ) const=0; }; template @@ -1289,6 +1475,12 @@ namespace Bu return new __Slot8( pCls, pFnc ); } + virtual bool operator==( const _Slot8 &rhs ) const + { + const __Slot8 &rrhs = (const __Slot8 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ); @@ -1312,6 +1504,11 @@ namespace Bu return new __Slot8F( pFnc ); } + virtual bool operator==( const _Slot8 &rhs ) const + { + return pFnc == ((const __Slot8F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t ); }; @@ -1341,6 +1538,17 @@ namespace Bu return *this; } + bool operator==( const Signal8 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot8 *pCb; }; @@ -1387,7 +1595,7 @@ namespace Bu else return (*i)( p1, p2, p3, p4, p5, p6, p7, p8 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -1424,6 +1632,7 @@ namespace Bu virtual ~_Slot9() { } virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9 )=0; virtual _Slot9 *clone() const=0; + virtual bool operator==( const _Slot9 &rhs ) const=0; }; template @@ -1444,6 +1653,12 @@ namespace Bu return new __Slot9( pCls, pFnc ); } + virtual bool operator==( const _Slot9 &rhs ) const + { + const __Slot9 &rrhs = (const __Slot9 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ); @@ -1467,6 +1682,11 @@ namespace Bu return new __Slot9F( pFnc ); } + virtual bool operator==( const _Slot9 &rhs ) const + { + return pFnc == ((const __Slot9F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t ); }; @@ -1496,6 +1716,17 @@ namespace Bu return *this; } + bool operator==( const Signal9 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot9 *pCb; }; @@ -1542,7 +1773,7 @@ namespace Bu else return (*i)( p1, p2, p3, p4, p5, p6, p7, p8, p9 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; @@ -1579,6 +1810,7 @@ namespace Bu virtual ~_Slot10() { } virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5, p6t p6, p7t p7, p8t p8, p9t p9, p10t p10 )=0; virtual _Slot10 *clone() const=0; + virtual bool operator==( const _Slot10 &rhs ) const=0; }; template @@ -1599,6 +1831,12 @@ namespace Bu return new __Slot10( pCls, pFnc ); } + virtual bool operator==( const _Slot10 &rhs ) const + { + const __Slot10 &rrhs = (const __Slot10 &)rhs; + return pCls == rrhs.pCls && pFnc == rrhs.pFnc; + } + private: cls *pCls; ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ); @@ -1622,6 +1860,11 @@ namespace Bu return new __Slot10F( pFnc ); } + virtual bool operator==( const _Slot10 &rhs ) const + { + return pFnc == ((const __Slot10F &)rhs).pFnc; + } + private: ret (*pFnc)( p1t, p2t, p3t, p4t, p5t, p6t, p7t, p8t, p9t, p10t ); }; @@ -1651,6 +1894,17 @@ namespace Bu return *this; } + bool operator==( const Signal10 &rhs ) const + { + if( pCb == rhs.pCb ) + return true; + if( pCb == NULL || rhs.pCb == NULL ) + return false; + if( typeid(pCb) != typeid(rhs.pCb) ) + return false; + return *pCb == *rhs.pCb; + } + private: _Slot10 *pCb; }; @@ -1697,7 +1951,7 @@ namespace Bu else return (*i)( p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 ); } - throw Bu::ExceptionBase("Empty SignalList with non-void return value called."); + throw Bu::SignalException("Empty SignalList with non-void return value called."); } }; diff --git a/src/stable/archive.h b/src/stable/archive.h index f98402d..5c3a055 100644 --- a/src/stable/archive.h +++ b/src/stable/archive.h @@ -129,7 +129,7 @@ namespace Bu private: Stream &rStream; uint32_t nNextID; - Hash hPtrID; + Hash hPtrID; Hash > hPtrDest; Hash hProps; }; diff --git a/src/stable/list.h b/src/stable/list.h index b7fb1d1..0b6329c 100644 --- a/src/stable/list.h +++ b/src/stable/list.h @@ -250,6 +250,11 @@ namespace Bu return *this; } + MyType &operator-=( const value &v ) + { + return erase( v ); + } + MyType &operator+=( const MyType &src ) { _hardCopy(); diff --git a/src/tests/signal.cpp b/src/tests/signal.cpp index 93519fa..62e8bd5 100644 --- a/src/tests/signal.cpp +++ b/src/tests/signal.cpp @@ -40,6 +40,8 @@ int main() lMaths += slot(Double); lMaths += slot(Square); println("Math'd %1 = %2").arg( 5 ).arg( lMaths(5) ); + lMaths -= slot(Square); + println("Math'd %1 = %2").arg( 5 ).arg( lMaths(5) ); return 0; } -- cgit v1.2.3