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.4 by pcg, Sat Jan 17 01:18:36 2004 UTC vs.
Revision 1.16 by root, Sun Nov 18 00:02:56 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines