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.6 by pcg, Tue Nov 29 19:21:09 2005 UTC vs.
Revision 1.9 by pcg, Wed May 31 00:31:47 2006 UTC

5// THIS IS A GENERATED FILE: callback.pl is part of the GVPE 5// THIS IS A GENERATED FILE: callback.pl is part of the GVPE
6// THIS IS A GENERATED FILE: distribution. 6// THIS IS A GENERATED FILE: distribution.
7 7
8/* 8/*
9 callback.h -- C++ callback mechanism 9 callback.h -- C++ callback mechanism
10 Copyright (C) 2003-2005 Marc Lehmann <pcg\@goof.com> 10 Copyright (C) 2003-2006 Marc Lehmann <pcg\@goof.com>
11 11
12 This file is part of GVPE. 12 This file is part of GVPE.
13 13
14 GVPE is free software; you can redistribute it and/or modify 14 GVPE is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by 15 it under the terms of the GNU General Public License as published by
27*/ 27*/
28 28
29#ifndef CALLBACK_H__ 29#ifndef CALLBACK_H__
30#define CALLBACK_H__ 30#define CALLBACK_H__
31 31
32#define CALLBACK_H_VERSION 2
33
34template<class signature>
35struct callback_funtype_trait;
36
37template<int arity, class signature>
38struct callback_get_impl;
39
32EOF 40EOF
33 41
34for my $a (0..7) { 42for my $a (0..10) {
35 my $CLASS = join "", map ", class A$_", 1..$a; 43 my $CLASS = join "", map ", class A$_", 1..$a;
36 my $TYPE = join ", ", map "A$_", 1..$a; 44 my $TYPE = join ", ", map "A$_", 1..$a;
37 my $ARG = join ", ", map "a$_", 1..$a; 45 my $ARG = join ", ", map "a$_", 1..$a;
38 my $TYPEARG = join ", ", map "A$_ a$_", 1..$a; 46 my $TYPEARG = join ", ", map "A$_ a$_", 1..$a;
47 my $TYPEDEFS = join " ", map "typedef A$_ arg$_\_type;", 1..$a;
48 my $TYPEvoid = $TYPE ? $TYPE : "void";
49 my $_TYPE = $TYPE ? ", $TYPE" : "";
39 my $_ARG = $ARG ? ", $ARG" : ""; 50 my $_ARG = $ARG ? ", $ARG" : "";
40 my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : ""; 51 my $_TYPEARG = $TYPEARG ? ", $TYPEARG" : "";
52 my $_TTYPE = $a ? join "", map ", typename T::arg$_\_type", 1..$a : "";
41 53
42 print <<EOF; 54 print <<EOF;
43template<class R$CLASS> 55template<class R$CLASS>
44class callback$a { 56class callback$a
57{
45 struct object { }; 58 struct object { };
59
60 typedef R (object::*ptr_type)($TYPE);
46 61
47 void *obj; 62 void *obj;
48 R (object::*meth)($TYPE); 63 R (object::*meth)($TYPE);
49 64
50 /* a proxy is a kind of recipe on how to call a specific class method */ 65 /* a proxy is a kind of recipe on how to call a specific class method */
51 struct proxy_base { 66 struct proxy_base {
52 virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) = 0; 67 virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) const = 0;
53 }; 68 };
54 template<class O1, class O2> 69 template<class O1, class O2>
55 struct proxy : proxy_base { 70 struct proxy : proxy_base {
56 virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) 71 virtual R call (void *obj, R (object::*meth)($TYPE)$_TYPEARG) const
57 { 72 {
58 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)($TYPE)>(meth))) 73 return (R)((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<R (O2::*)($TYPE)>(meth)))
59 ($ARG); 74 ($ARG);
60 } 75 }
61 }; 76 };
62 77
63 proxy_base *prxy; 78 proxy_base *prxy;
64 79
65public: 80public:
66 template<class O1, class O2> 81 template<class O1, class O2>
67 callback$a (O1 *object, R (O2::*method)($TYPE)) 82 explicit callback$a (O1 *object, R (O2::*method)($TYPE))
68 { 83 {
69 static proxy<O1,O2> p; 84 static proxy<O1,O2> p;
70 obj = reinterpret_cast<void *>(object); 85 obj = reinterpret_cast<void *>(object);
71 meth = reinterpret_cast<R (object::*)($TYPE)>(method); 86 meth = reinterpret_cast<R (object::*)($TYPE)>(method);
72 prxy = &p; 87 prxy = &p;
81 { 96 {
82 return call ($ARG); 97 return call ($ARG);
83 } 98 }
84}; 99};
85 100
101template<class R$CLASS>
102struct callback_funtype_trait$a
103{
104 static const int arity = $a;
105 typedef R type ($TYPEvoid);
106 typedef R result_type;
107 $TYPEDEFS
108};
109
110template<class R$CLASS>
111struct callback_funtype_trait<R ($TYPE)> : callback_funtype_trait$a<R$_TYPE>
112{
113};
114
115template<class signature>
116struct callback_get_impl<$a, signature>
117{
118 typedef callback_funtype_trait<signature> T;
119 typedef callback$a<typename T::result_type$_TTYPE> type;
120};
121
86EOF 122EOF
87} 123}
88 124
89print <<EOF 125print <<EOF
126
127template<class signature>
128struct callback : callback_get_impl<callback_funtype_trait<signature>::arity, signature>::type
129{
130 typedef typename callback_get_impl<callback_funtype_trait<signature>::arity, signature>::type base_type;
131
132 template<class O, class M>
133 explicit callback (O object, M method)
134 : base_type (object, method)
135 {
136 }
137};
138
90#endif 139#endif
91EOF 140EOF
92 141

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines