ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev++.h
(Generate patch)

Comparing libev/ev++.h (file contents):
Revision 1.8 by root, Tue Nov 27 08:20:41 2007 UTC vs.
Revision 1.11 by root, Tue Nov 27 22:31:52 2007 UTC

6namespace ev { 6namespace ev {
7 7
8 template<class watcher> 8 template<class watcher>
9 class callback 9 class callback
10 { 10 {
11 struct object { }; 11 struct klass; // it is vital that this is never defined
12 12
13 void *obj; 13 klass *o;
14 void (object::*meth)(watcher &, int); 14 void (klass::*m)(watcher &, int);
15
16 /* a proxy is a kind of recipe on how to call a specific class method */
17 struct proxy_base {
18 virtual void call (void *obj, void (object::*meth)(watcher &, int), watcher &w, int) const = 0;
19 };
20 template<class O1, class O2>
21 struct proxy : proxy_base {
22 virtual void call (void *obj, void (object::*meth)(watcher &, int), watcher &w, int e) const
23 {
24 ((reinterpret_cast<O1 *>(obj)) ->* (reinterpret_cast<void (O2::*)(watcher &, int)>(meth)))
25 (w, e);
26 }
27 };
28
29 proxy_base *prxy;
30 15
31 public: 16 public:
32 template<class O1, class O2> 17 template<class O1, class O2>
33 explicit callback (O1 *object, void (O2::*method)(watcher &, int)) 18 explicit callback (O1 *object, void (O2::*method)(watcher &, int))
34 { 19 {
35 static proxy<O1,O2> p;
36 obj = reinterpret_cast<void *>(object); 20 o = reinterpret_cast<klass *>(object);
37 meth = reinterpret_cast<void (object::*)(watcher &, int)>(method); 21 m = reinterpret_cast<void (klass::*)(watcher &, int)>(method);
38 prxy = &p;
39 } 22 }
40 23
24 // this works because a standards-compliant C++ compiler
25 // basically can't help it: it doesn't have the knowledge
26 // required to miscompile (klass is not defined anywhere
27 // and nothing is known about the constructor arguments) :)
41 void call (watcher *w, int e) const 28 void call (watcher *w, int revents)
42 { 29 {
43 return prxy->call (obj, meth, *w, e); 30 (o->*m) (*w, revents);
44 } 31 }
45 }; 32 };
46 33
47 enum { 34 enum {
48 UNDEF = EV_UNDEF, 35 UNDEF = EV_UNDEF,
50 READ = EV_READ, 37 READ = EV_READ,
51 WRITE = EV_WRITE, 38 WRITE = EV_WRITE,
52 TIMEOUT = EV_TIMEOUT, 39 TIMEOUT = EV_TIMEOUT,
53 PERIODIC = EV_PERIODIC, 40 PERIODIC = EV_PERIODIC,
54 SIGNAL = EV_SIGNAL, 41 SIGNAL = EV_SIGNAL,
42 CHILD = EV_CHILD,
43 STAT = EV_STAT,
55 IDLE = EV_IDLE, 44 IDLE = EV_IDLE,
56 CHECK = EV_CHECK, 45 CHECK = EV_CHECK,
57 PREPARE = EV_PREPARE, 46 PREPARE = EV_PREPARE,
58 CHILD = EV_CHILD, 47 FORK = EV_FORK,
48 EMBED = EV_EMBED,
59 ERROR = EV_ERROR, 49 ERROR = EV_ERROR,
60 }; 50 };
61 51
62 typedef ev_tstamp tstamp; 52 typedef ev_tstamp tstamp;
63 53
304 ev_embed_sweep (EV_A_ static_cast<ev_embed *>(this)); 294 ev_embed_sweep (EV_A_ static_cast<ev_embed *>(this));
305 } 295 }
306 EV_END_WATCHER (embed, embed) 296 EV_END_WATCHER (embed, embed)
307 #endif 297 #endif
308 298
299 #if EV_FORK_ENABLE
300 EV_BEGIN_WATCHER (fork, fork)
301 void set () { }
302 EV_END_WATCHER (fork, fork)
303 #endif
304
309 #undef EV_CONSTRUCT 305 #undef EV_CONSTRUCT
310 #undef EV_BEGIN_WATCHER 306 #undef EV_BEGIN_WATCHER
311 #undef EV_END_WATCHER 307 #undef EV_END_WATCHER
312} 308}
313 309

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines