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.1 by pcg, Wed Apr 2 03:06:22 2003 UTC vs.
Revision 1.14 by pcg, Wed Dec 5 18:19:50 2007 UTC

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
1/* 5/*
2 callback.h -- C++ callback mechanism 6 callback.h -- C++ callback mechanism
7 Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com>
3 8
9 This file is part of GVPE.
10
4 This program is free software; you can redistribute it and/or modify 11 GVPE is free software; you can redistribute it and/or modify
5 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
6 the Free Software Foundation; either version 2 of the License, or 13 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version. 14 (at your option) any later version.
8 15
9 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 19 GNU General Public License for more details.
13 20
14 You should have received a copy of the GNU General Public License 21 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software 22 along with gvpe; if not, write to the Free Software
16 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/ 24*/
18 25
19#ifndef VPE_CALLBACK_H__ 26#ifndef CALLBACK_H__
20#define VPE_CALLBACK_H__ 27#define CALLBACK_H__
21 28
29#define CALLBACK_H_VERSION 3
30
31template<typename signature>
32struct callback;
33
34template<class R>
35struct callback<R ()>
36{
37 typedef R (*ptr_type)(void *self);
38
39 template<class K, R (K::*method)()>
40 void set (K *object)
41 {
42 self = object;
43 func = thunk<K, method>;
44 }
45
46 R call () const
47 {
48 return func (self);
49 }
50
51 R operator ()() const
52 {
53 return call ();
54 }
55
56private:
57
58 void *self;
59 ptr_type func;
60
61 template<class klass, R (klass::*method)()>
62 static R thunk (void *self)
63 {
64 klass *obj = static_cast<klass *>(self);
65 return (obj->*method) ();
66 }
67};
68
22template<class R, class A> 69template<class R, class A1>
23class callback { 70struct callback<R (A1)>
24 struct object { }; 71{
72 typedef R (*ptr_type)(void *self, A1);
25 73
26 void *obj; 74 template<class K, R (K::*method)(A1)>
27 R (object::*meth)(A arg); 75 void set (K *object)
28 76 {
29 // a proxy is a kind of recipe on how to call a specific class method 77 self = object;
30 struct proxy_base { 78 func = thunk<K, method>;
31 virtual R call (void *obj, R (object::*meth)(A), A arg) = 0;
32 }; 79 }
33 template<class O1, class O2>
34 struct proxy : proxy_base {
35 virtual R call (void *obj, R (object::*meth)(A), A arg)
36 {
37 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)(A)>(meth)))
38 (arg);
39 }
40 };
41 80
42 proxy_base *prxy;
43
44public:
45 template<class O1, class O2>
46 callback (O1 *object, R (O2::*method)(A))
47 {
48 static proxy<O1,O2> p;
49 obj = reinterpret_cast<void *>(object);
50 meth = reinterpret_cast<R (object::*)(A)>(method);
51 prxy = &p;
52 }
53
54 R call(A arg) const 81 R call (A1 a1) const
55 { 82 {
56 return prxy->call (obj, meth, arg); 83 return func (self, a1);
57 } 84 }
58 85
59 R operator ()(A arg) const 86 R operator ()(A1 a1) const
60 { 87 {
61 return call (arg); 88 return call (a1);
62 } 89 }
90
91private:
92
93 void *self;
94 ptr_type func;
95
96 template<class klass, R (klass::*method)(A1)>
97 static R thunk (void *self, A1 a1)
98 {
99 klass *obj = static_cast<klass *>(self);
100 return (obj->*method) (a1);
101 }
63}; 102};
103
104template<class R, class A1, class A2>
105struct callback<R (A1, A2)>
106{
107 typedef R (*ptr_type)(void *self, A1, A2);
108
109 template<class K, R (K::*method)(A1, A2)>
110 void set (K *object)
111 {
112 self = object;
113 func = thunk<K, method>;
114 }
115
116 R call (A1 a1, A2 a2) const
117 {
118 return func (self, a1, a2);
119 }
120
121 R operator ()(A1 a1, A2 a2) const
122 {
123 return call (a1, a2);
124 }
125
126private:
127
128 void *self;
129 ptr_type func;
130
131 template<class klass, R (klass::*method)(A1, A2)>
132 static R thunk (void *self, A1 a1, A2 a2)
133 {
134 klass *obj = static_cast<klass *>(self);
135 return (obj->*method) (a1, a2);
136 }
137};
138
139template<class R, class A1, class A2, class A3>
140struct callback<R (A1, A2, A3)>
141{
142 typedef R (*ptr_type)(void *self, A1, A2, A3);
143
144 template<class K, R (K::*method)(A1, A2, A3)>
145 void set (K *object)
146 {
147 self = object;
148 func = thunk<K, method>;
149 }
150
151 R call (A1 a1, A2 a2, A3 a3) const
152 {
153 return func (self, a1, a2, a3);
154 }
155
156 R operator ()(A1 a1, A2 a2, A3 a3) const
157 {
158 return call (a1, a2, a3);
159 }
160
161private:
162
163 void *self;
164 ptr_type func;
165
166 template<class klass, R (klass::*method)(A1, A2, A3)>
167 static R thunk (void *self, A1 a1, A2 a2, A3 a3)
168 {
169 klass *obj = static_cast<klass *>(self);
170 return (obj->*method) (a1, a2, a3);
171 }
172};
173
174template<class R, class A1, class A2, class A3, class A4>
175struct callback<R (A1, A2, A3, A4)>
176{
177 typedef R (*ptr_type)(void *self, A1, A2, A3, A4);
178
179 template<class K, R (K::*method)(A1, A2, A3, A4)>
180 void set (K *object)
181 {
182 self = object;
183 func = thunk<K, method>;
184 }
185
186 R call (A1 a1, A2 a2, A3 a3, A4 a4) const
187 {
188 return func (self, a1, a2, a3, a4);
189 }
190
191 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) const
192 {
193 return call (a1, a2, a3, a4);
194 }
195
196private:
197
198 void *self;
199 ptr_type func;
200
201 template<class klass, R (klass::*method)(A1, A2, A3, A4)>
202 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4)
203 {
204 klass *obj = static_cast<klass *>(self);
205 return (obj->*method) (a1, a2, a3, a4);
206 }
207};
208
209template<class R, class A1, class A2, class A3, class A4, class A5>
210struct callback<R (A1, A2, A3, A4, A5)>
211{
212 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5);
213
214 template<class K, R (K::*method)(A1, A2, A3, A4, A5)>
215 void set (K *object)
216 {
217 self = object;
218 func = thunk<K, method>;
219 }
220
221 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
222 {
223 return func (self, a1, a2, a3, a4, a5);
224 }
225
226 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) const
227 {
228 return call (a1, a2, a3, a4, a5);
229 }
230
231private:
232
233 void *self;
234 ptr_type func;
235
236 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5)>
237 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
238 {
239 klass *obj = static_cast<klass *>(self);
240 return (obj->*method) (a1, a2, a3, a4, a5);
241 }
242};
243
244template<class R, class A1, class A2, class A3, class A4, class A5, class A6>
245struct callback<R (A1, A2, A3, A4, A5, A6)>
246{
247 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6);
248
249 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6)>
250 void set (K *object)
251 {
252 self = object;
253 func = thunk<K, method>;
254 }
255
256 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
257 {
258 return func (self, a1, a2, a3, a4, a5, a6);
259 }
260
261 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) const
262 {
263 return call (a1, a2, a3, a4, a5, a6);
264 }
265
266private:
267
268 void *self;
269 ptr_type func;
270
271 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6)>
272 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
273 {
274 klass *obj = static_cast<klass *>(self);
275 return (obj->*method) (a1, a2, a3, a4, a5, a6);
276 }
277};
278
279template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
280struct callback<R (A1, A2, A3, A4, A5, A6, A7)>
281{
282 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7);
283
284 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7)>
285 void set (K *object)
286 {
287 self = object;
288 func = thunk<K, method>;
289 }
290
291 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
292 {
293 return func (self, a1, a2, a3, a4, a5, a6, a7);
294 }
295
296 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) const
297 {
298 return call (a1, a2, a3, a4, a5, a6, a7);
299 }
300
301private:
302
303 void *self;
304 ptr_type func;
305
306 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7)>
307 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
308 {
309 klass *obj = static_cast<klass *>(self);
310 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7);
311 }
312};
313
314template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
315struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8)>
316{
317 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8);
318
319 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
320 void set (K *object)
321 {
322 self = object;
323 func = thunk<K, method>;
324 }
325
326 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
327 {
328 return func (self, a1, a2, a3, a4, a5, a6, a7, a8);
329 }
330
331 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) const
332 {
333 return call (a1, a2, a3, a4, a5, a6, a7, a8);
334 }
335
336private:
337
338 void *self;
339 ptr_type func;
340
341 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8)>
342 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
343 {
344 klass *obj = static_cast<klass *>(self);
345 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8);
346 }
347};
348
349template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
350struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9)>
351{
352 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9);
353
354 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
355 void set (K *object)
356 {
357 self = object;
358 func = thunk<K, method>;
359 }
360
361 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
362 {
363 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9);
364 }
365
366 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) const
367 {
368 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9);
369 }
370
371private:
372
373 void *self;
374 ptr_type func;
375
376 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)>
377 static R thunk (void *self, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
378 {
379 klass *obj = static_cast<klass *>(self);
380 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9);
381 }
382};
383
384template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
385struct callback<R (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
386{
387 typedef R (*ptr_type)(void *self, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
388
389 template<class K, R (K::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
390 void set (K *object)
391 {
392 self = object;
393 func = thunk<K, method>;
394 }
395
396 R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
397 {
398 return func (self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
399 }
400
401 R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) const
402 {
403 return call (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
404 }
405
406private:
407
408 void *self;
409 ptr_type func;
410
411 template<class klass, R (klass::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>
412 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)
413 {
414 klass *obj = static_cast<klass *>(self);
415 return (obj->*method) (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
416 }
417};
418
64 419
65#endif 420#endif
66

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines