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/FbTk/MemFun.hh | |
parent | 68e90ab84fc8720264694de47c1ac33c401b49e5 (diff) | |
download | fluxbox_pavel-ceff86b79401c27ed83cad65f59a6621c9a58084.zip fluxbox_pavel-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/FbTk/MemFun.hh')
-rw-r--r-- | src/FbTk/MemFun.hh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/FbTk/MemFun.hh b/src/FbTk/MemFun.hh index 0425fc6..d265703 100644 --- a/src/FbTk/MemFun.hh +++ b/src/FbTk/MemFun.hh | |||
@@ -22,6 +22,8 @@ | |||
22 | #ifndef FBTK_MEM_FUN_HH | 22 | #ifndef FBTK_MEM_FUN_HH |
23 | #define FBTK_MEM_FUN_HH | 23 | #define FBTK_MEM_FUN_HH |
24 | 24 | ||
25 | #include "SelectArg.hh" | ||
26 | |||
25 | namespace FbTk { | 27 | namespace FbTk { |
26 | 28 | ||
27 | /// No argument functor | 29 | /// No argument functor |
@@ -218,6 +220,60 @@ MemFunIgnoreArgs( Object& obj, ReturnType (Object:: *action)(Arg1,Arg2) ) { | |||
218 | return MemFun2IgnoreArgs<ReturnType, Object, Arg1, Arg2>(obj, action); | 220 | return MemFun2IgnoreArgs<ReturnType, Object, Arg1, Arg2>(obj, action); |
219 | } | 221 | } |
220 | 222 | ||
223 | /** | ||
224 | * Creates a functor that selects a specific argument of three possible ones | ||
225 | * and uses it for the single argument operator. | ||
226 | */ | ||
227 | template < int ArgNum, typename Functor> | ||
228 | class MemFunSelectArgImpl { | ||
229 | public: | ||
230 | |||
231 | MemFunSelectArgImpl(Functor func): | ||
232 | m_func(func) { | ||
233 | } | ||
234 | |||
235 | template <typename Type1, typename Type2, typename Type3> | ||
236 | void operator ()(Type1 a, Type2 b, Type3 c) { | ||
237 | m_func(STLUtil::SelectArg<ArgNum>()(a, b, c)); | ||
238 | } | ||
239 | |||
240 | template <typename Type1, typename Type2> | ||
241 | void operator ()(Type1 a, Type2 b) { | ||
242 | m_func(STLUtil::SelectArg<ArgNum>()(a, b)); | ||
243 | } | ||
244 | |||
245 | template <typename Type1> | ||
246 | void operator ()(Type1 a) { | ||
247 | m_func(a); | ||
248 | } | ||
249 | |||
250 | private: | ||
251 | Functor m_func; | ||
252 | }; | ||
253 | |||
254 | /// Creates a functor that selects the first argument of three possible ones | ||
255 | /// and uses it for the single argument operator. | ||
256 | template <typename ReturnType, typename Object, typename Arg1> | ||
257 | MemFunSelectArgImpl<0, MemFun1<ReturnType, Object, Arg1> > | ||
258 | MemFunSelectArg0(Object& obj, ReturnType (Object:: *action)(Arg1)) { | ||
259 | return MemFunSelectArgImpl<0, MemFun1<ReturnType, Object, Arg1> >(MemFun(obj, action)); | ||
260 | } | ||
261 | |||
262 | /// Creates a functor that selects the second argument (or first if there is | ||
263 | /// only one) of three possible onesand uses it for the single argument operator. | ||
264 | template <typename ReturnType, typename Object, typename Arg1> | ||
265 | MemFunSelectArgImpl<1, MemFun1<ReturnType, Object, Arg1> > | ||
266 | MemFunSelectArg1(Object& obj, ReturnType (Object:: *action)(Arg1)) { | ||
267 | return MemFunSelectArgImpl<1, MemFun1<ReturnType, Object, Arg1> >(MemFun(obj, action)); | ||
268 | } | ||
269 | |||
270 | /// Creates a functor that selects the third argument (or the last argument if there is | ||
271 | /// less than three arguments) of three possible onesand uses it for the single argument operator. | ||
272 | template <typename ReturnType, typename Object, typename Arg1> | ||
273 | MemFunSelectArgImpl<2, MemFun1<ReturnType, Object, Arg1> > | ||
274 | MemFunSelectArg2(Object& obj, ReturnType (Object:: *action)(Arg1)) { | ||
275 | return MemFunSelectArgImpl<2, MemFun1<ReturnType, Object, Arg1> >(MemFun(obj, action)); | ||
276 | } | ||
221 | 277 | ||
222 | } // namespace FbTk | 278 | } // namespace FbTk |
223 | 279 | ||