diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-12-19 00:16:48 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-12-19 00:16:48 +0000 |
| commit | 15628cc7534c008d0f5e206f29fd71a412031650 (patch) | |
| tree | ae10793976a8766b1324723aad4892631f0f4dad | |
| parent | 03e8c5ad314252cde58c53688c70b9f836a1d5b4 (diff) | |
| download | libbu++-15628cc7534c008d0f5e206f29fd71a412031650.tar.gz libbu++-15628cc7534c008d0f5e206f29fd71a412031650.tar.bz2 libbu++-15628cc7534c008d0f5e206f29fd71a412031650.tar.xz libbu++-15628cc7534c008d0f5e206f29fd71a412031650.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | src/tests/signal.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
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 @@ | |||
| 1 | #include <bu/signals.h> | ||
| 2 | #include <bu/list.h> | ||
| 3 | #include <bu/string.h> | ||
| 4 | #include <bu/sio.h> | ||
| 5 | |||
| 6 | using namespace Bu; | ||
| 7 | |||
| 8 | void PrintPlain( const Bu::String &s ) | ||
| 9 | { | ||
| 10 | println(s); | ||
| 11 | } | ||
| 12 | |||
| 13 | void PrintFancy( const Bu::String &s ) | ||
| 14 | { | ||
| 15 | println("STRING!!! ->%1<- !!!GNIRTS").arg( s ); | ||
| 16 | } | ||
| 17 | |||
| 18 | int Square( int a ) | ||
| 19 | { | ||
| 20 | return a*a; | ||
| 21 | } | ||
| 22 | |||
| 23 | int Double( int a ) | ||
| 24 | { | ||
| 25 | return a+a; | ||
| 26 | } | ||
| 27 | |||
| 28 | template<typename R, typename P> | ||
| 29 | class SignalList1 : public Bu::List<Bu::Signal1<R,P> > | ||
| 30 | { | ||
| 31 | typedef Bu::List<Bu::Signal1<R,P> > MyType; | ||
| 32 | public: | ||
| 33 | SignalList1() | ||
| 34 | { | ||
| 35 | } | ||
| 36 | |||
| 37 | using MyType::iterator; | ||
| 38 | using MyType::const_iterator; | ||
| 39 | |||
| 40 | R operator()( P p1 ) | ||
| 41 | { | ||
| 42 | println("===Non-void um...non-specialization==="); | ||
| 43 | R tmp; | ||
| 44 | for( typename MyType::iterator i = MyType::begin(); i; i++ ) | ||
| 45 | tmp = (*i)( p1 ); | ||
| 46 | return tmp; | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | |||
| 50 | template<typename P> | ||
| 51 | class SignalList1<void, P> : public Bu::List<Bu::Signal1<void,P> > | ||
| 52 | { | ||
| 53 | typedef Bu::List<Bu::Signal1<void,P> > MyType; | ||
| 54 | public: | ||
| 55 | SignalList1() | ||
| 56 | { | ||
| 57 | } | ||
| 58 | |||
| 59 | using MyType::iterator; | ||
| 60 | using MyType::const_iterator; | ||
| 61 | |||
| 62 | void operator()( P p1 ) | ||
| 63 | { | ||
| 64 | println("===Void specialization==="); | ||
| 65 | for( typename MyType::iterator i = MyType::begin(); i; i++ ) | ||
| 66 | (*i)( p1 ); | ||
| 67 | } | ||
| 68 | }; | ||
| 69 | |||
| 70 | int main() | ||
| 71 | { | ||
| 72 | SignalList1<void,const Bu::String &> lPrints; | ||
| 73 | |||
| 74 | lPrints += slot(PrintPlain); | ||
| 75 | lPrints += slot(PrintFancy); | ||
| 76 | |||
| 77 | lPrints("Hello there"); | ||
| 78 | |||
| 79 | SignalList1<int,int> lMaths; | ||
| 80 | lMaths += slot(Double); | ||
| 81 | lMaths += slot(Square); | ||
| 82 | println("Math'd %1 = %2").arg( 5 ).arg( lMaths(5) ); | ||
| 83 | |||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
