diff options
author | Henrik Kinnunen <fluxgen@fluxbox.org> | 2010-03-19 01:23:41 (GMT) |
---|---|---|
committer | Henrik Kinnunen <fluxgen@fluxbox.org> | 2010-03-19 01:23:41 (GMT) |
commit | ceff86b79401c27ed83cad65f59a6621c9a58084 (patch) | |
tree | 3dc59ecc1a7a5b31b2d87686aacc3c6e2dbdc5ab /src/tests | |
parent | 68e90ab84fc8720264694de47c1ac33c401b49e5 (diff) | |
download | fluxbox-ceff86b79401c27ed83cad65f59a6621c9a58084.zip fluxbox-ceff86b79401c27ed83cad65f59a6621c9a58084.tar.bz2 |
Added SelectArg and MemFunSelectArg*
The MemFunSelectArg* functions can be used to select
a specific argument from a signal. For example this would
select the string argument as argument to the callback:
Signal<void, int, float, string> signal;
signal.connect(MemFunSelectArg2(obj, &Object::takesOneStringArg));
signal.emit(10, 3.14, "hello");
...
void Object::takesOneStringArg(const string& value) {
...
}
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/testSignals.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/tests/testSignals.cc b/src/tests/testSignals.cc index f382289..75f046e 100644 --- a/src/tests/testSignals.cc +++ b/src/tests/testSignals.cc | |||
@@ -49,7 +49,7 @@ struct FunctionClass { | |||
49 | } | 49 | } |
50 | 50 | ||
51 | void takeIt( string& str ) { | 51 | void takeIt( string& str ) { |
52 | cout << "takeIt( " << str << ")" << endl; | 52 | cout << "FunctionClass::takeIt( " << str << " )" << endl; |
53 | } | 53 | } |
54 | 54 | ||
55 | void showMessage( int value, const string& message ) { | 55 | void showMessage( int value, const string& message ) { |
@@ -61,8 +61,21 @@ struct FunctionClass { | |||
61 | void threeArgs( int value, const string& str, double pi ) { | 61 | void threeArgs( int value, const string& str, double pi ) { |
62 | cout << "(" << value << "): " << str << ", pi = " << pi << endl; | 62 | cout << "(" << value << "): " << str << ", pi = " << pi << endl; |
63 | } | 63 | } |
64 | |||
64 | }; | 65 | }; |
65 | 66 | ||
67 | struct Printer { | ||
68 | void printInt(int value) { | ||
69 | cout << "Int:" << value << endl; | ||
70 | } | ||
71 | void printString(string value) { | ||
72 | cout << "string:" << value << endl; | ||
73 | } | ||
74 | void printFloat(float value) { | ||
75 | cout << "Float:" << value << endl; | ||
76 | } | ||
77 | }; | ||
78 | |||
66 | int main() { | 79 | int main() { |
67 | using FbTk::Signal; | 80 | using FbTk::Signal; |
68 | using FbTk::SignalTracker; | 81 | using FbTk::SignalTracker; |
@@ -161,4 +174,22 @@ int main() { | |||
161 | // subject notify its observers | 174 | // subject notify its observers |
162 | source.emit("hello world"); | 175 | source.emit("hello world"); |
163 | } | 176 | } |
177 | |||
178 | // Test argument selector | ||
179 | { | ||
180 | using namespace FbTk; | ||
181 | Signal<void, int, string, float> source; | ||
182 | |||
183 | Printer printer; | ||
184 | source.connect(MemFunSelectArg0(printer, &Printer::printInt)); | ||
185 | source.connect(MemFunSelectArg1(printer, &Printer::printString)); | ||
186 | source.connect(MemFunSelectArg2(printer, &Printer::printFloat)); | ||
187 | |||
188 | source.emit(10, "hello", 3.141592); | ||
189 | |||
190 | Signal<void, string, int> source2; | ||
191 | source2.connect(MemFunSelectArg0(printer, &Printer::printString)); | ||
192 | source2.connect(MemFunSelectArg1(printer, &Printer::printInt)); | ||
193 | source2.emit("world", 37); | ||
194 | } | ||
164 | } | 195 | } |