| 1 |
pcg |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
pcg |
1.10 |
use strict; |
| 4 |
|
|
|
| 5 |
pcg |
1.1 |
print <<EOF; |
| 6 |
pcg |
1.6 |
// THIS IS A GENERATED FILE: RUN callback.pl to regenerate it |
| 7 |
|
|
// THIS IS A GENERATED FILE: callback.pl is part of the GVPE |
| 8 |
|
|
// THIS IS A GENERATED FILE: distribution. |
| 9 |
pcg |
1.1 |
|
| 10 |
|
|
/* |
| 11 |
|
|
callback.h -- C++ callback mechanism |
| 12 |
pcg |
1.10 |
Copyright (C) 2003-2007 Marc Lehmann <pcg\@goof.com> |
| 13 |
pcg |
1.1 |
|
| 14 |
pcg |
1.4 |
This file is part of GVPE. |
| 15 |
|
|
|
| 16 |
|
|
GVPE is free software; you can redistribute it and/or modify |
| 17 |
pcg |
1.1 |
it under the terms of the GNU General Public License as published by |
| 18 |
|
|
the Free Software Foundation; either version 2 of the License, or |
| 19 |
|
|
(at your option) any later version. |
| 20 |
|
|
|
| 21 |
|
|
This program is distributed in the hope that it will be useful, |
| 22 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
|
|
GNU General Public License for more details. |
| 25 |
|
|
|
| 26 |
|
|
You should have received a copy of the GNU General Public License |
| 27 |
pcg |
1.4 |
along with gvpe; if not, write to the Free Software |
| 28 |
pcg |
1.5 |
Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 |
pcg |
1.1 |
*/ |
| 30 |
|
|
|
| 31 |
pcg |
1.3 |
#ifndef CALLBACK_H__ |
| 32 |
|
|
#define CALLBACK_H__ |
| 33 |
pcg |
1.1 |
|
| 34 |
pcg |
1.10 |
#define CALLBACK_H_VERSION 3 |
| 35 |
pcg |
1.9 |
|
| 36 |
pcg |
1.11 |
template<typename signature> |
| 37 |
|
|
struct callback; |
| 38 |
pcg |
1.9 |
|
| 39 |
pcg |
1.1 |
EOF |
| 40 |
|
|
|
| 41 |
pcg |
1.9 |
for my $a (0..10) { |
| 42 |
pcg |
1.1 |
my $CLASS = join "", map ", class A$_", 1..$a; |
| 43 |
|
|
my $TYPE = join ", ", map "A$_", 1..$a; |
| 44 |
|
|
my $ARG = join ", ", map "a$_", 1..$a; |
| 45 |
|
|
my $TYPEARG = join ", ", map "A$_ a$_", 1..$a; |
| 46 |
pcg |
1.9 |
my $TYPEDEFS = join " ", map "typedef A$_ arg$_\_type;", 1..$a; |
| 47 |
|
|
my $TYPEvoid = $TYPE ? $TYPE : "void"; |
| 48 |
pcg |
1.11 |
my $_ARG = $ARG ? ", $ARG" : ""; |
| 49 |
pcg |
1.9 |
my $_TYPE = $TYPE ? ", $TYPE" : ""; |
| 50 |
pcg |
1.11 |
my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : ""; |
| 51 |
pcg |
1.9 |
my $_TTYPE = $a ? join "", map ", typename T::arg$_\_type", 1..$a : ""; |
| 52 |
pcg |
1.1 |
|
| 53 |
|
|
print <<EOF; |
| 54 |
|
|
template<class R$CLASS> |
| 55 |
pcg |
1.11 |
struct callback<R ($TYPE)> |
| 56 |
pcg |
1.9 |
{ |
| 57 |
pcg |
1.11 |
typedef R (*ptr_type)(void *self$_TYPE); |
| 58 |
pcg |
1.9 |
|
| 59 |
pcg |
1.11 |
private: |
| 60 |
pcg |
1.1 |
|
| 61 |
pcg |
1.11 |
void *self; |
| 62 |
|
|
ptr_type func; |
| 63 |
|
|
|
| 64 |
|
|
protected: |
| 65 |
|
|
|
| 66 |
|
|
template<typename method> |
| 67 |
|
|
struct thunktype; |
| 68 |
|
|
|
| 69 |
|
|
template<class klass> |
| 70 |
|
|
struct thunktype<R (klass::*)> |
| 71 |
|
|
{ |
| 72 |
|
|
typedef klass K; |
| 73 |
|
|
}; |
| 74 |
|
|
|
| 75 |
|
|
template<class klass, R (klass::*method)($TYPE)> |
| 76 |
|
|
static R thunk (void *self$_TYPEARG) |
| 77 |
|
|
{ |
| 78 |
|
|
klass *obj = static_cast<klass *>(self); |
| 79 |
|
|
return (obj->*method) ($ARG); |
| 80 |
|
|
} |
| 81 |
pcg |
1.1 |
|
| 82 |
|
|
public: |
| 83 |
pcg |
1.11 |
template<class K, R (K::*method)($TYPE)> |
| 84 |
|
|
void set (K *object) |
| 85 |
pcg |
1.10 |
{ |
| 86 |
pcg |
1.11 |
self = object; |
| 87 |
|
|
func = thunk<K, method>; |
| 88 |
pcg |
1.10 |
} |
| 89 |
|
|
|
| 90 |
pcg |
1.11 |
R call ($TYPEARG) const |
| 91 |
pcg |
1.10 |
{ |
| 92 |
pcg |
1.11 |
return func (self$_ARG); |
| 93 |
pcg |
1.10 |
} |
| 94 |
pcg |
1.1 |
|
| 95 |
|
|
R operator ()($TYPEARG) const |
| 96 |
pcg |
1.10 |
{ |
| 97 |
|
|
return call ($ARG); |
| 98 |
|
|
} |
| 99 |
pcg |
1.1 |
}; |
| 100 |
|
|
|
| 101 |
|
|
EOF |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
|
print <<EOF |
| 105 |
pcg |
1.9 |
|
| 106 |
pcg |
1.1 |
#endif |
| 107 |
|
|
EOF |
| 108 |
|
|
|