6
#ifndef SQUID_ASYNCJOBCALLS_H
7
#define SQUID_ASYNCJOBCALLS_H
9
#include "base/AsyncJob.h"
12
* *MemFunT are member function (i.e., class method) wrappers. They store
13
* details of a method call in an object so that the call can be delayed
14
* and executed asynchronously. Details may include the object pointer,
15
* the handler method pointer, and parameters. To simplify, we require
16
* all handlers to return void and not be constant.
20
* We need one wrapper for every supported member function arity (i.e.,
21
* number of handler arguments). The first template parameter is the class
22
* type of the handler. That class must be an AsyncJob child.
25
// Arity names are from http://en.wikipedia.org/wiki/Arity
28
class NullaryMemFunT: public JobDialer
31
typedef void (C::*Method)();
32
explicit NullaryMemFunT(C *anObject, Method aMethod):
33
JobDialer(anObject), object(anObject), method(aMethod) {}
35
virtual void print(std::ostream &os) const { os << "()"; }
42
virtual void doDial() { (object->*method)(); }
45
template <class C, class Argument1>
46
class UnaryMemFunT: public JobDialer
49
typedef void (C::*Method)(Argument1);
50
explicit UnaryMemFunT(C *anObject, Method aMethod, const Argument1 &anArg1):
52
object(anObject), method(aMethod), arg1(anArg1) {}
54
virtual void print(std::ostream &os) const { os << '(' << arg1 << ')'; }
62
virtual void doDial() { (object->*method)(arg1); }
65
// ... add more as needed
68
// Now we add global templated functions that create the member function
69
// wrappers above. These are for convenience: it is often easier to
70
// call a templated function than to create a templated object.
74
MemFun(C *object, typename NullaryMemFunT<C>::Method method)
76
return NullaryMemFunT<C>(object, method);
79
template <class C, class Argument1>
80
UnaryMemFunT<C, Argument1>
81
MemFun(C *object, typename UnaryMemFunT<C, Argument1>::Method method,
84
return UnaryMemFunT<C, Argument1>(object, method, arg1);
87
#endif /* SQUID_ASYNCJOBCALLS_H */