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

# User Rev Content
1 root 1.5 // 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 pcg 1.1
5     /*
6     callback.h -- C++ callback mechanism
7 root 1.9 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com>
8 pcg 1.1
9 root 1.5 This file is part of GVPE.
10    
11     GVPE is free software; you can redistribute it and/or modify
12 pcg 1.1 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 root 1.5 along with gvpe; if not, write to the Free Software
23 root 1.4 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 pcg 1.1 */
25    
26 pcg 1.2 #ifndef CALLBACK_H__
27     #define CALLBACK_H__
28 pcg 1.1
29 root 1.9 #define CALLBACK_H_VERSION 3
30 root 1.8
31 root 1.10 template<typename signature>
32     struct callback;
33 root 1.8
34 root 1.10 #define callback_set(callback,obj,klass,method) callback.set<klass, &klass::method> (obj)
35 root 1.8
36 pcg 1.1 template<class R>
37 root 1.10 struct callback<R ()>
38 root 1.8 {
39 root 1.10 typedef R (*ptr_type)(void *self);
40 pcg 1.1
41 root 1.10 private:
42 root 1.8
43 root 1.10 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 pcg 1.1
64     public:
65 root 1.10 template<class K, R (K::*method)()>
66     void set (K *object)
67 root 1.9 {
68 root 1.10 self = object;
69     func = thunk<K, method>;
70 root 1.9 }
71    
72 root 1.10 R call () const
73 root 1.9 {
74 root 1.10 return func (self);
75 root 1.9 }
76 pcg 1.1
77 root 1.5 R operator ()() const
78 root 1.9 {
79     return call ();
80     }
81 pcg 1.1 };
82    
83 root 1.10 template<class R, class A1>
84     struct callback<R (A1)>
85 root 1.8 {
86 root 1.10 typedef R (*ptr_type)(void *self, A1);
87    
88     private:
89    
90     void *self;
91     ptr_type func;
92 root 1.8
93 root 1.10 protected:
94 root 1.8
95 root 1.10 template<typename method>
96     struct thunktype;
97 pcg 1.1
98 root 1.10 template<class klass>
99     struct thunktype<R (klass::*)>
100     {
101     typedef klass K;
102     };
103 pcg 1.1
104 root 1.10 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 pcg 1.1
111     public:
112 root 1.10 template<class K, R (K::*method)(A1)>
113     void set (K *object)
114 root 1.9 {
115 root 1.10 self = object;
116     func = thunk<K, method>;
117 root 1.9 }
118    
119 root 1.10 R call (A1 a1) const
120 root 1.9 {
121 root 1.10 return func (self, a1);
122 root 1.9 }
123 pcg 1.1
124 root 1.5 R operator ()(A1 a1) const
125 root 1.9 {
126     return call (a1);
127     }
128 pcg 1.1 };
129    
130 root 1.10 template<class R, class A1, class A2>
131     struct callback<R (A1, A2)>
132 root 1.8 {
133 root 1.10 typedef R (*ptr_type)(void *self, A1, A2);
134    
135     private:
136    
137     void *self;
138     ptr_type func;
139 root 1.8
140 root 1.10 protected:
141 root 1.8
142 root 1.10 template<typename method>
143     struct thunktype;
144 root 1.8
145 root 1.10 template<class klass>
146     struct thunktype<R (klass::*)>
147     {
148     typedef klass K;
149     };
150 pcg 1.1
151 root 1.10 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 pcg 1.1
158     public:
159 root 1.10 template<class K, R (K::*method)(A1, A2)>
160     void set (K *object)
161 root 1.9 {
162 root 1.10 self = object;
163     func = thunk<K, method>;
164 root 1.9 }
165    
166 root 1.10 R call (A1 a1, A2 a2) const
167 root 1.9 {
168 root 1.10 return func (self, a1, a2);
169 root 1.9 }
170 pcg 1.1
171 root 1.5 R operator ()(A1 a1, A2 a2) const
172 root 1.9 {
173     return call (a1, a2);
174     }
175 pcg 1.1 };
176    
177 root 1.10 template<class R, class A1, class A2, class A3>
178     struct callback<R (A1, A2, A3)>
179 root 1.8 {
180 root 1.10 typedef R (*ptr_type)(void *self, A1, A2, A3);
181    
182     private:
183    
184     void *self;
185     ptr_type func;
186 root 1.8
187 root 1.10 protected:
188 root 1.8
189 root 1.10 template<typename method>
190     struct thunktype;
191 pcg 1.1
192 root 1.10 template<class klass>
193     struct thunktype<R (klass::*)>
194     {
195     typedef klass K;
196     };
197 root 1.8
198 root 1.10 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 pcg 1.1
205     public:
206 root 1.10 template<class K, R (K::*method)(A1, A2, A3)>
207     void set (K *object)
208 root 1.9 {
209 root 1.10 self = object;
210     func = thunk<K, method>;
211 root 1.9 }
212    
213 root 1.10 R call (A1 a1, A2 a2, A3 a3) const
214 root 1.9 {
215 root 1.10 return func (self, a1, a2, a3);
216 root 1.9 }
217 pcg 1.1
218 root 1.5 R operator ()(A1 a1, A2 a2, A3 a3) const
219 root 1.9 {
220     return call (a1, a2, a3);
221     }
222 pcg 1.1 };
223    
224 root 1.10 template<class R, class A1, class A2, class A3, class A4>
225     struct callback<R (A1, A2, A3, A4)>
226 root 1.8 {
227 root 1.10 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
228    
229     private:
230 root 1.8
231 root 1.10 void *self;
232     ptr_type func;
233 root 1.8
234 root 1.10 protected:
235 root 1.8
236 root 1.10 template<typename method>
237     struct thunktype;
238 pcg 1.1
239 root 1.10 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 pcg 1.1
252     public:
253 root 1.10 template<class K, R (K::*method)(A1, A2, A3, A4)>
254     void set (K *object)
255 root 1.9 {
256 root 1.10 self = object;
257     func = thunk<K, method>;
258 root 1.9 }
259    
260 root 1.10 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
261 root 1.9 {
262 root 1.10 return func (self, a1, a2, a3, a4);
263 root 1.9 }
264 pcg 1.1
265 root 1.5 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
266 root 1.9 {
267     return call (a1, a2, a3, a4);
268     }
269 pcg 1.1 };
270    
271 root 1.10 template<class R, class A1, class A2, class A3, class A4, class A5>
272     struct callback<R (A1, A2, A3, A4, A5)>
273 root 1.8 {
274 root 1.10 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
275    
276     private:
277    
278     void *self;
279     ptr_type func;
280 root 1.8
281 root 1.10 protected:
282 root 1.8
283 root 1.10 template<typename method>
284     struct thunktype;
285 pcg 1.1
286 root 1.10 template<class klass>
287     struct thunktype<R (klass::*)>
288     {
289     typedef klass K;
290     };
291 pcg 1.1
292 root 1.10 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 pcg 1.1
299     public:
300 root 1.10 template<class K, R (K::*method)(A1, A2, A3, A4, A5)>
301     void set (K *object)
302 root 1.9 {
303 root 1.10 self = object;
304     func = thunk<K, method>;
305 root 1.9 }
306    
307 root 1.10 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
308 root 1.9 {
309 root 1.10 return func (self, a1, a2, a3, a4, a5);
310 root 1.9 }
311 pcg 1.1
312 root 1.5 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
313 root 1.9 {
314     return call (a1, a2, a3, a4, a5);
315     }
316 pcg 1.1 };
317    
318 root 1.10 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 root 1.8 {
321 root 1.10 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
322    
323     private:
324    
325     void *self;
326     ptr_type func;
327 root 1.8
328 root 1.10 protected:
329 root 1.8
330 root 1.10 template<typename method>
331     struct thunktype;
332 root 1.8
333 root 1.10 template<class klass>
334     struct thunktype<R (klass::*)>
335     {
336     typedef klass K;
337     };
338 pcg 1.1
339 root 1.10 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 pcg 1.1
346     public:
347 root 1.10 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6)>
348     void set (K *object)
349 root 1.9 {
350 root 1.10 self = object;
351     func = thunk<K, method>;
352 root 1.9 }
353    
354 root 1.10 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
355 root 1.9 {
356 root 1.10 return func (self, a1, a2, a3, a4, a5, a6);
357 root 1.9 }
358 pcg 1.1
359 root 1.5 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
360 root 1.9 {
361     return call (a1, a2, a3, a4, a5, a6);
362     }
363 pcg 1.1 };
364    
365 root 1.10 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 root 1.8 {
368 root 1.10 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
369    
370     private:
371 root 1.8
372 root 1.10 void *self;
373     ptr_type func;
374 root 1.8
375 root 1.10 protected:
376 pcg 1.1
377 root 1.10 template<typename method>
378     struct thunktype;
379 root 1.8
380 root 1.10 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 pcg 1.1
393     public:
394 root 1.10 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7)>
395     void set (K *object)
396 root 1.9 {
397 root 1.10 self = object;
398     func = thunk<K, method>;
399 root 1.9 }
400    
401 root 1.10 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
402 root 1.9 {
403 root 1.10 return func (self, a1, a2, a3, a4, a5, a6, a7);
404 root 1.9 }
405 pcg 1.1
406 root 1.5 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
407 root 1.9 {
408     return call (a1, a2, a3, a4, a5, a6, a7);
409     }
410 pcg 1.1 };
411    
412 root 1.10 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 root 1.8 {
415 root 1.10 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 root 1.8
422 root 1.10 protected:
423 root 1.8
424 root 1.10 template<typename method>
425     struct thunktype;
426 root 1.8
427 root 1.10 template<class klass>
428     struct thunktype<R (klass::*)>
429     {
430     typedef klass K;
431     };
432 root 1.8
433 root 1.10 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 root 1.8
440     public:
441 root 1.10 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
442     void set (K *object)
443 root 1.9 {
444 root 1.10 self = object;
445     func = thunk<K, method>;
446 root 1.9 }
447    
448 root 1.10 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
449 root 1.9 {
450 root 1.10 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
451 root 1.9 }
452 root 1.8
453     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
454 root 1.9 {
455     return call (a1, a2, a3, a4, a5, a6, a7, a8);
456     }
457 root 1.8 };
458    
459 root 1.10 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 root 1.8 {
462 root 1.10 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 root 1.8
469 root 1.10 protected:
470 root 1.8
471 root 1.10 template<typename method>
472     struct thunktype;
473 root 1.8
474 root 1.10 template<class klass>
475     struct thunktype<R (klass::*)>
476     {
477     typedef klass K;
478     };
479 root 1.8
480 root 1.10 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 root 1.8
487     public:
488 root 1.10 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
489     void set (K *object)
490 root 1.9 {
491 root 1.10 self = object;
492     func = thunk<K, method>;
493 root 1.9 }
494    
495 root 1.10 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
496 root 1.9 {
497 root 1.10 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
498 root 1.9 }
499 root 1.8
500     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
501 root 1.9 {
502     return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
503     }
504 root 1.8 };
505    
506 root 1.10 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 root 1.8 {
509 root 1.10 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 root 1.8
516 root 1.10 protected:
517 root 1.8
518 root 1.10 template<typename method>
519     struct thunktype;
520 root 1.8
521 root 1.10 template<class klass>
522     struct thunktype<R (klass::*)>
523     {
524     typedef klass K;
525     };
526 root 1.8
527 root 1.10 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 root 1.8
534     public:
535 root 1.10 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
536     void set (K *object)
537 root 1.9 {
538 root 1.10 self = object;
539     func = thunk<K, method>;
540 root 1.9 }
541    
542 root 1.10 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
543 root 1.9 {
544 root 1.10 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
545 root 1.9 }
546 root 1.8
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 root 1.9 {
549     return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
550     }
551 root 1.8 };
552    
553    
554 pcg 1.1 #endif