diff options
author | Henrik Kinnunen <fluxgen@fluxbox.org> | 2010-03-18 09:45:33 (GMT) |
---|---|---|
committer | Henrik Kinnunen <fluxgen@fluxbox.org> | 2010-03-18 09:45:33 (GMT) |
commit | 0504de454a0a3bf06466029940af480e3caaa8b2 (patch) | |
tree | 0c4507b4fe965cbe2080329ef9bad443c14fa6aa /src/tests | |
parent | 5a91ada3c6c9f199b3646465206d4b2b613cad3e (diff) | |
download | fluxbox_lack-0504de454a0a3bf06466029940af480e3caaa8b2.zip fluxbox_lack-0504de454a0a3bf06466029940af480e3caaa8b2.tar.bz2 |
Added MemFunIgnoreArgs which ignores aditional arguments.
For example connecting a function that takes two arguments
to a signal that emits three arguments:
struct Functor {
void show(int a, int b);
};
Functor f;
Signal<void, int, int, int> s3;
s3.connect(MemFunIgnoreArgs(f, &Functor::show));
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/testSignals.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/tests/testSignals.cc b/src/tests/testSignals.cc index 86096bf..6d68d3a 100644 --- a/src/tests/testSignals.cc +++ b/src/tests/testSignals.cc | |||
@@ -21,7 +21,8 @@ struct OneArgument { | |||
21 | }; | 21 | }; |
22 | 22 | ||
23 | struct TwoArguments { | 23 | struct TwoArguments { |
24 | void operator ()( int value, const string& message ) { | 24 | template <typename T1, typename T2> |
25 | void operator ()( const T1& value, const T2& message ) { | ||
25 | cout << "Two arguments, (1) = " << value << ", (2) = " << message << endl; | 26 | cout << "Two arguments, (1) = " << value << ", (2) = " << message << endl; |
26 | } | 27 | } |
27 | }; | 28 | }; |
@@ -51,6 +52,9 @@ struct FunctionClass { | |||
51 | void showMessage( int value, const string& message ) { | 52 | void showMessage( int value, const string& message ) { |
52 | cout << "(" << value << "): " << message << endl; | 53 | cout << "(" << value << "): " << message << endl; |
53 | } | 54 | } |
55 | void showMessage2( const string& message1, const string& message2) { | ||
56 | cout << "(" << message1 << ", " << message2 << ")" << endl; | ||
57 | } | ||
54 | void threeArgs( int value, const string& str, double pi ) { | 58 | void threeArgs( int value, const string& str, double pi ) { |
55 | cout << "(" << value << "): " << str << ", pi = " << pi << endl; | 59 | cout << "(" << value << "): " << str << ", pi = " << pi << endl; |
56 | } | 60 | } |
@@ -118,4 +122,21 @@ int main() { | |||
118 | three_args.clear(); | 122 | three_args.clear(); |
119 | three_args.connect(MemFun(obj, &FunctionClass::threeArgs)); | 123 | three_args.connect(MemFun(obj, &FunctionClass::threeArgs)); |
120 | three_args.emit(9, "nine", 3.141592); | 124 | three_args.emit(9, "nine", 3.141592); |
125 | |||
126 | // Test ignore signals | ||
127 | { | ||
128 | cout << "----------- Testing ignoring arguments for signal." << endl; | ||
129 | using FbTk::MemFunIgnoreArgs; | ||
130 | // Create a signal that emits with three arguments, and connect | ||
131 | // sinks that takes less than three arguments. | ||
132 | Signal<void, string, string, float> more_args; | ||
133 | more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::print)); | ||
134 | more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::takeIt)); | ||
135 | more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::showMessage2)); | ||
136 | more_args.emit("This should be visible for takeIt(string)", | ||
137 | "Visible to the two args function.", | ||
138 | 2.9); | ||
139 | |||
140 | } | ||
141 | |||
121 | } | 142 | } |