From 15628cc7534c008d0f5e206f29fd71a412031650 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 19 Dec 2012 00:16:48 +0000 Subject: Added an initial test for the SignalList concept. I think it's actually just about done. List may want some extras to make it really nice, but that's immaterial to the signal code, I think it's about time to write generators. I have an idea for optomizing the return value code too, I'll try that out. --- src/tests/signal.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/tests/signal.cpp diff --git a/src/tests/signal.cpp b/src/tests/signal.cpp new file mode 100644 index 0000000..8920461 --- /dev/null +++ b/src/tests/signal.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +using namespace Bu; + +void PrintPlain( const Bu::String &s ) +{ + println(s); +} + +void PrintFancy( const Bu::String &s ) +{ + println("STRING!!! ->%1<- !!!GNIRTS").arg( s ); +} + +int Square( int a ) +{ + return a*a; +} + +int Double( int a ) +{ + 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; + + lPrints += slot(PrintPlain); + lPrints += slot(PrintFancy); + + lPrints("Hello there"); + + SignalList1 lMaths; + lMaths += slot(Double); + lMaths += slot(Square); + println("Math'd %1 = %2").arg( 5 ).arg( lMaths(5) ); + + return 0; +} + -- cgit v1.2.3