diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-12-16 20:10:58 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-12-16 20:10:58 +0000 |
commit | f72c6e4b97afeb69d9ea4d743c0c302d647ea424 (patch) | |
tree | 48d9d94db520455324e902759e887c0d98de976a /src/tests/signals.cpp | |
parent | 5eba456f0147b12a6247cd7aa41e55d121962358 (diff) | |
download | libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.gz libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.bz2 libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.xz libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.zip |
The new signal/slots system is in place, and works from 0-5 parameters right
now, I'll probably add more later on...
I've also started on the replacement for ParamProc, OptParser. It should do
everything that ParamProc did, only with less code, and much better.
Diffstat (limited to '')
-rw-r--r-- | src/tests/signals.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/tests/signals.cpp b/src/tests/signals.cpp new file mode 100644 index 0000000..b4b1363 --- /dev/null +++ b/src/tests/signals.cpp | |||
@@ -0,0 +1,87 @@ | |||
1 | #include <bu/signals.h> | ||
2 | #include <bu/sio.h> | ||
3 | |||
4 | using namespace Bu; | ||
5 | |||
6 | class Thing | ||
7 | { | ||
8 | public: | ||
9 | Thing() : | ||
10 | iState( 82731 ) | ||
11 | { | ||
12 | } | ||
13 | |||
14 | virtual ~Thing() | ||
15 | { | ||
16 | } | ||
17 | |||
18 | void fnc0() | ||
19 | { | ||
20 | sio << iState << ": void fnc0()" << sio.nl; | ||
21 | } | ||
22 | |||
23 | void fnc1( int a ) | ||
24 | { | ||
25 | sio << iState << ": void fnc1( " << a << " )" << sio.nl; | ||
26 | } | ||
27 | |||
28 | void fnc2( int a, Bu::FString b ) | ||
29 | { | ||
30 | sio << iState << ": void fnc2( " << a << ", \"" << b << "\" )" << sio.nl; | ||
31 | } | ||
32 | |||
33 | void fnc3( int a, Bu::FString b, double c ) | ||
34 | { | ||
35 | sio << iState << ": void fnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl; | ||
36 | } | ||
37 | |||
38 | void fnc4( int a, Bu::FString b, double c, char d ) | ||
39 | { | ||
40 | sio << iState << ": void fnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl; | ||
41 | } | ||
42 | |||
43 | void fnc5( int a, Bu::FString b, double c, char d, long e ) | ||
44 | { | ||
45 | sio << iState << ": void fnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl; | ||
46 | } | ||
47 | |||
48 | private: | ||
49 | int iState; | ||
50 | }; | ||
51 | |||
52 | void pfnc0() | ||
53 | { | ||
54 | sio << "This doesn't have state, it's pfnc0()!" << sio.nl; | ||
55 | } | ||
56 | |||
57 | void callit( Signal0<void> sig ) | ||
58 | { | ||
59 | sig(); | ||
60 | } | ||
61 | |||
62 | int main() | ||
63 | { | ||
64 | Thing t; | ||
65 | |||
66 | Signal0<void> cb0( slot( &t, &Thing::fnc0 ) ); | ||
67 | cb0(); | ||
68 | |||
69 | Signal1<void, int> cb1( slot( &t, &Thing::fnc1 ) ); | ||
70 | cb1( 5 ); | ||
71 | |||
72 | Signal2<void, int, Bu::FString> cb2( slot( &t, &Thing::fnc2 ) ); | ||
73 | cb2( 5, "Hi there" ); | ||
74 | |||
75 | Signal3<void, int, Bu::FString, double> cb3( slot( &t, &Thing::fnc3 ) ); | ||
76 | cb3( 5, "Hi there", 12.85 ); | ||
77 | |||
78 | Signal4<void, int, Bu::FString, double, char> cb4( slot( &t, &Thing::fnc4 ) ); | ||
79 | cb4( 5, "Hi there", 12.85, 'z' ); | ||
80 | |||
81 | Signal5<void, int, Bu::FString, double, char, long> cb5( slot( &t, &Thing::fnc5 ) ); | ||
82 | cb5( 5, "Hi there", 12.85, 'z', 849 ); | ||
83 | |||
84 | // Signal1<int, int> cb1( slot( &t, &Thing::fnc1 ) ); | ||
85 | // sio << "Result: " << cb1( 5 ) << sio.nl; | ||
86 | } | ||
87 | |||