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

Comparing libev/ev++.h (file contents):
Revision 1.41 by root, Tue Sep 30 18:35:47 2008 UTC vs.
Revision 1.44 by root, Wed Dec 3 15:23:44 2008 UTC

56 56
57namespace ev { 57namespace ev {
58 58
59 typedef ev_tstamp tstamp; 59 typedef ev_tstamp tstamp;
60 60
61 enum { 61 enum
62 {
62 UNDEF = EV_UNDEF, 63 UNDEF = EV_UNDEF,
63 NONE = EV_NONE, 64 NONE = EV_NONE,
64 READ = EV_READ, 65 READ = EV_READ,
65 WRITE = EV_WRITE, 66 WRITE = EV_WRITE,
66 TIMEOUT = EV_TIMEOUT, 67 TIMEOUT = EV_TIMEOUT,
72 CHECK = EV_CHECK, 73 CHECK = EV_CHECK,
73 PREPARE = EV_PREPARE, 74 PREPARE = EV_PREPARE,
74 FORK = EV_FORK, 75 FORK = EV_FORK,
75 ASYNC = EV_ASYNC, 76 ASYNC = EV_ASYNC,
76 EMBED = EV_EMBED, 77 EMBED = EV_EMBED,
78# undef ERROR // some systems stupidly #define ERROR
77 ERROR = EV_ERROR, 79 ERROR = EV_ERROR,
78 }; 80 };
79 81
80 enum 82 enum
81 { 83 {
158 return false; 160 return false;
159#endif 161#endif
160 } 162 }
161 163
162#if EV_MULTIPLICITY 164#if EV_MULTIPLICITY
163 bool operator == (struct ev_loop *other) const throw () 165 bool operator == (const EV_P) const throw ()
164 { 166 {
165 return this->EV_AX == other; 167 return this->EV_AX == EV_A;
166 }
167
168 bool operator != (struct ev_loop *other) const throw ()
169 { 168 }
170 return ! (*this == other); 169
170 bool operator != (const EV_P) const throw ()
171 } 171 {
172
173 bool operator == (const struct ev_loop *other) const throw ()
174 {
175 return this->EV_AX == other;
176 }
177
178 bool operator != (const struct ev_loop *other) const throw ()
179 {
180 return (*this == other); 172 return (*this == EV_A);
181 } 173 }
182 174
183 operator struct ev_loop * () const throw () 175 operator struct ev_loop * () const throw ()
184 { 176 {
185 return EV_AX; 177 return EV_AX;
249 { 241 {
250 ev_set_timeout_collect_interval (EV_AX_ interval); 242 ev_set_timeout_collect_interval (EV_AX_ interval);
251 } 243 }
252 244
253 // function callback 245 // function callback
254 void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw () 246 void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) throw ()
255 { 247 {
256 ev_once (EV_AX_ fd, events, timeout, cb, arg); 248 ev_once (EV_AX_ fd, events, timeout, cb, arg);
257 } 249 }
258 250
259 // method callback 251 // method callback
261 void once (int fd, int events, tstamp timeout, K *object) throw () 253 void once (int fd, int events, tstamp timeout, K *object) throw ()
262 { 254 {
263 once (fd, events, timeout, method_thunk<K, method>, object); 255 once (fd, events, timeout, method_thunk<K, method>, object);
264 } 256 }
265 257
258 // default method == operator ()
259 template<class K>
260 void once (int fd, int events, tstamp timeout, K *object) throw ()
261 {
262 once (fd, events, timeout, method_thunk<K, &K::operator ()>, object);
263 }
264
266 template<class K, void (K::*method)(int)> 265 template<class K, void (K::*method)(int)>
267 static void method_thunk (int revents, void* arg) 266 static void method_thunk (int revents, void *arg)
268 {
269 K *obj = static_cast<K *>(arg);
270 (obj->*method) (revents);
271 } 267 {
268 static_cast<K *>(arg)->*method
269 (revents);
270 }
272 271
273 // const method callback 272 // no-argument method callback
274 template<class K, void (K::*method)(int) const>
275 void once (int fd, int events, tstamp timeout, const K *object) throw ()
276 {
277 once (fd, events, timeout, const_method_thunk<K, method>, object);
278 }
279
280 template<class K, void (K::*method)(int) const>
281 static void const_method_thunk (int revents, void* arg)
282 {
283 K *obj = static_cast<K *>(arg);
284 (obj->*method) (revents);
285 }
286
287 // simple method callback
288 template<class K, void (K::*method)()> 273 template<class K, void (K::*method)()>
289 void once (int fd, int events, tstamp timeout, K *object) throw () 274 void once (int fd, int events, tstamp timeout, K *object) throw ()
290 { 275 {
291 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 276 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
292 } 277 }
293 278
294 template<class K, void (K::*method)()> 279 template<class K, void (K::*method)()>
295 static void method_noargs_thunk (int revents, void* arg) 280 static void method_noargs_thunk (int revents, void *arg)
296 { 281 {
297 K *obj = static_cast<K *>(arg); 282 static_cast<K *>(arg)->*method
298 (obj->*method) (); 283 ();
299 } 284 }
300 285
301 // simpler function callback 286 // simpler function callback
302 template<void (*cb)(int)> 287 template<void (*cb)(int)>
303 void once (int fd, int events, tstamp timeout) throw () 288 void once (int fd, int events, tstamp timeout) throw ()
304 { 289 {
305 once (fd, events, timeout, simpler_func_thunk<cb>); 290 once (fd, events, timeout, simpler_func_thunk<cb>);
306 } 291 }
307 292
308 template<void (*cb)(int)> 293 template<void (*cb)(int)>
309 static void simpler_func_thunk (int revents, void* arg) 294 static void simpler_func_thunk (int revents, void *arg)
310 { 295 {
296 (*cb)
311 (*cb) (revents); 297 (revents);
312 } 298 }
313 299
314 // simplest function callback 300 // simplest function callback
315 template<void (*cb)()> 301 template<void (*cb)()>
316 void once (int fd, int events, tstamp timeout) throw () 302 void once (int fd, int events, tstamp timeout) throw ()
317 { 303 {
318 once (fd, events, timeout, simplest_func_thunk<cb>); 304 once (fd, events, timeout, simplest_func_thunk<cb>);
319 } 305 }
320 306
321 template<void (*cb)()> 307 template<void (*cb)()>
322 static void simplest_func_thunk (int revents, void* arg) 308 static void simplest_func_thunk (int revents, void *arg)
323 { 309 {
324 (*cb) (); 310 (*cb)
311 ();
325 } 312 }
326 313
327 void feed_fd_event (int fd, int revents) throw () 314 void feed_fd_event (int fd, int revents) throw ()
328 { 315 {
329 ev_feed_fd_event (EV_AX_ fd, revents); 316 ev_feed_fd_event (EV_AX_ fd, revents);
419 struct base : ev_watcher 406 struct base : ev_watcher
420 { 407 {
421 #if EV_MULTIPLICITY 408 #if EV_MULTIPLICITY
422 EV_PX; 409 EV_PX;
423 410
424 void set (EV_PX) throw () 411 void set (EV_P) throw ()
425 { 412 {
426 this->EV_A = EV_A; 413 this->EV_A = EV_A;
427 } 414 }
428 #endif 415 #endif
429 416
433 #endif 420 #endif
434 { 421 {
435 ev_init (this, 0); 422 ev_init (this, 0);
436 } 423 }
437 424
438 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () 425 void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
439 { 426 {
440 this->data = data; 427 this->data = (void *)data;
441 ev_set_cb (static_cast<ev_watcher *>(this), cb); 428 ev_set_cb (static_cast<ev_watcher *>(this), cb);
429 }
430
431 // function callback
432 template<void (*function)(watcher &w, int)>
433 void set (void *data = 0) throw ()
434 {
435 set_ (data, function_thunk<function>);
436 }
437
438 template<void (*function)(watcher &w, int)>
439 static void function_thunk (EV_P_ ev_watcher *w, int revents)
440 {
441 function
442 (*static_cast<watcher *>(w), revents);
442 } 443 }
443 444
444 // method callback 445 // method callback
445 template<class K, void (K::*method)(watcher &w, int)> 446 template<class K, void (K::*method)(watcher &w, int)>
446 void set (K *object) throw () 447 void set (K *object) throw ()
447 { 448 {
448 set_ (object, method_thunk<K, method>); 449 set_ (object, method_thunk<K, method>);
449 } 450 }
450 451
452 // default method == operator ()
453 template<class K>
454 void set (K *object) throw ()
455 {
456 set_ (object, method_thunk<K, &K::operator ()>);
457 }
458
451 template<class K, void (K::*method)(watcher &w, int)> 459 template<class K, void (K::*method)(watcher &w, int)>
452 static void method_thunk (EV_P_ ev_watcher *w, int revents) 460 static void method_thunk (EV_P_ ev_watcher *w, int revents)
453 { 461 {
454 K *obj = static_cast<K *>(w->data); 462 (static_cast<K *>(w->data)->*method)
455 (obj->*method) (*static_cast<watcher *>(w), revents);
456 }
457
458 // const method callback
459 template<class K, void (K::*method)(watcher &w, int) const>
460 void set (const K *object) throw ()
461 {
462 set_ (object, const_method_thunk<K, method>);
463 }
464
465 template<class K, void (K::*method)(watcher &w, int) const>
466 static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
467 {
468 K *obj = static_cast<K *>(w->data);
469 (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
470 }
471
472 // function callback
473 template<void (*function)(watcher &w, int)>
474 void set (void *data = 0) throw ()
475 {
476 set_ (data, function_thunk<function>);
477 }
478
479 template<void (*function)(watcher &w, int)>
480 static void function_thunk (EV_P_ ev_watcher *w, int revents)
481 {
482 function (*static_cast<watcher *>(w), revents); 463 (*static_cast<watcher *>(w), revents);
483 } 464 }
484 465
485 // simple callback 466 // no-argument callback
486 template<class K, void (K::*method)()> 467 template<class K, void (K::*method)()>
487 void set (K *object) throw () 468 void set (K *object) throw ()
488 { 469 {
489 set_ (object, method_noargs_thunk<K, method>); 470 set_ (object, method_noargs_thunk<K, method>);
490 } 471 }
491 472
492 template<class K, void (K::*method)()> 473 template<class K, void (K::*method)()>
493 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) 474 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
494 { 475 {
495 K *obj = static_cast<K *>(w->data); 476 static_cast<K *>(w->data)->*method
496 (obj->*method) (); 477 ();
497 } 478 }
498 479
499 void operator ()(int events = EV_UNDEF) 480 void operator ()(int events = EV_UNDEF)
500 { 481 {
482 return
501 return ev_cb (static_cast<ev_watcher *>(this)) 483 ev_cb (static_cast<ev_watcher *>(this))
502 (static_cast<ev_watcher *>(this), events); 484 (static_cast<ev_watcher *>(this), events);
503 } 485 }
504 486
505 bool is_active () const throw () 487 bool is_active () const throw ()
506 { 488 {
507 return ev_is_active (static_cast<const ev_watcher *>(this)); 489 return ev_is_active (static_cast<const ev_watcher *>(this));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines