]> git.ipfire.org Git - thirdparty/squid.git/blame - src/AsyncJobCalls.h
Merging async-call branch changes to HEAD:
[thirdparty/squid.git] / src / AsyncJobCalls.h
CommitLineData
0edbef7e 1
2/*
3 * $Id: AsyncJobCalls.h,v 1.1 2008/02/13 05:51:55 rousskov Exp $
4 */
5
6#ifndef SQUID_ASYNCJOBCALLS_H
7#define SQUID_ASYNCJOBCALLS_H
8
9#include "ICAP/AsyncJob.h"
10
11/*
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.
17 */
18
19/*
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.
23 */
24
25// Arity names are from http://en.wikipedia.org/wiki/Arity
26
27template <class C>
28class NullaryMemFunT: public JobDialer
29{
30public:
31 typedef void (C::*Method)();
32 explicit NullaryMemFunT(C *anObject, Method aMethod):
33 JobDialer(anObject), object(anObject), method(aMethod) {}
34
35 virtual void print(std::ostream &os) const { os << "()"; }
36
37public:
38 C *object;
39 Method method;
40
41protected:
42 virtual void doDial() { (object->*method)(); }
43};
44
45template <class C, class Argument1>
46class UnaryMemFunT: public JobDialer
47{
48public:
49 typedef void (C::*Method)(Argument1);
50 explicit UnaryMemFunT(C *anObject, Method aMethod, const Argument1 &anArg1):
51 JobDialer(anObject),
52 object(anObject), method(aMethod), arg1(anArg1) {}
53
54 virtual void print(std::ostream &os) const { os << '(' << arg1 << ')'; }
55
56public:
57 C *object;
58 Method method;
59 Argument1 arg1;
60
61protected:
62 virtual void doDial() { (object->*method)(arg1); }
63};
64
65// ... add more as needed
66
67
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.
71
72template <class C>
73NullaryMemFunT<C>
74MemFun(C *object, typename NullaryMemFunT<C>::Method method)
75{
76 return NullaryMemFunT<C>(object, method);
77}
78
79template <class C, class Argument1>
80UnaryMemFunT<C, Argument1>
81MemFun(C *object, typename UnaryMemFunT<C, Argument1>::Method method,
82 Argument1 arg1)
83{
84 return UnaryMemFunT<C, Argument1>(object, method, arg1);
85}
86
87#endif /* SQUID_ASYNCJOBCALLS_H */