ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.h
Revision: 1.8
Committed: Tue Dec 27 16:36:16 2005 UTC (18 years, 4 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.7: +8 -8 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.7 // 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.2
5 pcg 1.1 /*
6     callback.h -- C++ callback mechanism
7 pcg 1.7 Copyright (C) 2003-2005 Marc Lehmann <pcg@goof.com>
8 pcg 1.1
9 pcg 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 pcg 1.5 along with gvpe; if not, write to the Free Software
23 pcg 1.6 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 pcg 1.1 */
25    
26 pcg 1.4 #ifndef CALLBACK_H__
27     #define CALLBACK_H__
28 pcg 1.1
29 pcg 1.2 template<class R>
30     class callback0 {
31     struct object { };
32    
33     void *obj;
34     R (object::*meth)();
35    
36     /* a proxy is a kind of recipe on how to call a specific class method */
37     struct proxy_base {
38     virtual R call (void *obj, R (object::*meth)()) = 0;
39     };
40     template<class O1, class O2>
41     struct proxy : proxy_base {
42     virtual R call (void *obj, R (object::*meth)())
43     {
44 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)()>(meth)))
45 pcg 1.2 ();
46     }
47     };
48    
49     proxy_base *prxy;
50    
51     public:
52     template<class O1, class O2>
53     callback0 (O1 *object, R (O2::*method)())
54     {
55     static proxy<O1,O2> p;
56     obj = reinterpret_cast<void *>(object);
57     meth = reinterpret_cast<R (object::*)()>(method);
58     prxy = &p;
59     }
60    
61     R call() const
62     {
63     return prxy->call (obj, meth);
64     }
65    
66     R operator ()() const
67     {
68     return call ();
69     }
70     };
71    
72     template<class R, class A1>
73     class callback1 {
74 pcg 1.1 struct object { };
75    
76     void *obj;
77 pcg 1.2 R (object::*meth)(A1);
78 pcg 1.1
79 pcg 1.2 /* a proxy is a kind of recipe on how to call a specific class method */
80 pcg 1.1 struct proxy_base {
81 pcg 1.2 virtual R call (void *obj, R (object::*meth)(A1), A1 a1) = 0;
82 pcg 1.1 };
83     template<class O1, class O2>
84     struct proxy : proxy_base {
85 pcg 1.2 virtual R call (void *obj, R (object::*meth)(A1), A1 a1)
86 pcg 1.1 {
87 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1)>(meth)))
88 pcg 1.2 (a1);
89 pcg 1.1 }
90     };
91    
92     proxy_base *prxy;
93    
94     public:
95     template<class O1, class O2>
96 pcg 1.2 callback1 (O1 *object, R (O2::*method)(A1))
97 pcg 1.1 {
98     static proxy<O1,O2> p;
99     obj = reinterpret_cast<void *>(object);
100 pcg 1.2 meth = reinterpret_cast<R (object::*)(A1)>(method);
101 pcg 1.1 prxy = &p;
102     }
103    
104 pcg 1.2 R call(A1 a1) const
105 pcg 1.1 {
106 pcg 1.2 return prxy->call (obj, meth, a1);
107 pcg 1.1 }
108    
109 pcg 1.2 R operator ()(A1 a1) const
110 pcg 1.1 {
111 pcg 1.2 return call (a1);
112     }
113     };
114    
115     template<class R, class A1, class A2>
116     class callback2 {
117     struct object { };
118    
119     void *obj;
120     R (object::*meth)(A1, A2);
121    
122     /* a proxy is a kind of recipe on how to call a specific class method */
123     struct proxy_base {
124     virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2) = 0;
125     };
126     template<class O1, class O2>
127     struct proxy : proxy_base {
128     virtual R call (void *obj, R (object::*meth)(A1, A2), A1 a1, A2 a2)
129     {
130 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2)>(meth)))
131 pcg 1.2 (a1, a2);
132     }
133     };
134    
135     proxy_base *prxy;
136    
137     public:
138     template<class O1, class O2>
139     callback2 (O1 *object, R (O2::*method)(A1, A2))
140     {
141     static proxy<O1,O2> p;
142     obj = reinterpret_cast<void *>(object);
143     meth = reinterpret_cast<R (object::*)(A1, A2)>(method);
144     prxy = &p;
145     }
146    
147     R call(A1 a1, A2 a2) const
148     {
149     return prxy->call (obj, meth, a1, a2);
150     }
151    
152     R operator ()(A1 a1, A2 a2) const
153     {
154     return call (a1, a2);
155     }
156     };
157    
158     template<class R, class A1, class A2, class A3>
159     class callback3 {
160     struct object { };
161    
162     void *obj;
163     R (object::*meth)(A1, A2, A3);
164    
165     /* a proxy is a kind of recipe on how to call a specific class method */
166     struct proxy_base {
167     virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3) = 0;
168     };
169     template<class O1, class O2>
170     struct proxy : proxy_base {
171     virtual R call (void *obj, R (object::*meth)(A1, A2, A3), A1 a1, A2 a2, A3 a3)
172     {
173 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3)>(meth)))
174 pcg 1.2 (a1, a2, a3);
175     }
176     };
177    
178     proxy_base *prxy;
179    
180     public:
181     template<class O1, class O2>
182     callback3 (O1 *object, R (O2::*method)(A1, A2, A3))
183     {
184     static proxy<O1,O2> p;
185     obj = reinterpret_cast<void *>(object);
186     meth = reinterpret_cast<R (object::*)(A1, A2, A3)>(method);
187     prxy = &p;
188     }
189    
190     R call(A1 a1, A2 a2, A3 a3) const
191     {
192     return prxy->call (obj, meth, a1, a2, a3);
193     }
194    
195     R operator ()(A1 a1, A2 a2, A3 a3) const
196     {
197     return call (a1, a2, a3);
198     }
199     };
200    
201     template<class R, class A1, class A2, class A3, class A4>
202     class callback4 {
203     struct object { };
204    
205     void *obj;
206     R (object::*meth)(A1, A2, A3, A4);
207    
208     /* a proxy is a kind of recipe on how to call a specific class method */
209     struct proxy_base {
210     virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4) = 0;
211     };
212     template<class O1, class O2>
213     struct proxy : proxy_base {
214     virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4), A1 a1, A2 a2, A3 a3, A4 a4)
215     {
216 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4)>(meth)))
217 pcg 1.2 (a1, a2, a3, a4);
218     }
219     };
220    
221     proxy_base *prxy;
222    
223     public:
224     template<class O1, class O2>
225     callback4 (O1 *object, R (O2::*method)(A1, A2, A3, A4))
226     {
227     static proxy<O1,O2> p;
228     obj = reinterpret_cast<void *>(object);
229     meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4)>(method);
230     prxy = &p;
231     }
232    
233     R call(A1 a1, A2 a2, A3 a3, A4 a4) const
234     {
235     return prxy->call (obj, meth, a1, a2, a3, a4);
236     }
237    
238     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
239     {
240     return call (a1, a2, a3, a4);
241     }
242     };
243    
244     template<class R, class A1, class A2, class A3, class A4, class A5>
245     class callback5 {
246     struct object { };
247    
248     void *obj;
249     R (object::*meth)(A1, A2, A3, A4, A5);
250    
251     /* a proxy is a kind of recipe on how to call a specific class method */
252     struct proxy_base {
253     virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) = 0;
254     };
255     template<class O1, class O2>
256     struct proxy : proxy_base {
257     virtual R call (void *obj, R (object::*meth)(A1, A2, A3, A4, A5), A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
258     {
259 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5)>(meth)))
260 pcg 1.2 (a1, a2, a3, a4, a5);
261     }
262     };
263    
264     proxy_base *prxy;
265    
266     public:
267     template<class O1, class O2>
268     callback5 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5))
269     {
270     static proxy<O1,O2> p;
271     obj = reinterpret_cast<void *>(object);
272     meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5)>(method);
273     prxy = &p;
274     }
275    
276     R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
277     {
278     return prxy->call (obj, meth, a1, a2, a3, a4, a5);
279     }
280    
281     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
282     {
283     return call (a1, a2, a3, a4, a5);
284     }
285     };
286    
287     template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
288     class callback6 {
289     struct object { };
290    
291     void *obj;
292     R (object::*meth)(A1, A2, A3, A4, A5, A6);
293    
294     /* a proxy is a kind of recipe on how to call a specific class method */
295     struct proxy_base {
296     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) = 0;
297     };
298     template<class O1, class O2>
299     struct proxy : proxy_base {
300     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)
301     {
302 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6)>(meth)))
303 pcg 1.2 (a1, a2, a3, a4, a5, a6);
304     }
305     };
306    
307     proxy_base *prxy;
308    
309     public:
310     template<class O1, class O2>
311     callback6 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6))
312     {
313     static proxy<O1,O2> p;
314     obj = reinterpret_cast<void *>(object);
315     meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6)>(method);
316     prxy = &p;
317     }
318    
319     R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
320     {
321     return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6);
322     }
323    
324     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
325     {
326     return call (a1, a2, a3, a4, a5, a6);
327     }
328     };
329    
330     template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
331     class callback7 {
332     struct object { };
333    
334     void *obj;
335     R (object::*meth)(A1, A2, A3, A4, A5, A6, A7);
336    
337     /* a proxy is a kind of recipe on how to call a specific class method */
338     struct proxy_base {
339     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) = 0;
340     };
341     template<class O1, class O2>
342     struct proxy : proxy_base {
343     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)
344     {
345 pcg 1.8 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A1, A2, A3, A4, A5, A6, A7)>(meth)))
346 pcg 1.2 (a1, a2, a3, a4, a5, a6, a7);
347     }
348     };
349    
350     proxy_base *prxy;
351    
352     public:
353     template<class O1, class O2>
354     callback7 (O1 *object, R (O2::*method)(A1, A2, A3, A4, A5, A6, A7))
355     {
356     static proxy<O1,O2> p;
357     obj = reinterpret_cast<void *>(object);
358     meth = reinterpret_cast<R (object::*)(A1, A2, A3, A4, A5, A6, A7)>(method);
359     prxy = &p;
360     }
361    
362     R call(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
363     {
364     return prxy->call (obj, meth, a1, a2, a3, a4, a5, a6, a7);
365     }
366    
367     R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
368     {
369     return call (a1, a2, a3, a4, a5, a6, a7);
370 pcg 1.1 }
371     };
372    
373     #endif