1 |
pcg |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
print <<EOF; |
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 |
|
|
// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it |
8 |
|
|
// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it |
9 |
|
|
// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it |
10 |
|
|
|
11 |
|
|
/* |
12 |
|
|
callback.h -- C++ callback mechanism |
13 |
pcg |
1.2 |
Copyright (C) 2003 Marc Lehmann <pcg\@goof.com> |
14 |
pcg |
1.1 |
|
15 |
|
|
This program is free software; you can redistribute it and/or modify |
16 |
|
|
it under the terms of the GNU General Public License as published by |
17 |
|
|
the Free Software Foundation; either version 2 of the License, or |
18 |
|
|
(at your option) any later version. |
19 |
|
|
|
20 |
|
|
This program is distributed in the hope that it will be useful, |
21 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 |
|
|
GNU General Public License for more details. |
24 |
|
|
|
25 |
|
|
You should have received a copy of the GNU General Public License |
26 |
|
|
along with this program; if not, write to the Free Software |
27 |
|
|
Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
|
|
*/ |
29 |
|
|
|
30 |
|
|
#ifndef VPE_CALLBACK_H__ |
31 |
|
|
#define VPE_CALLBACK_H__ |
32 |
|
|
|
33 |
|
|
EOF |
34 |
|
|
|
35 |
|
|
for my $a (0..7) { |
36 |
|
|
my $CLASS = join "", map ", class A$_", 1..$a; |
37 |
|
|
my $TYPE = join ", ", map "A$_", 1..$a; |
38 |
|
|
my $ARG = join ", ", map "a$_", 1..$a; |
39 |
|
|
my $TYPEARG = join ", ", map "A$_ a$_", 1..$a; |
40 |
|
|
my $_ARG = $ARG ? ", $ARG" : ""; |
41 |
|
|
my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : ""; |
42 |
|
|
|
43 |
|
|
print <<EOF; |
44 |
|
|
template<class R$CLASS> |
45 |
|
|
class callback$a { |
46 |
|
|
struct object { }; |
47 |
|
|
|
48 |
|
|
void *obj; |
49 |
|
|
R (object::*meth)($TYPE); |
50 |
|
|
|
51 |
|
|
/* a proxy is a kind of recipe on how to call a specific class method */ |
52 |
|
|
struct proxy_base { |
53 |
|
|
virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) = 0; |
54 |
|
|
}; |
55 |
|
|
template<class O1, class O2> |
56 |
|
|
struct proxy : proxy_base { |
57 |
|
|
virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) |
58 |
|
|
{ |
59 |
|
|
((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)($TYPE)>(meth))) |
60 |
|
|
($ARG); |
61 |
|
|
} |
62 |
|
|
}; |
63 |
|
|
|
64 |
|
|
proxy_base *prxy; |
65 |
|
|
|
66 |
|
|
public: |
67 |
|
|
template<class O1, class O2> |
68 |
|
|
callback$a (O1 *object, R (O2::*method)($TYPE)) |
69 |
|
|
{ |
70 |
|
|
static proxy<O1,O2> p; |
71 |
|
|
obj = reinterpret_cast<void *>(object); |
72 |
|
|
meth = reinterpret_cast<R (object::*)($TYPE)>(method); |
73 |
|
|
prxy = &p; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
R call($TYPEARG) const |
77 |
|
|
{ |
78 |
|
|
return prxy->call (obj, meth$_ARG); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
R operator ()($TYPEARG) const |
82 |
|
|
{ |
83 |
|
|
return call ($ARG); |
84 |
|
|
} |
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
EOF |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
print <<EOF |
91 |
|
|
#endif |
92 |
|
|
EOF |
93 |
|
|
|