ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.h
(Generate patch)

Comparing gvpe/src/callback.h (file contents):
Revision 1.10 by pcg, Wed May 31 00:31:47 2006 UTC vs.
Revision 1.12 by pcg, Tue Dec 4 15:01:12 2007 UTC

2// THIS IS A GENERATED FILE: callback.pl is part of the GVPE 2// THIS IS A GENERATED FILE: callback.pl is part of the GVPE
3// THIS IS A GENERATED FILE: distribution. 3// THIS IS A GENERATED FILE: distribution.
4 4
5/* 5/*
6 callback.h -- C++ callback mechanism 6 callback.h -- C++ callback mechanism
7 Copyright (C) 2003-2006 Marc Lehmann <pcg@goof.com> 7 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com>
8 8
9 This file is part of GVPE. 9 This file is part of GVPE.
10 10
11 GVPE is free software; you can redistribute it and/or modify 11 GVPE is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 it under the terms of the GNU General Public License as published by
24*/ 24*/
25 25
26#ifndef CALLBACK_H__ 26#ifndef CALLBACK_H__
27#define CALLBACK_H__ 27#define CALLBACK_H__
28 28
29#define CALLBACK_H_VERSION 2 29#define CALLBACK_H_VERSION 3
30 30
31template<class signature> 31template<typename signature>
32struct callback_funtype_trait;
33
34template<int arity, class signature>
35struct callback_get_impl; 32struct callback;
33
34#define callback_set(callback,obj,klass,method) callback.set<klass, &klass::method> (obj)
36 35
37template<class R> 36template<class R>
38class callback0 37struct callback<R ()>
39{ 38{
40 struct object { }; 39 typedef R (*ptr_type)(void *self);
41 40
42 typedef R (object::*ptr_type)(); 41private:
43 42
44 void *obj; 43 void *self;
45 R (object::*meth)(); 44 ptr_type func;
46 45
47 /* a proxy is a kind of recipe on how to call a specific class method */ 46protected:
48 struct proxy_base { 47
49 virtual R call (void *obj, R (object::*meth)()) const = 0; 48 template<typename method>
49 struct thunktype;
50
51 template<class klass>
52 struct thunktype<R (klass::*)>
53 {
54 typedef klass K;
55 };
56
57 template<class klass, R (klass::*method)()>
58 static R thunk (void *self)
59 {
60 klass *obj = static_cast<klass *>(self);
61 return (obj->*method) ();
50 }; 62 }
51 template<class O1, class O2> 63
52 struct proxy : proxy_base { 64public:
53 virtual R call (void *obj, R (object::*meth)()) const 65 template<class K, R (K::*method)()>
54 { 66 void set (K *object)
55 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)()>(meth))) 67 {
56 (); 68 self = object;
57 } 69 func = thunk<K, method>;
58 }; 70 }
59 71
60 proxy_base *prxy;
61
62public:
63 template<class O1, class O2>
64 explicit callback0 (O1 *object, R (O2::*method)())
65 {
66 static proxy<O1,O2> p;
67 obj = reinterpret_cast<void *>(object);
68 meth = reinterpret_cast<R (object::*)()>(method);
69 prxy = &p;
70 }
71
72 R call() const 72 R call () const
73 { 73 {
74 return prxy->call (obj, meth); 74 return func (self);
75 } 75 }
76 76
77 R operator ()() const 77 R operator ()() const
78 { 78 {
79 return call (); 79 return call ();
80 }
81};
82
83template<class R>
84struct callback_funtype_trait0
85{
86 static const int arity = 0;
87 typedef R type (void);
88 typedef R result_type;
89 80 }
90}; 81};
91 82
92template<class R>
93struct callback_funtype_trait<R ()> : callback_funtype_trait0<R>
94{
95};
96
97template<class signature>
98struct callback_get_impl<0, signature>
99{
100 typedef callback_funtype_trait<signature> T;
101 typedef callback0<typename T::result_type> type;
102};
103
104template<class R, class A1> 83template<class R, class A1>
105class callback1 84struct callback<R (A1)>
106{ 85{
107 struct object { }; 86 typedef R (*ptr_type)(void *self, A1);
108 87
109 typedef R (object::*ptr_type)(A1); 88private:
110 89
111 void *obj; 90 void *self;
112 R (object::*meth)(A1); 91 ptr_type func;
113 92
114 /* a proxy is a kind of recipe on how to call a specific class method */ 93protected:
115 struct proxy_base { 94
116 virtual R call (void *obj, R (object::*meth)(A1), A1 a1) const = 0; 95 template<typename method>
96 struct thunktype;
97
98 template<class klass>
99 struct thunktype<R (klass::*)>
100 {
101 typedef klass K;
102 };
103
104 template<class klass, R (klass::*method)(A1)>
105 static R thunk (void *self, A1 a1)
106 {
107 klass *obj = static_cast<klass *>(self);
108 return (obj->*method) (a1);
117 }; 109 }
118 template<class O1, class O2> 110
119 struct proxy : proxy_base { 111public:
120 virtual R call (void *obj, R (object::*meth)(A1), A1 a1) const 112 template<class K, R (K::*method)(A1)>
121 { 113 void set (K *object)
122 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1)>(meth))) 114 {
123 (a1); 115 self = object;
124 } 116 func = thunk<K, method>;
125 }; 117 }
126 118
127 proxy_base *prxy;
128
129public:
130 template<class O1, class O2>
131 explicit callback1 (O1 *object, R (O2::*method)(A1))
132 {
133 static proxy<O1,O2> p;
134 obj = reinterpret_cast<void *>(object);
135 meth = reinterpret_cast<R (object::*)(A1)>(method);
136 prxy = &p;
137 }
138
139 R call(A1 a1) const 119 R call (A1 a1) const
140 { 120 {
141 return prxy->call (obj, meth, a1); 121 return func (self, a1);
142 } 122 }
143 123
144 R operator ()(A1 a1) const 124 R operator ()(A1 a1) const
145 { 125 {
146 return call (a1); 126 return call (a1);
147 } 127 }
148}; 128};
149 129
150template<class R, class A1>
151struct callback_funtype_trait1
152{
153 static const int arity = 1;
154 typedef R type (A1);
155 typedef R result_type;
156 typedef A1 arg1_type;
157};
158
159template<class R, class A1>
160struct callback_funtype_trait<R (A1)> : callback_funtype_trait1<R, A1>
161{
162};
163
164template<class signature>
165struct callback_get_impl<1, signature>
166{
167 typedef callback_funtype_trait<signature> T;
168 typedef callback1<typename T::result_type, typename T::arg1_type> type;
169};
170
171template<class R, class A1, class A2> 130template<class R, class A1, class A2>
172class callback2 131struct callback<R (A1, A2)>
173{ 132{
174 struct object { };
175
176 typedef R (object::*ptr_type)(A1, A2); 133 typedef R (*ptr_type)(void *self, A1, A2);
177 134
178 void *obj; 135private:
179 R (object::*meth)(A1, A2);
180 136
181 /* a proxy is a kind of recipe on how to call a specific class method */ 137 void *self;
182 struct proxy_base { 138 ptr_type func;
183 virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2) const = 0; 139
140protected:
141
142 template<typename method>
143 struct thunktype;
144
145 template<class klass>
146 struct thunktype<R (klass::*)>
147 {
148 typedef klass K;
149 };
150
151 template<class klass, R (klass::*method)(A1, A2)>
152 static R thunk (void *self, A1 a1, A2 a2)
153 {
154 klass *obj = static_cast<klass *>(self);
155 return (obj->*method) (a1, a2);
184 }; 156 }
185 template<class O1, class O2> 157
186 struct proxy : proxy_base { 158public:
187 virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2) const 159 template<class K, R (K::*method)(A1, A2)>
188 { 160 void set (K *object)
189 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2)>(meth))) 161 {
190 (a1, a2); 162 self = object;
191 } 163 func = thunk<K, method>;
192 }; 164 }
193 165
194 proxy_base *prxy;
195
196public:
197 template<class O1, class O2>
198 explicit callback2 (O1 *object, R (O2::*method)(A1, A2))
199 {
200 static proxy<O1,O2> p;
201 obj = reinterpret_cast<void *>(object);
202 meth = reinterpret_cast<R (object::*)(A1, A2)>(method);
203 prxy = &p;
204 }
205
206 R call(A1 a1, A2 a2) const 166 R call (A1 a1, A2 a2) const
207 { 167 {
208 return prxy->call (obj, meth, a1, a2); 168 return func (self, a1, a2);
209 } 169 }
210 170
211 R operator ()(A1 a1, A2 a2) const 171 R operator ()(A1 a1, A2 a2) const
212 { 172 {
213 return call (a1, a2); 173 return call (a1, a2);
214 } 174 }
215}; 175};
216 176
217template<class R, class A1, class A2>
218struct callback_funtype_trait2
219{
220 static const int arity = 2;
221 typedef R type (A1, A2);
222 typedef R result_type;
223 typedef A1 arg1_type; typedef A2 arg2_type;
224};
225
226template<class R, class A1, class A2>
227struct callback_funtype_trait<R (A1, A2)> : callback_funtype_trait2<R, A1, A2>
228{
229};
230
231template<class signature>
232struct callback_get_impl<2, signature>
233{
234 typedef callback_funtype_trait<signature> T;
235 typedef callback2<typename T::result_type, typename T::arg1_type, typename T::arg2_type> type;
236};
237
238template<class R, class A1, class A2, class A3> 177template<class R, class A1, class A2, class A3>
239class callback3 178struct callback<R (A1, A2, A3)>
240{ 179{
241 struct object { };
242
243 typedef R (object::*ptr_type)(A1, A2, A3); 180 typedef R (*ptr_type)(void *self, A1, A2, A3);
244 181
245 void *obj; 182private:
246 R (object::*meth)(A1, A2, A3);
247 183
248 /* a proxy is a kind of recipe on how to call a specific class method */ 184 void *self;
249 struct proxy_base { 185 ptr_type func;
250 virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3) const = 0; 186
187protected:
188
189 template<typename method>
190 struct thunktype;
191
192 template<class klass>
193 struct thunktype<R (klass::*)>
194 {
195 typedef klass K;
196 };
197
198 template<class klass, R (klass::*method)(A1, A2, A3)>
199 static R thunk (void *self, A1 a1, A2 a2, A3 a3)
200 {
201 klass *obj = static_cast<klass *>(self);
202 return (obj->*method) (a1, a2, a3);
251 }; 203 }
252 template<class O1, class O2> 204
253 struct proxy : proxy_base { 205public:
254 virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3) const 206 template<class K, R (K::*method)(A1, A2, A3)>
255 { 207 void set (K *object)
256 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3)>(meth))) 208 {
257 (a1, a2, a3); 209 self = object;
258 } 210 func = thunk<K, method>;
259 }; 211 }
260 212
261 proxy_base *prxy;
262
263public:
264 template<class O1, class O2>
265 explicit callback3 (O1 *object, R (O2::*method)(A1, A2, A3))
266 {
267 static proxy<O1,O2> p;
268 obj = reinterpret_cast<void *>(object);
269 meth = reinterpret_cast<R (object::*)(A1, A2, A3)>(method);
270 prxy = &p;
271 }
272
273 R call(A1 a1, A2 a2, A3 a3) const 213 R call (A1 a1, A2 a2, A3 a3) const
274 { 214 {
275 return prxy->call (obj, meth, a1, a2, a3); 215 return func (self, a1, a2, a3);
276 } 216 }
277 217
278 R operator ()(A1 a1, A2 a2, A3 a3) const 218 R operator ()(A1 a1, A2 a2, A3 a3) const
279 { 219 {
280 return call (a1, a2, a3); 220 return call (a1, a2, a3);
281 } 221 }
282}; 222};
283 223
284template<class R, class A1, class A2, class A3>
285struct callback_funtype_trait3
286{
287 static const int arity = 3;
288 typedef R type (A1, A2, A3);
289 typedef R result_type;
290 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type;
291};
292
293template<class R, class A1, class A2, class A3>
294struct callback_funtype_trait<R (A1, A2, A3)> : callback_funtype_trait3<R, A1, A2, A3>
295{
296};
297
298template<class signature>
299struct callback_get_impl<3, signature>
300{
301 typedef callback_funtype_trait<signature> T;
302 typedef callback3<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type> type;
303};
304
305template<class R, class A1, class A2, class A3, class A4> 224template<class R, class A1, class A2, class A3, class A4>
306class callback4 225struct callback<R (A1, A2, A3, A4)>
307{ 226{
308 struct object { };
309
310 typedef R (object::*ptr_type)(A1, A2, A3, A4); 227 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
311 228
312 void *obj; 229private:
313 R (object::*meth)(A1, A2, A3, A4);
314 230
315 /* a proxy is a kind of recipe on how to call a specific class method */ 231 void *self;
316 struct proxy_base { 232 ptr_type func;
317 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4) const = 0; 233
234protected:
235
236 template<typename method>
237 struct thunktype;
238
239 template<class klass>
240 struct thunktype<R (klass::*)>
241 {
242 typedef klass K;
243 };
244
245 template<class klass, R (klass::*method)(A1, A2, A3, A4)>
246 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4)
247 {
248 klass *obj = static_cast<klass *>(self);
249 return (obj->*method) (a1, a2, a3, a4);
318 }; 250 }
319 template<class O1, class O2> 251
320 struct proxy : proxy_base { 252public:
321 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4) const 253 template<class K, R (K::*method)(A1, A2, A3, A4)>
322 { 254 void set (K *object)
323 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4)>(meth))) 255 {
324 (a1, a2, a3, a4); 256 self = object;
325 } 257 func = thunk<K, method>;
326 }; 258 }
327 259
328 proxy_base *prxy;
329
330public:
331 template<class O1, class O2>
332 explicit callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4))
333 {
334 static proxy<O1,O2> p;
335 obj = reinterpret_cast<void *>(object);
336 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4)>(method);
337 prxy = &p;
338 }
339
340 R call(A1 a1, A2 a2, A3 a3, A4 a4) const 260 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
341 { 261 {
342 return prxy->call (obj, meth, a1, a2, a3, a4); 262 return func (self, a1, a2, a3, a4);
343 } 263 }
344 264
345 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const 265 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
346 { 266 {
347 return call (a1, a2, a3, a4); 267 return call (a1, a2, a3, a4);
348 } 268 }
349}; 269};
350 270
351template<class R, class A1, class A2, class A3, class A4>
352struct callback_funtype_trait4
353{
354 static const int arity = 4;
355 typedef R type (A1, A2, A3, A4);
356 typedef R result_type;
357 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type;
358};
359
360template<class R, class A1, class A2, class A3, class A4>
361struct callback_funtype_trait<R (A1, A2, A3, A4)> : callback_funtype_trait4<R, A1, A2, A3, A4>
362{
363};
364
365template<class signature>
366struct callback_get_impl<4, signature>
367{
368 typedef callback_funtype_trait<signature> T;
369 typedef callback4<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type> type;
370};
371
372template<class R, class A1, class A2, class A3, class A4, class A5> 271template<class R, class A1, class A2, class A3, class A4, class A5>
373class callback5 272struct callback<R (A1, A2, A3, A4, A5)>
374{ 273{
375 struct object { };
376
377 typedef R (object::*ptr_type)(A1, A2, A3, A4, A5); 274 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
378 275
379 void *obj; 276private:
380 R (object::*meth)(A1, A2, A3, A4, A5);
381 277
382 /* a proxy is a kind of recipe on how to call a specific class method */ 278 void *self;
383 struct proxy_base { 279 ptr_type func;
384 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const = 0; 280
281protected:
282
283 template<typename method>
284 struct thunktype;
285
286 template<class klass>
287 struct thunktype<R (klass::*)>
288 {
289 typedef klass K;
290 };
291
292 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5)>
293 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
294 {
295 klass *obj = static_cast<klass *>(self);
296 return (obj->*method) (a1, a2, a3, a4, a5);
385 }; 297 }
386 template<class O1, class O2> 298
387 struct proxy : proxy_base { 299public:
388 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 300 template<class K, R (K::*method)(A1, A2, A3, A4, A5)>
389 { 301 void set (K *object)
390 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5)>(meth))) 302 {
391 (a1, a2, a3, a4, a5); 303 self = object;
392 } 304 func = thunk<K, method>;
393 }; 305 }
394 306
395 proxy_base *prxy;
396
397public:
398 template<class O1, class O2>
399 explicit callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5))
400 {
401 static proxy<O1,O2> p;
402 obj = reinterpret_cast<void *>(object);
403 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5)>(method);
404 prxy = &p;
405 }
406
407 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 307 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
408 { 308 {
409 return prxy->call (obj, meth, a1, a2, a3, a4, a5); 309 return func (self, a1, a2, a3, a4, a5);
410 } 310 }
411 311
412 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const 312 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
413 { 313 {
414 return call (a1, a2, a3, a4, a5); 314 return call (a1, a2, a3, a4, a5);
415 } 315 }
416}; 316};
417 317
418template<class R, class A1, class A2, class A3, class A4, class A5>
419struct callback_funtype_trait5
420{
421 static const int arity = 5;
422 typedef R type (A1, A2, A3, A4, A5);
423 typedef R result_type;
424 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type;
425};
426
427template<class R, class A1, class A2, class A3, class A4, class A5>
428struct callback_funtype_trait<R (A1, A2, A3, A4, A5)> : callback_funtype_trait5<R, A1, A2, A3, A4, A5>
429{
430};
431
432template<class signature>
433struct callback_get_impl<5, signature>
434{
435 typedef callback_funtype_trait<signature> T;
436 typedef callback5<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type> type;
437};
438
439template<class R, class A1, class A2, class A3, class A4, class A5, class A6> 318template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
440class callback6 319struct callback<R (A1, A2, A3, A4, A5, A6)>
441{ 320{
442 struct object { };
443
444 typedef R (object::*ptr_type)(A1, A2, A3, A4, A5, A6); 321 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
445 322
446 void *obj; 323private:
447 R (object::*meth)(A1, A2, A3, A4, A5, A6);
448 324
449 /* a proxy is a kind of recipe on how to call a specific class method */ 325 void *self;
450 struct proxy_base { 326 ptr_type func;
451 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const = 0; 327
328protected:
329
330 template<typename method>
331 struct thunktype;
332
333 template<class klass>
334 struct thunktype<R (klass::*)>
335 {
336 typedef klass K;
337 };
338
339 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6)>
340 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
341 {
342 klass *obj = static_cast<klass *>(self);
343 return (obj->*method) (a1, a2, a3, a4, a5, a6);
452 }; 344 }
453 template<class O1, class O2> 345
454 struct proxy : proxy_base { 346public:
455 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 347 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6)>
456 { 348 void set (K *object)
457 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6)>(meth))) 349 {
458 (a1, a2, a3, a4, a5, a6); 350 self = object;
459 } 351 func = thunk<K, method>;
460 }; 352 }
461 353
462 proxy_base *prxy;
463
464public:
465 template<class O1, class O2>
466 explicit callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6))
467 {
468 static proxy<O1,O2> p;
469 obj = reinterpret_cast<void *>(object);
470 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6)>(method);
471 prxy = &p;
472 }
473
474 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 354 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
475 { 355 {
476 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6); 356 return func (self, a1, a2, a3, a4, a5, a6);
477 } 357 }
478 358
479 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const 359 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
480 { 360 {
481 return call (a1, a2, a3, a4, a5, a6); 361 return call (a1, a2, a3, a4, a5, a6);
482 } 362 }
483}; 363};
484 364
485template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
486struct callback_funtype_trait6
487{
488 static const int arity = 6;
489 typedef R type (A1, A2, A3, A4, A5, A6);
490 typedef R result_type;
491 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type;
492};
493
494template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
495struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6)> : callback_funtype_trait6<R, A1, A2, A3, A4, A5, A6>
496{
497};
498
499template<class signature>
500struct callback_get_impl<6, signature>
501{
502 typedef callback_funtype_trait<signature> T;
503 typedef callback6<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type> type;
504};
505
506template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7> 365template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
507class callback7 366struct callback<R (A1, A2, A3, A4, A5, A6, A7)>
508{ 367{
509 struct object { };
510
511 typedef R (object::*ptr_type)(A1, A2, A3, A4, A5, A6, A7); 368 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
512 369
513 void *obj; 370private:
514 R (object::*meth)(A1, A2, A3, A4, A5, A6, A7);
515 371
516 /* a proxy is a kind of recipe on how to call a specific class method */ 372 void *self;
517 struct proxy_base { 373 ptr_type func;
518 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const = 0; 374
375protected:
376
377 template<typename method>
378 struct thunktype;
379
380 template<class klass>
381 struct thunktype<R (klass::*)>
382 {
383 typedef klass K;
384 };
385
386 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7)>
387 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
388 {
389 klass *obj = static_cast<klass *>(self);
390 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7);
519 }; 391 }
520 template<class O1, class O2> 392
521 struct proxy : proxy_base { 393public:
522 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 394 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7)>
523 { 395 void set (K *object)
524 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6, A7)>(meth))) 396 {
525 (a1, a2, a3, a4, a5, a6, a7); 397 self = object;
526 } 398 func = thunk<K, method>;
527 }; 399 }
528 400
529 proxy_base *prxy;
530
531public:
532 template<class O1, class O2>
533 explicit callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7))
534 {
535 static proxy<O1,O2> p;
536 obj = reinterpret_cast<void *>(object);
537 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6, A7)>(method);
538 prxy = &p;
539 }
540
541 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 401 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
542 { 402 {
543 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7); 403 return func (self, a1, a2, a3, a4, a5, a6, a7);
544 } 404 }
545 405
546 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const 406 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
547 { 407 {
548 return call (a1, a2, a3, a4, a5, a6, a7); 408 return call (a1, a2, a3, a4, a5, a6, a7);
549 } 409 }
550}; 410};
551 411
552template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
553struct callback_funtype_trait7
554{
555 static const int arity = 7;
556 typedef R type (A1, A2, A3, A4, A5, A6, A7);
557 typedef R result_type;
558 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type;
559};
560
561template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
562struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7)> : callback_funtype_trait7<R, A1, A2, A3, A4, A5, A6, A7>
563{
564};
565
566template<class signature>
567struct callback_get_impl<7, signature>
568{
569 typedef callback_funtype_trait<signature> T;
570 typedef callback7<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type> type;
571};
572
573template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> 412template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
574class callback8 413struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8)>
575{ 414{
576 struct object { };
577
578 typedef R (object::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8); 415 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8);
579 416
580 void *obj; 417private:
581 R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8);
582 418
583 /* a proxy is a kind of recipe on how to call a specific class method */ 419 void *self;
584 struct proxy_base { 420 ptr_type func;
585 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const = 0; 421
422protected:
423
424 template<typename method>
425 struct thunktype;
426
427 template<class klass>
428 struct thunktype<R (klass::*)>
429 {
430 typedef klass K;
431 };
432
433 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
434 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
435 {
436 klass *obj = static_cast<klass *>(self);
437 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8);
586 }; 438 }
587 template<class O1, class O2> 439
588 struct proxy : proxy_base { 440public:
589 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 441 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
590 { 442 void set (K *object)
591 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6, A7, A8)>(meth))) 443 {
592 (a1, a2, a3, a4, a5, a6, a7, a8); 444 self = object;
593 } 445 func = thunk<K, method>;
594 }; 446 }
595 447
596 proxy_base *prxy;
597
598public:
599 template<class O1, class O2>
600 explicit callback8 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8))
601 {
602 static proxy<O1,O2> p;
603 obj = reinterpret_cast<void *>(object);
604 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6, A7, A8)>(method);
605 prxy = &p;
606 }
607
608 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 448 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
609 { 449 {
610 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7, a8); 450 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
611 } 451 }
612 452
613 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const 453 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
614 { 454 {
615 return call (a1, a2, a3, a4, a5, a6, a7, a8); 455 return call (a1, a2, a3, a4, a5, a6, a7, a8);
616 } 456 }
617}; 457};
618 458
619template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
620struct callback_funtype_trait8
621{
622 static const int arity = 8;
623 typedef R type (A1, A2, A3, A4, A5, A6, A7, A8);
624 typedef R result_type;
625 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type; typedef A8 arg8_type;
626};
627
628template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
629struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7, A8)> : callback_funtype_trait8<R, A1, A2, A3, A4, A5, A6, A7, A8>
630{
631};
632
633template<class signature>
634struct callback_get_impl<8, signature>
635{
636 typedef callback_funtype_trait<signature> T;
637 typedef callback8<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type, typename T::arg8_type> type;
638};
639
640template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> 459template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
641class callback9 460struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
642{ 461{
643 struct object { };
644
645 typedef R (object::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8, A9); 462 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9);
646 463
647 void *obj; 464private:
648 R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
649 465
650 /* a proxy is a kind of recipe on how to call a specific class method */ 466 void *self;
651 struct proxy_base { 467 ptr_type func;
652 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8, A9), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const = 0; 468
469protected:
470
471 template<typename method>
472 struct thunktype;
473
474 template<class klass>
475 struct thunktype<R (klass::*)>
476 {
477 typedef klass K;
478 };
479
480 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
481 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
482 {
483 klass *obj = static_cast<klass *>(self);
484 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9);
653 }; 485 }
654 template<class O1, class O2> 486
655 struct proxy : proxy_base { 487public:
656 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8, A9), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 488 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
657 { 489 void set (K *object)
658 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>(meth))) 490 {
659 (a1, a2, a3, a4, a5, a6, a7, a8, a9); 491 self = object;
660 } 492 func = thunk<K, method>;
661 }; 493 }
662 494
663 proxy_base *prxy;
664
665public:
666 template<class O1, class O2>
667 explicit callback9 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9))
668 {
669 static proxy<O1,O2> p;
670 obj = reinterpret_cast<void *>(object);
671 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>(method);
672 prxy = &p;
673 }
674
675 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 495 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
676 { 496 {
677 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7, a8, a9); 497 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
678 } 498 }
679 499
680 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const 500 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
681 { 501 {
682 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9); 502 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
683 } 503 }
684}; 504};
685 505
686template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
687struct callback_funtype_trait9
688{
689 static const int arity = 9;
690 typedef R type (A1, A2, A3, A4, A5, A6, A7, A8, A9);
691 typedef R result_type;
692 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type; typedef A8 arg8_type; typedef A9 arg9_type;
693};
694
695template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
696struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)> : callback_funtype_trait9<R, A1, A2, A3, A4, A5, A6, A7, A8, A9>
697{
698};
699
700template<class signature>
701struct callback_get_impl<9, signature>
702{
703 typedef callback_funtype_trait<signature> T;
704 typedef callback9<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type, typename T::arg8_type, typename T::arg9_type> type;
705};
706
707template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> 506template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
708class callback10 507struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
709{ 508{
710 struct object { };
711
712 typedef R (object::*ptr_type)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); 509 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
713 510
714 void *obj; 511private:
715 R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
716 512
717 /* a proxy is a kind of recipe on how to call a specific class method */ 513 void *self;
718 struct proxy_base { 514 ptr_type func;
719 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const = 0; 515
516protected:
517
518 template<typename method>
519 struct thunktype;
520
521 template<class klass>
522 struct thunktype<R (klass::*)>
523 {
524 typedef klass K;
525 };
526
527 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
528 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10)
529 {
530 klass *obj = static_cast<klass *>(self);
531 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
720 }; 532 }
721 template<class O1, class O2> 533
722 struct proxy : proxy_base { 534public:
723 virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 535 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
724 { 536 void set (K *object)
725 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>(meth))) 537 {
726 (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 538 self = object;
727 } 539 func = thunk<K, method>;
728 }; 540 }
729 541
730 proxy_base *prxy;
731
732public:
733 template<class O1, class O2>
734 explicit callback10 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10))
735 {
736 static proxy<O1,O2> p;
737 obj = reinterpret_cast<void *>(object);
738 meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>(method);
739 prxy = &p;
740 }
741
742 R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 542 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
743 { 543 {
744 return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 544 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
745 } 545 }
746 546
747 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const 547 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
748 { 548 {
749 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); 549 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
750 } 550 }
751}; 551};
752 552
753template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
754struct callback_funtype_trait10
755{
756 static const int arity = 10;
757 typedef R type (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
758 typedef R result_type;
759 typedef A1 arg1_type; typedef A2 arg2_type; typedef A3 arg3_type; typedef A4 arg4_type; typedef A5 arg5_type; typedef A6 arg6_type; typedef A7 arg7_type; typedef A8 arg8_type; typedef A9 arg9_type; typedef A10 arg10_type;
760};
761
762template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
763struct callback_funtype_trait<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : callback_funtype_trait10<R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>
764{
765};
766
767template<class signature>
768struct callback_get_impl<10, signature>
769{
770 typedef callback_funtype_trait<signature> T;
771 typedef callback10<typename T::result_type, typename T::arg1_type, typename T::arg2_type, typename T::arg3_type, typename T::arg4_type, typename T::arg5_type, typename T::arg6_type, typename T::arg7_type, typename T::arg8_type, typename T::arg9_type, typename T::arg10_type> type;
772};
773
774
775template<class signature>
776struct callback : callback_get_impl<callback_funtype_trait<signature>::arity, signature>::type
777{
778 typedef typename callback_get_impl<callback_funtype_trait<signature>::arity, signature>::type base_type;
779
780 template<class O, class M>
781 explicit callback (O object, M method)
782 : base_type (object, method)
783 {
784 }
785};
786 553
787#endif 554#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines