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

Comparing libev/ev++.h (file contents):
Revision 1.42 by root, Mon Nov 3 14:27:06 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,
159 return false; 160 return false;
160#endif 161#endif
161 } 162 }
162 163
163#if EV_MULTIPLICITY 164#if EV_MULTIPLICITY
164 bool operator == (struct ev_loop *other) const throw () 165 bool operator == (const EV_P) const throw ()
165 { 166 {
166 return this->EV_AX == other; 167 return this->EV_AX == EV_A;
167 }
168
169 bool operator != (struct ev_loop *other) const throw ()
170 { 168 }
171 return ! (*this == other); 169
170 bool operator != (const EV_P) const throw ()
172 } 171 {
173
174 bool operator == (const struct ev_loop *other) const throw ()
175 {
176 return this->EV_AX == other;
177 }
178
179 bool operator != (const struct ev_loop *other) const throw ()
180 {
181 return (*this == other); 172 return (*this == EV_A);
182 } 173 }
183 174
184 operator struct ev_loop * () const throw () 175 operator struct ev_loop * () const throw ()
185 { 176 {
186 return EV_AX; 177 return EV_AX;
250 { 241 {
251 ev_set_timeout_collect_interval (EV_AX_ interval); 242 ev_set_timeout_collect_interval (EV_AX_ interval);
252 } 243 }
253 244
254 // function callback 245 // function callback
255 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 ()
256 { 247 {
257 ev_once (EV_AX_ fd, events, timeout, cb, arg); 248 ev_once (EV_AX_ fd, events, timeout, cb, arg);
258 } 249 }
259 250
260 // method callback 251 // method callback
262 void once (int fd, int events, tstamp timeout, K *object) throw () 253 void once (int fd, int events, tstamp timeout, K *object) throw ()
263 { 254 {
264 once (fd, events, timeout, method_thunk<K, method>, object); 255 once (fd, events, timeout, method_thunk<K, method>, object);
265 } 256 }
266 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
267 template<class K, void (K::*method)(int)> 265 template<class K, void (K::*method)(int)>
268 static void method_thunk (int revents, void* arg) 266 static void method_thunk (int revents, void *arg)
269 {
270 K *obj = static_cast<K *>(arg);
271 (obj->*method) (revents);
272 } 267 {
268 static_cast<K *>(arg)->*method
269 (revents);
270 }
273 271
274 // const method callback 272 // no-argument method callback
275 template<class K, void (K::*method)(int) const>
276 void once (int fd, int events, tstamp timeout, const K *object) throw ()
277 {
278 once (fd, events, timeout, const_method_thunk<K, method>, object);
279 }
280
281 template<class K, void (K::*method)(int) const>
282 static void const_method_thunk (int revents, void* arg)
283 {
284 K *obj = static_cast<K *>(arg);
285 (obj->*method) (revents);
286 }
287
288 // simple method callback
289 template<class K, void (K::*method)()> 273 template<class K, void (K::*method)()>
290 void once (int fd, int events, tstamp timeout, K *object) throw () 274 void once (int fd, int events, tstamp timeout, K *object) throw ()
291 { 275 {
292 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 276 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
293 } 277 }
294 278
295 template<class K, void (K::*method)()> 279 template<class K, void (K::*method)()>
296 static void method_noargs_thunk (int revents, void* arg) 280 static void method_noargs_thunk (int revents, void *arg)
297 { 281 {
298 K *obj = static_cast<K *>(arg); 282 static_cast<K *>(arg)->*method
299 (obj->*method) (); 283 ();
300 } 284 }
301 285
302 // simpler function callback 286 // simpler function callback
303 template<void (*cb)(int)> 287 template<void (*cb)(int)>
304 void once (int fd, int events, tstamp timeout) throw () 288 void once (int fd, int events, tstamp timeout) throw ()
305 { 289 {
306 once (fd, events, timeout, simpler_func_thunk<cb>); 290 once (fd, events, timeout, simpler_func_thunk<cb>);
307 } 291 }
308 292
309 template<void (*cb)(int)> 293 template<void (*cb)(int)>
310 static void simpler_func_thunk (int revents, void* arg) 294 static void simpler_func_thunk (int revents, void *arg)
311 { 295 {
296 (*cb)
312 (*cb) (revents); 297 (revents);
313 } 298 }
314 299
315 // simplest function callback 300 // simplest function callback
316 template<void (*cb)()> 301 template<void (*cb)()>
317 void once (int fd, int events, tstamp timeout) throw () 302 void once (int fd, int events, tstamp timeout) throw ()
318 { 303 {
319 once (fd, events, timeout, simplest_func_thunk<cb>); 304 once (fd, events, timeout, simplest_func_thunk<cb>);
320 } 305 }
321 306
322 template<void (*cb)()> 307 template<void (*cb)()>
323 static void simplest_func_thunk (int revents, void* arg) 308 static void simplest_func_thunk (int revents, void *arg)
324 { 309 {
325 (*cb) (); 310 (*cb)
311 ();
326 } 312 }
327 313
328 void feed_fd_event (int fd, int revents) throw () 314 void feed_fd_event (int fd, int revents) throw ()
329 { 315 {
330 ev_feed_fd_event (EV_AX_ fd, revents); 316 ev_feed_fd_event (EV_AX_ fd, revents);
420 struct base : ev_watcher 406 struct base : ev_watcher
421 { 407 {
422 #if EV_MULTIPLICITY 408 #if EV_MULTIPLICITY
423 EV_PX; 409 EV_PX;
424 410
425 void set (EV_PX) throw () 411 void set (EV_P) throw ()
426 { 412 {
427 this->EV_A = EV_A; 413 this->EV_A = EV_A;
428 } 414 }
429 #endif 415 #endif
430 416
434 #endif 420 #endif
435 { 421 {
436 ev_init (this, 0); 422 ev_init (this, 0);
437 } 423 }
438 424
439 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 ()
440 { 426 {
441 this->data = data; 427 this->data = (void *)data;
442 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);
443 } 443 }
444 444
445 // method callback 445 // method callback
446 template<class K, void (K::*method)(watcher &w, int)> 446 template<class K, void (K::*method)(watcher &w, int)>
447 void set (K *object) throw () 447 void set (K *object) throw ()
448 { 448 {
449 set_ (object, method_thunk<K, method>); 449 set_ (object, method_thunk<K, method>);
450 } 450 }
451 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
452 template<class K, void (K::*method)(watcher &w, int)> 459 template<class K, void (K::*method)(watcher &w, int)>
453 static void method_thunk (EV_P_ ev_watcher *w, int revents) 460 static void method_thunk (EV_P_ ev_watcher *w, int revents)
454 { 461 {
455 K *obj = static_cast<K *>(w->data); 462 (static_cast<K *>(w->data)->*method)
456 (obj->*method) (*static_cast<watcher *>(w), revents);
457 }
458
459 // const method callback
460 template<class K, void (K::*method)(watcher &w, int) const>
461 void set (const K *object) throw ()
462 {
463 set_ (object, const_method_thunk<K, method>);
464 }
465
466 template<class K, void (K::*method)(watcher &w, int) const>
467 static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
468 {
469 K *obj = static_cast<K *>(w->data);
470 (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
471 }
472
473 // function callback
474 template<void (*function)(watcher &w, int)>
475 void set (void *data = 0) throw ()
476 {
477 set_ (data, function_thunk<function>);
478 }
479
480 template<void (*function)(watcher &w, int)>
481 static void function_thunk (EV_P_ ev_watcher *w, int revents)
482 {
483 function (*static_cast<watcher *>(w), revents); 463 (*static_cast<watcher *>(w), revents);
484 } 464 }
485 465
486 // simple callback 466 // no-argument callback
487 template<class K, void (K::*method)()> 467 template<class K, void (K::*method)()>
488 void set (K *object) throw () 468 void set (K *object) throw ()
489 { 469 {
490 set_ (object, method_noargs_thunk<K, method>); 470 set_ (object, method_noargs_thunk<K, method>);
491 } 471 }
492 472
493 template<class K, void (K::*method)()> 473 template<class K, void (K::*method)()>
494 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)
495 { 475 {
496 K *obj = static_cast<K *>(w->data); 476 static_cast<K *>(w->data)->*method
497 (obj->*method) (); 477 ();
498 } 478 }
499 479
500 void operator ()(int events = EV_UNDEF) 480 void operator ()(int events = EV_UNDEF)
501 { 481 {
482 return
502 return ev_cb (static_cast<ev_watcher *>(this)) 483 ev_cb (static_cast<ev_watcher *>(this))
503 (static_cast<ev_watcher *>(this), events); 484 (static_cast<ev_watcher *>(this), events);
504 } 485 }
505 486
506 bool is_active () const throw () 487 bool is_active () const throw ()
507 { 488 {
508 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