Home · Modules · All Classes · All Namespaces
functors.h
1 
23 #ifndef _TelepathyQt_functors_h_HEADER_GUARD_
24 #define _TelepathyQt_functors_h_HEADER_GUARD_
25 
26 #ifndef IN_TP_QT_HEADER
27 #error IN_TP_QT_HEADER
28 #endif
29 
30 #include <TelepathyQt/Global>
31 
32 namespace Tp
33 {
34 
35 struct TP_QT_EXPORT BaseFunctor
36 {
37 };
38 
39 template <class R >
40 struct PtrFunctor0 : public BaseFunctor
41 {
42  typedef R (*FunctionType)();
43  typedef R ResultType;
44 
46 
47  ResultType operator()() const { return fn(); }
48 
50 };
51 
52 template <class R, class T >
53 struct MemberFunctor0 : public BaseFunctor
54 {
55  typedef R (T::*FunctionType)();
56  typedef R ResultType;
57 
59 
60  ResultType operator()() const { return (object->*(fn))(); }
61 
62  T *object;
64 };
65 
66 template <class R , class Arg1>
67 struct PtrFunctor1 : public BaseFunctor
68 {
69  typedef R (*FunctionType)(Arg1);
70  typedef R ResultType;
71 
73 
74  ResultType operator()(Arg1 a1) const { return fn(a1); }
75 
77 };
78 
79 template <class R, class T , class Arg1>
80 struct MemberFunctor1 : public BaseFunctor
81 {
82  typedef R (T::*FunctionType)(Arg1);
83  typedef R ResultType;
84 
86 
87  ResultType operator()(Arg1 a1) const { return (object->*(fn))(a1); }
88 
89  T *object;
91 };
92 
93 template <class R , class Arg1, class Arg2>
94 struct PtrFunctor2 : public BaseFunctor
95 {
96  typedef R (*FunctionType)(Arg1, Arg2);
97  typedef R ResultType;
98 
100 
101  ResultType operator()(Arg1 a1, Arg2 a2) const { return fn(a1, a2); }
102 
104 };
105 
106 template <class R, class T , class Arg1, class Arg2>
108 {
109  typedef R (T::*FunctionType)(Arg1, Arg2);
110  typedef R ResultType;
111 
113 
114  ResultType operator()(Arg1 a1, Arg2 a2) const { return (object->*(fn))(a1, a2); }
115 
116  T *object;
118 };
119 
120 template <class R , class Arg1, class Arg2, class Arg3>
121 struct PtrFunctor3 : public BaseFunctor
122 {
123  typedef R (*FunctionType)(Arg1, Arg2, Arg3);
124  typedef R ResultType;
125 
127 
128  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const { return fn(a1, a2, a3); }
129 
131 };
132 
133 template <class R, class T , class Arg1, class Arg2, class Arg3>
135 {
136  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3);
137  typedef R ResultType;
138 
140 
141  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const { return (object->*(fn))(a1, a2, a3); }
142 
143  T *object;
145 };
146 
147 template <class R , class Arg1, class Arg2, class Arg3, class Arg4>
148 struct PtrFunctor4 : public BaseFunctor
149 {
150  typedef R (*FunctionType)(Arg1, Arg2, Arg3, Arg4);
151  typedef R ResultType;
152 
154 
155  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const { return fn(a1, a2, a3, a4); }
156 
158 };
159 
160 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4>
162 {
163  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4);
164  typedef R ResultType;
165 
167 
168  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const { return (object->*(fn))(a1, a2, a3, a4); }
169 
170  T *object;
172 };
173 
174 template <class R , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
175 struct PtrFunctor5 : public BaseFunctor
176 {
177  typedef R (*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5);
178  typedef R ResultType;
179 
181 
182  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const { return fn(a1, a2, a3, a4, a5); }
183 
185 };
186 
187 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
189 {
190  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5);
191  typedef R ResultType;
192 
194 
195  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const { return (object->*(fn))(a1, a2, a3, a4, a5); }
196 
197  T *object;
199 };
200 
201 template <class R , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
202 struct PtrFunctor6 : public BaseFunctor
203 {
204  typedef R (*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
205  typedef R ResultType;
206 
208 
209  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const { return fn(a1, a2, a3, a4, a5, a6); }
210 
212 };
213 
214 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
216 {
217  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
218  typedef R ResultType;
219 
221 
222  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const { return (object->*(fn))(a1, a2, a3, a4, a5, a6); }
223 
224  T *object;
226 };
227 
228 template <class R , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
229 struct PtrFunctor7 : public BaseFunctor
230 {
231  typedef R (*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
232  typedef R ResultType;
233 
235 
236  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const { return fn(a1, a2, a3, a4, a5, a6, a7); }
237 
239 };
240 
241 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
243 {
244  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
245  typedef R ResultType;
246 
248 
249  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const { return (object->*(fn))(a1, a2, a3, a4, a5, a6, a7); }
250 
251  T *object;
253 };
254 
255 // convenience methods
256 
257 // ptrFun
258 
259 template <class R>
260 inline PtrFunctor0<R>
261 ptrFun(R (*fn)() )
262 { return PtrFunctor0<R>(fn); }
263 
264 template <class R, class Arg1>
265 inline PtrFunctor1<R, Arg1>
266 ptrFun(R (*fn)(Arg1) )
267 { return PtrFunctor1<R, Arg1>(fn); }
268 
269 template <class R, class Arg1, class Arg2>
270 inline PtrFunctor2<R, Arg1, Arg2>
271 ptrFun(R (*fn)(Arg1, Arg2) )
272 { return PtrFunctor2<R, Arg1, Arg2>(fn); }
273 
274 template <class R, class Arg1, class Arg2, class Arg3>
275 inline PtrFunctor3<R, Arg1, Arg2, Arg3>
276 ptrFun(R (*fn)(Arg1, Arg2, Arg3) )
277 { return PtrFunctor3<R, Arg1, Arg2, Arg3>(fn); }
278 
279 template <class R, class Arg1, class Arg2, class Arg3, class Arg4>
280 inline PtrFunctor4<R, Arg1, Arg2, Arg3, Arg4>
281 ptrFun(R (*fn)(Arg1, Arg2, Arg3, Arg4) )
283 
284 template <class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
285 inline PtrFunctor5<R, Arg1, Arg2, Arg3, Arg4, Arg5>
286 ptrFun(R (*fn)(Arg1, Arg2, Arg3, Arg4, Arg5) )
288 
289 template <class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
290 inline PtrFunctor6<R, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>
291 ptrFun(R (*fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) )
293 
294 template <class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
295 inline PtrFunctor7<R, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>
296 ptrFun(R (*fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) )
298 
299 // memFun
300 
301 template <class R, class T>
302 inline MemberFunctor0<R, T>
303 memFun( T *obj, R (T::*fn)() )
304 { return MemberFunctor0<R, T>(obj, fn); }
305 
306 template <class R, class T, class Arg1>
307 inline MemberFunctor1<R, T, Arg1>
308 memFun( T *obj, R (T::*fn)(Arg1) )
309 { return MemberFunctor1<R, T, Arg1>(obj, fn); }
310 
311 template <class R, class T, class Arg1, class Arg2>
312 inline MemberFunctor2<R, T, Arg1, Arg2>
313 memFun( T *obj, R (T::*fn)(Arg1, Arg2) )
314 { return MemberFunctor2<R, T, Arg1, Arg2>(obj, fn); }
315 
316 template <class R, class T, class Arg1, class Arg2, class Arg3>
317 inline MemberFunctor3<R, T, Arg1, Arg2, Arg3>
318 memFun( T *obj, R (T::*fn)(Arg1, Arg2, Arg3) )
319 { return MemberFunctor3<R, T, Arg1, Arg2, Arg3>(obj, fn); }
320 
321 template <class R, class T, class Arg1, class Arg2, class Arg3, class Arg4>
322 inline MemberFunctor4<R, T, Arg1, Arg2, Arg3, Arg4>
323 memFun( T *obj, R (T::*fn)(Arg1, Arg2, Arg3, Arg4) )
325 
326 template <class R, class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
327 inline MemberFunctor5<R, T, Arg1, Arg2, Arg3, Arg4, Arg5>
328 memFun( T *obj, R (T::*fn)(Arg1, Arg2, Arg3, Arg4, Arg5) )
330 
331 template <class R, class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
332 inline MemberFunctor6<R, T, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>
333 memFun( T *obj, R (T::*fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6) )
335 
336 template <class R, class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
337 inline MemberFunctor7<R, T, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>
338 memFun( T *obj, R (T::*fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) )
340 
341 }
342 
343 #endif
MemberFunctor0(T *object, FunctionType fn)
Definition: functors.h:58
MemberFunctor4(T *object, FunctionType fn)
Definition: functors.h:166
FunctionType fn
Definition: functors.h:103
R(* FunctionType)(Arg1, Arg2, Arg3, Arg4)
Definition: functors.h:150
PtrFunctor7(FunctionType fn)
Definition: functors.h:234
FunctionType fn
Definition: functors.h:144
R(T::* FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)
Definition: functors.h:244
T * object
Definition: functors.h:197
Definition: functors.h:121
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
Definition: functors.h:222
R ResultType
Definition: functors.h:232
Definition: functors.h:80
R(* FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5)
Definition: functors.h:177
R(* FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)
Definition: functors.h:231
R ResultType
Definition: functors.h:205
R ResultType
Definition: functors.h:191
ResultType operator()(Arg1 a1) const
Definition: functors.h:74
PtrFunctor0< R > ptrFun(R(*fn)())
Definition: functors.h:261
MemberFunctor1(T *object, FunctionType fn)
Definition: functors.h:85
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
Definition: functors.h:249
R(T::* FunctionType)(Arg1, Arg2, Arg3)
Definition: functors.h:136
R ResultType
Definition: functors.h:178
R(T::* FunctionType)(Arg1, Arg2, Arg3, Arg4)
Definition: functors.h:163
FunctionType fn
Definition: functors.h:117
MemberFunctor0< R, T > memFun(T *obj, R(T::*fn)())
Definition: functors.h:303
ResultType operator()(Arg1 a1) const
Definition: functors.h:87
FunctionType fn
Definition: functors.h:49
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
Definition: functors.h:209
Definition: functors.h:175
Definition: functors.h:134
R(T::* FunctionType)()
Definition: functors.h:55
R(T::* FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)
Definition: functors.h:217
R ResultType
Definition: functors.h:56
PtrFunctor4(FunctionType fn)
Definition: functors.h:153
Definition: functors.h:242
R ResultType
Definition: functors.h:70
T * object
Definition: functors.h:62
Definition: functors.h:202
FunctionType fn
Definition: functors.h:252
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
Definition: functors.h:195
MemberFunctor6(T *object, FunctionType fn)
Definition: functors.h:220
FunctionType fn
Definition: functors.h:130
FunctionType fn
Definition: functors.h:157
FunctionType fn
Definition: functors.h:184
R ResultType
Definition: functors.h:43
R(T::* FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5)
Definition: functors.h:190
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
Definition: functors.h:128
R(* FunctionType)()
Definition: functors.h:42
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
Definition: functors.h:236
R ResultType
Definition: functors.h:151
R(T::* FunctionType)(Arg1)
Definition: functors.h:82
R ResultType
Definition: functors.h:97
PtrFunctor0(FunctionType fn)
Definition: functors.h:45
FunctionType fn
Definition: functors.h:211
R(* FunctionType)(Arg1, Arg2, Arg3)
Definition: functors.h:123
MemberFunctor2(T *object, FunctionType fn)
Definition: functors.h:112
R(* FunctionType)(Arg1, Arg2)
Definition: functors.h:96
ResultType operator()() const
Definition: functors.h:60
ResultType operator()(Arg1 a1, Arg2 a2) const
Definition: functors.h:101
R ResultType
Definition: functors.h:110
ResultType operator()(Arg1 a1, Arg2 a2) const
Definition: functors.h:114
R(* FunctionType)(Arg1)
Definition: functors.h:69
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
Definition: functors.h:141
PtrFunctor5(FunctionType fn)
Definition: functors.h:180
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
Definition: functors.h:182
Definition: functors.h:40
Definition: functors.h:161
T * object
Definition: functors.h:224
R ResultType
Definition: functors.h:218
R ResultType
Definition: functors.h:245
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
Definition: functors.h:168
PtrFunctor1(FunctionType fn)
Definition: functors.h:72
FunctionType fn
Definition: functors.h:225
PtrFunctor6(FunctionType fn)
Definition: functors.h:207
T * object
Definition: functors.h:170
Definition: functors.h:107
Definition: functors.h:229
T * object
Definition: functors.h:89
Definition: functors.h:67
T * object
Definition: functors.h:143
Definition: functors.h:188
PtrFunctor2(FunctionType fn)
Definition: functors.h:99
FunctionType fn
Definition: functors.h:63
Definition: functors.h:148
T * object
Definition: functors.h:251
R ResultType
Definition: functors.h:164
MemberFunctor3(T *object, FunctionType fn)
Definition: functors.h:139
R ResultType
Definition: functors.h:137
R ResultType
Definition: functors.h:124
FunctionType fn
Definition: functors.h:171
PtrFunctor3(FunctionType fn)
Definition: functors.h:126
Definition: functors.h:215
T * object
Definition: functors.h:116
FunctionType fn
Definition: functors.h:198
Definition: functors.h:35
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
Definition: functors.h:155
R(* FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)
Definition: functors.h:204
FunctionType fn
Definition: functors.h:76
ResultType operator()() const
Definition: functors.h:47
FunctionType fn
Definition: functors.h:238
Definition: abstract-adaptor.cpp:31
FunctionType fn
Definition: functors.h:90
MemberFunctor7(T *object, FunctionType fn)
Definition: functors.h:247
R(T::* FunctionType)(Arg1, Arg2)
Definition: functors.h:109
Definition: functors.h:94
MemberFunctor5(T *object, FunctionType fn)
Definition: functors.h:193
Definition: functors.h:53
R ResultType
Definition: functors.h:83