ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/callback.pl
(Generate patch)

Comparing gvpe/src/callback.pl (file contents):
Revision 1.3 by pcg, Sat Jan 17 01:18:36 2004 UTC vs.
Revision 1.14 by pcg, Thu Aug 7 17:54:26 2008 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2 2
3use strict;
4
3print <<EOF; 5print <<EOF;
4// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it 6// THIS IS A GENERATED FILE: RUN callback.pl to regenerate it
5// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it 7// THIS IS A GENERATED FILE: callback.pl is part of the GVPE
6// THIS IS A GENERATED FILE, RUN callback.pl to regenerate it 8// THIS IS A GENERATED FILE: distribution.
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 9
11/* 10/*
12 callback.h -- C++ callback mechanism 11 * callback.h -- C++ callback mechanism
13 Copyright (C) 2003 Marc Lehmann <pcg\@goof.com> 12 * Copyright (C) 2003-2008 Marc Lehmann <pcg\@goof.com>
14 13 *
14 * This file is part of GVPE.
15 *
15 This program is free software; you can redistribute it and/or modify 16 * This program is free software; you can redistribute it and/or modify it
16 it under the terms of the GNU General Public License as published by 17 * under the terms of the GNU General Public License as published by the
17 the Free Software Foundation; either version 2 of the License, or 18 * Free Software Foundation; either version 3 of the License, or (at your
18 (at your option) any later version. 19 * option) any later version.
19 20 *
20 This program is distributed in the hope that it will be useful, 21 * This program is distributed in the hope that it will be useful, but
21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
23 GNU General Public License for more details. 24 * Public License for more details.
24 25 *
25 You should have received a copy of the GNU General Public License 26 * You should have received a copy of the GNU General Public License along
26 along with this program; if not, write to the Free Software 27 * with this program; if not, see <http://www.gnu.org/licenses/>.
27 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 28 *
29 * Additional permission under GNU GPL version 3 section 7
30 *
31 * If you modify this Program, or any covered work, by linking or
32 * combining it with the OpenSSL project's OpenSSL library (or a modified
33 * version of that library), containing parts covered by the terms of the
34 * OpenSSL or SSLeay licenses, the licensors of this Program grant you
35 * additional permission to convey the resulting work. Corresponding
36 * Source for a non-source form of such a combination shall include the
37 * source code for the parts of OpenSSL used as well as that of the
38 * covered work.
28*/ 39*/
29 40
30#ifndef CALLBACK_H__ 41#ifndef CALLBACK_H__
31#define CALLBACK_H__ 42#define CALLBACK_H__
32 43
44#define CALLBACK_H_VERSION 3
45
46template<typename signature>
47struct callback;
48
33EOF 49EOF
34 50
35for my $a (0..7) { 51for my $a (0..10) {
36 my $CLASS = join "", map ", class A$_", 1..$a; 52 my $CLASS = join "", map ", class A$_", 1..$a;
37 my $TYPE = join ", ", map "A$_", 1..$a; 53 my $TYPE = join ", ", map "A$_", 1..$a;
38 my $ARG = join ", ", map "a$_", 1..$a; 54 my $ARG = join ", ", map "a$_", 1..$a;
39 my $TYPEARG = join ", ", map "A$_ a$_", 1..$a; 55 my $TYPEARG = join ", ", map "A$_ a$_", 1..$a;
56 my $TYPEDEFS = join " ", map "typedef A$_ arg$_\_type;", 1..$a;
57 my $TYPEvoid = $TYPE ? $TYPE : "void";
40 my $_ARG = $ARG ? ", $ARG" : ""; 58 my $_ARG = $ARG ? ", $ARG" : "";
59 my $_TYPE = $TYPE ? ", $TYPE" : "";
41 my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : ""; 60 my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : "";
61 my $_TTYPE = $a ? join "", map ", typename T::arg$_\_type", 1..$a : "";
42 62
43 print <<EOF; 63 print <<EOF;
44template<class R$CLASS> 64template<class R$CLASS>
45class callback$a { 65struct callback<R ($TYPE)>
46 struct object { }; 66{
67 typedef R (*ptr_type)(void *self$_TYPE);
47 68
48 void *obj; 69 template<class K, R (K::*method)($TYPE)>
49 R (object::*meth)($TYPE); 70 void set (K *object)
71 {
72 self = object;
73 func = thunk<K, method>;
74 }
50 75
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
66public:
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 76 R call ($TYPEARG) const
77 { 77 {
78 return prxy->call (obj, meth$_ARG); 78 return func (self$_ARG);
79 } 79 }
80 80
81 R operator ()($TYPEARG) const 81 R operator ()($TYPEARG) const
82 { 82 {
83 return call ($ARG); 83 return call ($ARG);
84 } 84 }
85
86private:
87
88 void *self;
89 ptr_type func;
90
91 template<class klass, R (klass::*method)($TYPE)>
92 static R thunk (void *self$_TYPEARG)
93 {
94 klass *obj = static_cast<klass *>(self);
95 return (obj->*method) ($ARG);
96 }
85}; 97};
86 98
87EOF 99EOF
88} 100}
89 101
90print <<EOF 102print <<EOF
103
91#endif 104#endif
92EOF 105EOF
93 106

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines