From 8ba750c2d52b9db90c8274020c6053a32441ed43 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 20 Dec 2012 00:13:45 +0000 Subject: gensigs.bld now generates SignalList classes in addition to Signal classes. They're pretty nifty. --- gensigs.bld | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/tests/signal.cpp | 44 ++----------------------------------------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/gensigs.bld b/gensigs.bld index c452356..6cdd5d5 100644 --- a/gensigs.bld +++ b/gensigs.bld @@ -18,6 +18,7 @@ function genSigs( outName ) "\n" "#include \"bu/util.h\"\n" "#include \"bu/exceptionbase.h\"\n" + "#include \"bu/list.h\"\n" "\n" "namespace Bu\n" "{\n" @@ -28,9 +29,11 @@ function genSigs( outName ) for i in range( 0, 10 ) do { templParams = "typename ret"; + templSpecParams = ""; funcParams = ""; funcAnonParams = ""; templCallParams = "ret"; + templSpecCallParams = ""; funcCallParams = ""; if i >= 1 then { @@ -41,11 +44,14 @@ function genSigs( outName ) funcCallParams << ", "; funcParams << ", "; funcAnonParams << ", "; + templSpecParams << ", "; } templParams << ", typename p${p}t"; + templSpecParams << "typename p${p}t"; funcParams << "p${p}t p${p}"; funcAnonParams << "p${p}t"; templCallParams << ", p${p}t"; + templSpecCallParams << ", p${p}t"; funcCallParams << "p${p}"; } } @@ -156,6 +162,53 @@ function genSigs( outName ) " new __Slot${i}F<${templCallParams}>( pFnc )\n" " );\n" " }\n" + " \n" + " template<${templParams}>\n" + " class SignalList${i} : public Bu::List >\n" + " {\n" + " typedef Bu::List > MyType;\n" + " public:\n" + " SignalList${i}()\n" + " {\n" + " }\n" + " \n" + " using MyType::iterator;\n" + " using MyType::const_iterator;\n" + " \n" + " ret operator()( ${funcParams} )\n" + " {\n" + " typename MyType::iterator i, n;\n" + " for(i = MyType::begin(); i; i=n)\n" + " {\n" + " n = i;\n" + " n++;\n" + " if( n )\n" + " (*i)( ${funcCallParams} );\n" + " else\n" + " return (*i)( ${funcCallParams} );\n" + " }\n" + " throw Bu::ExceptionBase(\"Empty SignalList with non-void return value called.\");\n" + " }\n" + " };\n" + " \n" + " template<${templSpecParams}>\n" + " class SignalList${i} : public Bu::List >\n" + " {\n" + " typedef Bu::List > MyType;\n" + " public:\n" + " SignalList${i}()\n" + " {\n" + " }\n" + " \n" + " using MyType::iterator;\n" + " using MyType::const_iterator;\n" + " \n" + " void operator()( ${funcParams} )\n" + " {\n" + " for( typename MyType::iterator i = MyType::begin(); i; i++ )\n" + " (*i)( ${funcCallParams} );\n" + " }\n" + " };\n" "#endif // BU_SIGNAL_PARAM_COUNT_${i}\n" "\n" ); diff --git a/src/tests/signal.cpp b/src/tests/signal.cpp index 8920461..93519fa 100644 --- a/src/tests/signal.cpp +++ b/src/tests/signal.cpp @@ -17,56 +17,16 @@ void PrintFancy( const Bu::String &s ) int Square( int a ) { + println("Square called"); return a*a; } int Double( int a ) { + println("Double called"); return a+a; } -template -class SignalList1 : public Bu::List > -{ - typedef Bu::List > MyType; -public: - SignalList1() - { - } - - using MyType::iterator; - using MyType::const_iterator; - - R operator()( P p1 ) - { - println("===Non-void um...non-specialization==="); - R tmp; - for( typename MyType::iterator i = MyType::begin(); i; i++ ) - tmp = (*i)( p1 ); - return tmp; - } -}; - -template -class SignalList1 : public Bu::List > -{ - typedef Bu::List > MyType; -public: - SignalList1() - { - } - - using MyType::iterator; - using MyType::const_iterator; - - void operator()( P p1 ) - { - println("===Void specialization==="); - for( typename MyType::iterator i = MyType::begin(); i; i++ ) - (*i)( p1 ); - } -}; - int main() { SignalList1 lPrints; -- cgit v1.2.3