diff options
Diffstat (limited to 'src/tests/signal.cpp')
-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 | |||