ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/callback.h
Revision: 1.10
Committed: Tue Dec 4 14:50:40 2007 UTC (16 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.9: +312 -402 lines
Log Message:
experimental new callbacks, totally standards compliant, faster, smaller

File Contents

# Content
1 // THIS IS A GENERATED FILE: RUN callback.pl to regenerate it
2 // THIS IS A GENERATED FILE: callback.pl is part of the GVPE
3 // THIS IS A GENERATED FILE: distribution.
4
5 /*
6 callback.h -- C++ callback mechanism
7 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com>
8
9 This file is part of GVPE.
10
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
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with gvpe; if not, write to the Free Software
23 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #ifndef CALLBACK_H__
27 #define CALLBACK_H__
28
29 #define CALLBACK_H_VERSION 3
30
31 template<typename signature>
32 struct callback;
33
34 #define callback_set(callback,obj,klass,method) callback.set<klass, &klass::method> (obj)
35
36 template<class R>
37 struct callback<R ()>
38 {
39 typedef R (*ptr_type)(void *self);
40
41 private:
42
43 void *self;
44 ptr_type func;
45
46 protected:
47
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) ();
62 }
63
64 public:
65 template<class K, R (K::*method)()>
66 void set (K *object)
67 {
68 self = object;
69 func = thunk<K, method>;
70 }
71
72 R call () const
73 {
74 return func (self);
75 }
76
77 R operator ()() const
78 {
79 return call ();
80 }
81 };
82
83 template<class R, class A1>
84 struct callback<R (A1)>
85 {
86 typedef R (*ptr_type)(void *self, A1);
87
88 private:
89
90 void *self;
91 ptr_type func;
92
93 protected:
94
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);
109 }
110
111 public:
112 template<class K, R (K::*method)(A1)>
113 void set (K *object)
114 {
115 self = object;
116 func = thunk<K, method>;
117 }
118
119 R call (A1 a1) const
120 {
121 return func (self, a1);
122 }
123
124 R operator ()(A1 a1) const
125 {
126 return call (a1);
127 }
128 };
129
130 template<class R, class A1, class A2>
131 struct callback<R (A1, A2)>
132 {
133 typedef R (*ptr_type)(void *self, A1, A2);
134
135 private:
136
137 void *self;
138 ptr_type func;
139
140 protected:
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);
156 }
157
158 public:
159 template<class K, R (K::*method)(A1, A2)>
160 void set (K *object)
161 {
162 self = object;
163 func = thunk<K, method>;
164 }
165
166 R call (A1 a1, A2 a2) const
167 {
168 return func (self, a1, a2);
169 }
170
171 R operator ()(A1 a1, A2 a2) const
172 {
173 return call (a1, a2);
174 }
175 };
176
177 template<class R, class A1, class A2, class A3>
178 struct callback<R (A1, A2, A3)>
179 {
180 typedef R (*ptr_type)(void *self, A1, A2, A3);
181
182 private:
183
184 void *self;
185 ptr_type func;
186
187 protected:
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);
203 }
204
205 public:
206 template<class K, R (K::*method)(A1, A2, A3)>
207 void set (K *object)
208 {
209 self = object;
210 func = thunk<K, method>;
211 }
212
213 R call (A1 a1, A2 a2, A3 a3) const
214 {
215 return func (self, a1, a2, a3);
216 }
217
218 R operator ()(A1 a1, A2 a2, A3 a3) const
219 {
220 return call (a1, a2, a3);
221 }
222 };
223
224 template<class R, class A1, class A2, class A3, class A4>
225 struct callback<R (A1, A2, A3, A4)>
226 {
227 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
228
229 private:
230
231 void *self;
232 ptr_type func;
233
234 protected:
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);
250 }
251
252 public:
253 template<class K, R (K::*method)(A1, A2, A3, A4)>
254 void set (K *object)
255 {
256 self = object;
257 func = thunk<K, method>;
258 }
259
260 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
261 {
262 return func (self, a1, a2, a3, a4);
263 }
264
265 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
266 {
267 return call (a1, a2, a3, a4);
268 }
269 };
270
271 template<class R, class A1, class A2, class A3, class A4, class A5>
272 struct callback<R (A1, A2, A3, A4, A5)>
273 {
274 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
275
276 private:
277
278 void *self;
279 ptr_type func;
280
281 protected:
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);
297 }
298
299 public:
300 template<class K, R (K::*method)(A1, A2, A3, A4, A5)>
301 void set (K *object)
302 {
303 self = object;
304 func = thunk<K, method>;
305 }
306
307 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
308 {
309 return func (self, a1, a2, a3, a4, a5);
310 }
311
312 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
313 {
314 return call (a1, a2, a3, a4, a5);
315 }
316 };
317
318 template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
319 struct callback<R (A1, A2, A3, A4, A5, A6)>
320 {
321 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
322
323 private:
324
325 void *self;
326 ptr_type func;
327
328 protected:
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);
344 }
345
346 public:
347 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6)>
348 void set (K *object)
349 {
350 self = object;
351 func = thunk<K, method>;
352 }
353
354 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
355 {
356 return func (self, a1, a2, a3, a4, a5, a6);
357 }
358
359 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
360 {
361 return call (a1, a2, a3, a4, a5, a6);
362 }
363 };
364
365 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
366 struct callback<R (A1, A2, A3, A4, A5, A6, A7)>
367 {
368 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
369
370 private:
371
372 void *self;
373 ptr_type func;
374
375 protected:
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);
391 }
392
393 public:
394 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7)>
395 void set (K *object)
396 {
397 self = object;
398 func = thunk<K, method>;
399 }
400
401 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
402 {
403 return func (self, a1, a2, a3, a4, a5, a6, a7);
404 }
405
406 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
407 {
408 return call (a1, a2, a3, a4, a5, a6, a7);
409 }
410 };
411
412 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
413 struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8)>
414 {
415 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8);
416
417 private:
418
419 void *self;
420 ptr_type func;
421
422 protected:
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);
438 }
439
440 public:
441 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
442 void set (K *object)
443 {
444 self = object;
445 func = thunk<K, method>;
446 }
447
448 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
449 {
450 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
451 }
452
453 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
454 {
455 return call (a1, a2, a3, a4, a5, a6, a7, a8);
456 }
457 };
458
459 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
460 struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
461 {
462 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9);
463
464 private:
465
466 void *self;
467 ptr_type func;
468
469 protected:
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);
485 }
486
487 public:
488 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
489 void set (K *object)
490 {
491 self = object;
492 func = thunk<K, method>;
493 }
494
495 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
496 {
497 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
498 }
499
500 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
501 {
502 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
503 }
504 };
505
506 template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
507 struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
508 {
509 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
510
511 private:
512
513 void *self;
514 ptr_type func;
515
516 protected:
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);
532 }
533
534 public:
535 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
536 void set (K *object)
537 {
538 self = object;
539 func = thunk<K, method>;
540 }
541
542 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
543 {
544 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
545 }
546
547 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
548 {
549 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
550 }
551 };
552
553
554 #endif