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 | /* |
1 | /* |
6 | callback.h -- C++ callback mechanism |
2 | * callback.h -- C++ callback mechanism |
7 | Copyright (C) 2003-2007 Marc Lehmann <pcg@goof.com> |
3 | * Copyright (C) 2003-2018 Marc Lehmann <pcg@goof.com> |
8 | |
4 | * |
9 | This file is part of GVPE. |
5 | * This file is part of GVPE. |
10 | |
6 | * |
11 | GVPE is free software; you can redistribute it and/or modify |
7 | * This program is free software; you can redistribute it and/or modify it |
12 | 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 |
13 | the Free Software Foundation; either version 2 of the License, or |
9 | * Free Software Foundation; either version 3 of the License, or (at your |
14 | (at your option) any later version. |
10 | * option) any later version. |
15 | |
11 | * |
16 | 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 |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
19 | GNU General Public License for more details. |
15 | * Public License for more details. |
20 | |
16 | * |
21 | 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 |
22 | along with gvpe; if not, write to the Free Software |
18 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
23 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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. |
24 | */ |
30 | */ |
25 | |
31 | |
26 | #ifndef CALLBACK_H__ |
32 | #ifndef CALLBACK_H__ |
27 | #define CALLBACK_H__ |
33 | #define CALLBACK_H__ |
28 | |
34 | |
29 | #define CALLBACK_H_VERSION 3 |
35 | #define CALLBACK_H_VERSION 4 |
30 | |
36 | |
31 | template<typename signature> |
37 | template<typename signature> |
32 | struct callback; |
38 | struct callback; |
33 | |
39 | |
34 | template<class R> |
40 | template<class R, class ...Args> |
35 | struct callback<R ()> |
41 | struct callback<R (Args...)> |
36 | { |
42 | { |
37 | typedef R (*ptr_type)(void *self); |
43 | typedef R (*ptr_type)(void *self, Args...); |
38 | |
44 | |
39 | template<class K, R (K::*method)()> |
45 | template<class K, R (K::*method)(Args...)> |
40 | void set (K *object) |
46 | void set (K *object) |
41 | { |
47 | { |
42 | self = object; |
48 | self = object; |
43 | func = thunk<K, method>; |
49 | func = thunk<K, method>; |
44 | } |
50 | } |
45 | |
51 | |
46 | R call () const |
52 | R call (Args... args) const |
47 | { |
53 | { |
48 | return func (self); |
54 | return func (self, args...); |
49 | } |
55 | } |
50 | |
56 | |
51 | R operator ()() const |
57 | R operator ()(Args... args) const |
52 | { |
58 | { |
53 | return call (); |
59 | return call (args...); |
54 | } |
60 | } |
55 | |
61 | |
56 | private: |
62 | private: |
57 | |
63 | |
58 | void *self; |
64 | void *self; |
59 | ptr_type func; |
65 | ptr_type func; |
60 | |
66 | |
61 | template<class klass, R (klass::*method)()> |
67 | template<class klass, R (klass::*method)(Args...)> |
62 | static R thunk (void *self) |
68 | static R thunk (void *self, Args... args) |
63 | { |
69 | { |
64 | klass *obj = static_cast<klass *>(self); |
70 | klass *obj = static_cast<klass *>(self); |
65 | return (obj->*method) (); |
71 | return (obj->*method) (args...); |
66 | } |
72 | } |
67 | }; |
73 | }; |
68 | |
74 | |
69 | template<class R, class A1> |
|
|
70 | struct callback<R (A1)> |
|
|
71 | { |
|
|
72 | typedef R (*ptr_type)(void *self, A1); |
|
|
73 | |
|
|
74 | template<class K, R (K::*method)(A1)> |
|
|
75 | void set (K *object) |
|
|
76 | { |
|
|
77 | self = object; |
|
|
78 | func = thunk<K, method>; |
|
|
79 | } |
|
|
80 | |
|
|
81 | R call (A1 a1) const |
|
|
82 | { |
|
|
83 | return func (self, a1); |
|
|
84 | } |
|
|
85 | |
|
|
86 | R operator ()(A1 a1) const |
|
|
87 | { |
|
|
88 | return call (a1); |
|
|
89 | } |
|
|
90 | |
|
|
91 | private: |
|
|
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 | } |
|
|
102 | }; |
|
|
103 | |
|
|
104 | template<class R, class A1, class A2> |
|
|
105 | struct 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 | |
|
|
126 | private: |
|
|
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 | |
|
|
139 | template<class R, class A1, class A2, class A3> |
|
|
140 | struct 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 | |
|
|
161 | private: |
|
|
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 | |
|
|
174 | template<class R, class A1, class A2, class A3, class A4> |
|
|
175 | struct 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 | |
|
|
196 | private: |
|
|
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 | |
|
|
209 | template<class R, class A1, class A2, class A3, class A4, class A5> |
|
|
210 | struct 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 | |
|
|
231 | private: |
|
|
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 | |
|
|
244 | template<class R, class A1, class A2, class A3, class A4, class A5, class A6> |
|
|
245 | struct 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 | |
|
|
266 | private: |
|
|
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 | |
|
|
279 | template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7> |
|
|
280 | struct 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 | |
|
|
301 | private: |
|
|
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 | |
|
|
314 | template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> |
|
|
315 | struct 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 | |
|
|
336 | private: |
|
|
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 | |
|
|
349 | template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> |
|
|
350 | struct 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 | |
|
|
371 | private: |
|
|
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 | |
|
|
384 | template<class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> |
|
|
385 | struct 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 | |
|
|
406 | private: |
|
|
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 | |
|
|
419 | |
|
|
420 | #endif |
75 | #endif |