aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-05 15:07:32 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-05-10 11:00:45 (GMT)
commit19ac8e40d85235328e0e2c7c428a2d3e1e86872c (patch)
tree8cdfe2491657b38614b4bd6329102c0463d60db2 /src/FbTk
parent6cfa087536abf3328cabbe867df978309034edc9 (diff)
downloadfluxbox_paul-19ac8e40d85235328e0e2c7c428a2d3e1e86872c.zip
fluxbox_paul-19ac8e40d85235328e0e2c7c428a2d3e1e86872c.tar.bz2
Added FbTk::MemFunBind - a functor which binds all arguments of a function
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/MemFun.hh94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/FbTk/MemFun.hh b/src/FbTk/MemFun.hh
index 63f922e..73134d2 100644
--- a/src/FbTk/MemFun.hh
+++ b/src/FbTk/MemFun.hh
@@ -276,6 +276,100 @@ MemFunSelectArg2(Object& obj, ReturnType (Object:: *action)(Arg1)) {
276 return MemFunSelectArgImpl<2, MemFun1<ReturnType, Object, Arg1>, ReturnType>(MemFun(obj, action)); 276 return MemFunSelectArgImpl<2, MemFun1<ReturnType, Object, Arg1>, ReturnType>(MemFun(obj, action));
277} 277}
278 278
279/// Creates a functor with a bound parameter
280template<typename ReturnType, typename Object, typename Arg1>
281class MemFunBind1 {
282public:
283 typedef ReturnType (Object:: *Action)(Arg1);
284
285 MemFunBind1(Object& obj, Action action, Arg1 arg1):
286 m_obj(obj),
287 m_action(action),
288 m_arg1(arg1) {
289 }
290
291 ReturnType operator()() const {
292 return (m_obj.*m_action)(m_arg1);
293 }
294
295private:
296 Object& m_obj;
297 Action m_action;
298 Arg1 m_arg1;
299};
300
301/// Creates a functor with a bound parameter
302template<typename ReturnType, typename Object, typename Arg1>
303MemFunBind1<ReturnType, Object, Arg1>
304MemFunBind( Object& obj, ReturnType (Object:: *action)(Arg1), Arg1 arg1 ) {
305 return MemFunBind1<ReturnType, Object, Arg1>(obj, action, arg1);
306}
307
308/// Creates a functor with a bound parameter
309template<typename ReturnType, typename Object, typename Arg1, typename Arg2>
310class MemFunBind2 {
311public:
312 typedef ReturnType (Object:: *Action)(Arg1, Arg2);
313
314 MemFunBind2(Object& obj, Action action, Arg1 arg1, Arg2 arg2):
315 m_obj(obj),
316 m_action(action),
317 m_arg1(arg1),
318 m_arg2(arg2) {
319 }
320
321 ReturnType operator()() const {
322 return (m_obj.*m_action)(m_arg1, m_arg2);
323 }
324
325private:
326 Object& m_obj;
327 Action m_action;
328 Arg1 m_arg1;
329 Arg2 m_arg2;
330};
331
332/// Creates a functor with a bound parameter
333template<typename ReturnType, typename Object, typename Arg1, typename Arg2>
334MemFunBind2<ReturnType, Object, Arg1, Arg2>
335MemFunBind( Object& obj, ReturnType (Object:: *action)(Arg1, Arg2), Arg1 arg1, Arg2 arg2 ) {
336 return MemFunBind2<ReturnType, Object, Arg1, Arg2>(obj, action, arg1, arg2);
337}
338
339/// Creates a functor with a bound parameter
340template<typename ReturnType, typename Object, typename Arg1, typename Arg2, typename Arg3>
341class MemFunBind3 {
342public:
343 typedef ReturnType (Object:: *Action)(Arg1, Arg2, Arg3);
344
345 MemFunBind3(Object& obj, Action action, Arg1 arg1, Arg2 arg2, Arg3 arg3):
346 m_obj(obj),
347 m_action(action),
348 m_arg1(arg1),
349 m_arg2(arg2),
350 m_arg3(arg3) {
351 }
352
353 ReturnType operator()() const {
354 return (m_obj.*m_action)(m_arg1, m_arg2, m_arg3);
355 }
356
357private:
358 Object& m_obj;
359 Action m_action;
360 Arg1 m_arg1;
361 Arg2 m_arg2;
362 Arg3 m_arg3;
363};
364
365/// Creates a functor with a bound parameter
366template<typename ReturnType, typename Object, typename Arg1, typename Arg2, typename Arg3>
367MemFunBind2<ReturnType, Object, Arg1, Arg2>
368MemFunBind( Object& obj, ReturnType (Object:: *action)(Arg1, Arg2, Arg3),
369 Arg1 arg1, Arg2 arg2, Arg3 arg3 ) {
370 return MemFunBind3<ReturnType, Object, Arg1, Arg2, Arg3>(obj, action, arg1, arg2, arg3);
371}
372
279} // namespace FbTk 373} // namespace FbTk
280 374
281#endif // FBTK_MEM_FUN_HH 375#endif // FBTK_MEM_FUN_HH