Home · All Classes · All Namespaces · Modules · Functions · Files
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 
45  PtrFunctor0(FunctionType fn) : fn(fn) {}
46 
47  ResultType operator()() const { return fn(); }
48 
49  FunctionType fn;
50 };
51 
52 template <class R, class T >
53 struct MemberFunctor0 : public BaseFunctor
54 {
55  typedef R (T::*FunctionType)();
56  typedef R ResultType;
57 
58  MemberFunctor0(T *object, FunctionType fn) : object(object), fn(fn) {}
59 
60  ResultType operator()() const { return (object->*(fn))(); }
61 
62  T *object;
63  FunctionType fn;
64 };
65 
66 template <class R , class Arg1>
67 struct PtrFunctor1 : public BaseFunctor
68 {
69  typedef R (*FunctionType)(Arg1);
70  typedef R ResultType;
71 
72  PtrFunctor1(FunctionType fn) : fn(fn) {}
73 
74  ResultType operator()(Arg1 a1) const { return fn(a1); }
75 
76  FunctionType fn;
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 
85  MemberFunctor1(T *object, FunctionType fn) : object(object), fn(fn) {}
86 
87  ResultType operator()(Arg1 a1) const { return (object->*(fn))(a1); }
88 
89  T *object;
90  FunctionType fn;
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 
99  PtrFunctor2(FunctionType fn) : fn(fn) {}
100 
101  ResultType operator()(Arg1 a1, Arg2 a2) const { return fn(a1, a2); }
102 
103  FunctionType fn;
104 };
105 
106 template <class R, class T , class Arg1, class Arg2>
107 struct MemberFunctor2 : public BaseFunctor
108 {
109  typedef R (T::*FunctionType)(Arg1, Arg2);
110  typedef R ResultType;
111 
112  MemberFunctor2(T *object, FunctionType fn) : object(object), fn(fn) {}
113 
114  ResultType operator()(Arg1 a1, Arg2 a2) const { return (object->*(fn))(a1, a2); }
115 
116  T *object;
117  FunctionType fn;
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 
126  PtrFunctor3(FunctionType fn) : fn(fn) {}
127 
128  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const { return fn(a1, a2, a3); }
129 
130  FunctionType fn;
131 };
132 
133 template <class R, class T , class Arg1, class Arg2, class Arg3>
134 struct MemberFunctor3 : public BaseFunctor
135 {
136  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3);
137  typedef R ResultType;
138 
139  MemberFunctor3(T *object, FunctionType fn) : object(object), fn(fn) {}
140 
141  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const { return (object->*(fn))(a1, a2, a3); }
142 
143  T *object;
144  FunctionType fn;
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 
153  PtrFunctor4(FunctionType fn) : fn(fn) {}
154 
155  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const { return fn(a1, a2, a3, a4); }
156 
157  FunctionType fn;
158 };
159 
160 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4>
161 struct MemberFunctor4 : public BaseFunctor
162 {
163  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4);
164  typedef R ResultType;
165 
166  MemberFunctor4(T *object, FunctionType fn) : object(object), fn(fn) {}
167 
168  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const { return (object->*(fn))(a1, a2, a3, a4); }
169 
170  T *object;
171  FunctionType fn;
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 
180  PtrFunctor5(FunctionType fn) : fn(fn) {}
181 
182  ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const { return fn(a1, a2, a3, a4, a5); }
183 
184  FunctionType fn;
185 };
186 
187 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
188 struct MemberFunctor5 : public BaseFunctor
189 {
190  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5);
191  typedef R ResultType;
192 
193  MemberFunctor5(T *object, FunctionType fn) : object(object), fn(fn) {}
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;
198  FunctionType fn;
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 
207  PtrFunctor6(FunctionType fn) : fn(fn) {}
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 
211  FunctionType fn;
212 };
213 
214 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
215 struct MemberFunctor6 : public BaseFunctor
216 {
217  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
218  typedef R ResultType;
219 
220  MemberFunctor6(T *object, FunctionType fn) : object(object), fn(fn) {}
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;
225  FunctionType fn;
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 
234  PtrFunctor7(FunctionType fn) : fn(fn) {}
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 
238  FunctionType fn;
239 };
240 
241 template <class R, class T , class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
242 struct MemberFunctor7 : public BaseFunctor
243 {
244  typedef R (T::*FunctionType)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
245  typedef R ResultType;
246 
247  MemberFunctor7(T *object, FunctionType fn) : object(object), fn(fn) {}
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;
252  FunctionType fn;
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>
266 ptrFun(R (*fn)(Arg1) )
267 { return PtrFunctor1<R, Arg1>(fn); }
268 
269 template <class R, class Arg1, class 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>
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>
281 ptrFun(R (*fn)(Arg1, Arg2, Arg3, Arg4) )
283 
284 template <class R, class Arg1, class Arg2, class Arg3, class Arg4, class 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>
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>
296 ptrFun(R (*fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) )
298 
299 // memFun
300 
301 template <class R, class T>
303 memFun( T *obj, R (T::*fn)() )
304 { return MemberFunctor0<R, T>(obj, fn); }
305 
306 template <class R, class T, class 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>
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>
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>
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>
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>
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>
338 memFun( T *obj, R (T::*fn)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) )
340 
341 }
342 
343 #endif
PtrFunctor1(FunctionType fn)
Definition: functors.h:72
FunctionType fn
Definition: functors.h:252
FunctionType fn
Definition: functors.h:157
Definition: functors.h:40
FunctionType fn
Definition: functors.h:198
R ResultType
Definition: functors.h:205
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
Definition: functors.h:168
T * object
Definition: functors.h:251
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
Definition: functors.h:249
R ResultType
Definition: functors.h:245
ResultType operator()(Arg1 a1, Arg2 a2) const
Definition: functors.h:101
Definition: functors.h:121
PtrFunctor0(FunctionType fn)
Definition: functors.h:45
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
Definition: functors.h:141
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6, Arg7 a7) const
Definition: functors.h:236
Definition: functors.h:80
MemberFunctor3(T *object, FunctionType fn)
Definition: functors.h:139
T * object
Definition: functors.h:116
MemberFunctor0(T *object, FunctionType fn)
Definition: functors.h:58
Definition: functors.h:202
T * object
Definition: functors.h:224
PtrFunctor7(FunctionType fn)
Definition: functors.h:234
FunctionType fn
Definition: functors.h:117
FunctionType fn
Definition: functors.h:225
Definition: functors.h:161
FunctionType fn
Definition: functors.h:49
T * object
Definition: functors.h:143
T * object
Definition: functors.h:197
Definition: functors.h:242
PtrFunctor4(FunctionType fn)
Definition: functors.h:153
FunctionType fn
Definition: functors.h:171
R ResultType
Definition: functors.h:232
PtrFunctor3(FunctionType fn)
Definition: functors.h:126
R ResultType
Definition: functors.h:137
FunctionType fn
Definition: functors.h:238
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
Definition: functors.h:209
MemberFunctor6(T *object, FunctionType fn)
Definition: functors.h:220
FunctionType fn
Definition: functors.h:103
Definition: functors.h:53
ResultType operator()() const
Definition: functors.h:60
PtrFunctor0< R > ptrFun(R(*fn)())
Definition: functors.h:261
R ResultType
Definition: functors.h:178
PtrFunctor2(FunctionType fn)
Definition: functors.h:99
Definition: functors.h:229
FunctionType fn
Definition: functors.h:130
MemberFunctor5(T *object, FunctionType fn)
Definition: functors.h:193
Definition: functors.h:175
FunctionType fn
Definition: functors.h:76
R ResultType
Definition: functors.h:43
PtrFunctor5(FunctionType fn)
Definition: functors.h:180
FunctionType fn
Definition: functors.h:63
Definition: functors.h:94
R ResultType
Definition: functors.h:56
Definition: functors.h:215
FunctionType fn
Definition: functors.h:184
FunctionType fn
Definition: functors.h:90
R ResultType
Definition: functors.h:218
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3) const
Definition: functors.h:128
Definition: functors.h:134
ResultType operator()(Arg1 a1) const
Definition: functors.h:87
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
Definition: functors.h:182
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5, Arg6 a6) const
Definition: functors.h:222
MemberFunctor2(T *object, FunctionType fn)
Definition: functors.h:112
ResultType operator()(Arg1 a1, Arg2 a2) const
Definition: functors.h:114
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4, Arg5 a5) const
Definition: functors.h:195
PtrFunctor6(FunctionType fn)
Definition: functors.h:207
T * object
Definition: functors.h:170
R ResultType
Definition: functors.h:151
R ResultType
Definition: functors.h:191
FunctionType fn
Definition: functors.h:144
Definition: functors.h:67
R ResultType
Definition: functors.h:70
Definition: abstract-adaptor.cpp:31
ResultType operator()(Arg1 a1) const
Definition: functors.h:74
T * object
Definition: functors.h:62
Definition: functors.h:148
MemberFunctor0< R, T > memFun(T *obj, R(T::*fn)())
Definition: functors.h:303
ResultType operator()(Arg1 a1, Arg2 a2, Arg3 a3, Arg4 a4) const
Definition: functors.h:155
Definition: functors.h:107
MemberFunctor7(T *object, FunctionType fn)
Definition: functors.h:247
T * object
Definition: functors.h:89
ResultType operator()() const
Definition: functors.h:47
Definition: functors.h:188
FunctionType fn
Definition: functors.h:211
MemberFunctor4(T *object, FunctionType fn)
Definition: functors.h:166
R ResultType
Definition: functors.h:124
R ResultType
Definition: functors.h:110
Definition: functors.h:35
R ResultType
Definition: functors.h:164
R ResultType
Definition: functors.h:83
R ResultType
Definition: functors.h:97
MemberFunctor1(T *object, FunctionType fn)
Definition: functors.h:85


Copyright © 2008-2011 Collabora Ltd. and Nokia Corporation
Telepathy-Qt 0.9.7