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

Comparing libev/ev++.h (file contents):
Revision 1.43 by root, Wed Nov 5 14:36:18 2008 UTC vs.
Revision 1.45 by root, Fri Jul 10 00:36:21 2009 UTC

160 return false; 160 return false;
161#endif 161#endif
162 } 162 }
163 163
164#if EV_MULTIPLICITY 164#if EV_MULTIPLICITY
165 bool operator == (struct ev_loop *other) const throw () 165 bool operator == (const EV_P) const throw ()
166 { 166 {
167 return this->EV_AX == other; 167 return this->EV_AX == EV_A;
168 }
169
170 bool operator != (struct ev_loop *other) const throw ()
171 { 168 }
172 return ! (*this == other); 169
170 bool operator != (const EV_P) const throw ()
173 } 171 {
174
175 bool operator == (const struct ev_loop *other) const throw ()
176 {
177 return this->EV_AX == other;
178 }
179
180 bool operator != (const struct ev_loop *other) const throw ()
181 {
182 return (*this == other); 172 return (*this == EV_A);
183 } 173 }
184 174
185 operator struct ev_loop * () const throw () 175 operator struct ev_loop * () const throw ()
186 { 176 {
187 return EV_AX; 177 return EV_AX;
215#else 205#else
216 ev_default_fork (); 206 ev_default_fork ();
217#endif 207#endif
218 } 208 }
219 209
210 unsigned int backend () const throw ()
211 {
212 return ev_backend (EV_AX);
213 }
214
215 tstamp now () const throw ()
216 {
217 return ev_now (EV_AX);
218 }
219
220 void ref () throw ()
221 {
222 ev_ref (EV_AX);
223 }
224
225 void unref () throw ()
226 {
227 ev_unref (EV_AX);
228 }
229
230#if EV_MINIMAL < 2
220 unsigned int count () const throw () 231 unsigned int count () const throw ()
221 { 232 {
222 return ev_loop_count (EV_AX); 233 return ev_loop_count (EV_AX);
223 } 234 }
224 235
225 unsigned int backend () const throw () 236 unsigned int depth () const throw ()
226 {
227 return ev_backend (EV_AX);
228 } 237 {
229
230 tstamp now () const throw ()
231 {
232 return ev_now (EV_AX); 238 return ev_loop_depth (EV_AX);
233 }
234
235 void ref () throw ()
236 {
237 ev_ref (EV_AX);
238 }
239
240 void unref () throw ()
241 {
242 ev_unref (EV_AX);
243 } 239 }
244 240
245 void set_io_collect_interval (tstamp interval) throw () 241 void set_io_collect_interval (tstamp interval) throw ()
246 { 242 {
247 ev_set_io_collect_interval (EV_AX_ interval); 243 ev_set_io_collect_interval (EV_AX_ interval);
249 245
250 void set_timeout_collect_interval (tstamp interval) throw () 246 void set_timeout_collect_interval (tstamp interval) throw ()
251 { 247 {
252 ev_set_timeout_collect_interval (EV_AX_ interval); 248 ev_set_timeout_collect_interval (EV_AX_ interval);
253 } 249 }
250#endif
254 251
255 // function callback 252 // function callback
256 void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw () 253 void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) throw ()
257 { 254 {
258 ev_once (EV_AX_ fd, events, timeout, cb, arg); 255 ev_once (EV_AX_ fd, events, timeout, cb, arg);
259 } 256 }
260 257
261 // method callback 258 // method callback
263 void once (int fd, int events, tstamp timeout, K *object) throw () 260 void once (int fd, int events, tstamp timeout, K *object) throw ()
264 { 261 {
265 once (fd, events, timeout, method_thunk<K, method>, object); 262 once (fd, events, timeout, method_thunk<K, method>, object);
266 } 263 }
267 264
265 // default method == operator ()
266 template<class K>
267 void once (int fd, int events, tstamp timeout, K *object) throw ()
268 {
269 once (fd, events, timeout, method_thunk<K, &K::operator ()>, object);
270 }
271
268 template<class K, void (K::*method)(int)> 272 template<class K, void (K::*method)(int)>
269 static void method_thunk (int revents, void* arg) 273 static void method_thunk (int revents, void *arg)
270 {
271 K *obj = static_cast<K *>(arg);
272 (obj->*method) (revents);
273 } 274 {
275 static_cast<K *>(arg)->*method
276 (revents);
277 }
274 278
275 // const method callback 279 // no-argument method callback
276 template<class K, void (K::*method)(int) const>
277 void once (int fd, int events, tstamp timeout, const K *object) throw ()
278 {
279 once (fd, events, timeout, const_method_thunk<K, method>, object);
280 }
281
282 template<class K, void (K::*method)(int) const>
283 static void const_method_thunk (int revents, void* arg)
284 {
285 K *obj = static_cast<K *>(arg);
286 (obj->*method) (revents);
287 }
288
289 // simple method callback
290 template<class K, void (K::*method)()> 280 template<class K, void (K::*method)()>
291 void once (int fd, int events, tstamp timeout, K *object) throw () 281 void once (int fd, int events, tstamp timeout, K *object) throw ()
292 { 282 {
293 once (fd, events, timeout, method_noargs_thunk<K, method>, object); 283 once (fd, events, timeout, method_noargs_thunk<K, method>, object);
294 } 284 }
295 285
296 template<class K, void (K::*method)()> 286 template<class K, void (K::*method)()>
297 static void method_noargs_thunk (int revents, void* arg) 287 static void method_noargs_thunk (int revents, void *arg)
298 { 288 {
299 K *obj = static_cast<K *>(arg); 289 static_cast<K *>(arg)->*method
300 (obj->*method) (); 290 ();
301 } 291 }
302 292
303 // simpler function callback 293 // simpler function callback
304 template<void (*cb)(int)> 294 template<void (*cb)(int)>
305 void once (int fd, int events, tstamp timeout) throw () 295 void once (int fd, int events, tstamp timeout) throw ()
306 { 296 {
307 once (fd, events, timeout, simpler_func_thunk<cb>); 297 once (fd, events, timeout, simpler_func_thunk<cb>);
308 } 298 }
309 299
310 template<void (*cb)(int)> 300 template<void (*cb)(int)>
311 static void simpler_func_thunk (int revents, void* arg) 301 static void simpler_func_thunk (int revents, void *arg)
312 { 302 {
303 (*cb)
313 (*cb) (revents); 304 (revents);
314 } 305 }
315 306
316 // simplest function callback 307 // simplest function callback
317 template<void (*cb)()> 308 template<void (*cb)()>
318 void once (int fd, int events, tstamp timeout) throw () 309 void once (int fd, int events, tstamp timeout) throw ()
319 { 310 {
320 once (fd, events, timeout, simplest_func_thunk<cb>); 311 once (fd, events, timeout, simplest_func_thunk<cb>);
321 } 312 }
322 313
323 template<void (*cb)()> 314 template<void (*cb)()>
324 static void simplest_func_thunk (int revents, void* arg) 315 static void simplest_func_thunk (int revents, void *arg)
325 { 316 {
326 (*cb) (); 317 (*cb)
318 ();
327 } 319 }
328 320
329 void feed_fd_event (int fd, int revents) throw () 321 void feed_fd_event (int fd, int revents) throw ()
330 { 322 {
331 ev_feed_fd_event (EV_AX_ fd, revents); 323 ev_feed_fd_event (EV_AX_ fd, revents);
421 struct base : ev_watcher 413 struct base : ev_watcher
422 { 414 {
423 #if EV_MULTIPLICITY 415 #if EV_MULTIPLICITY
424 EV_PX; 416 EV_PX;
425 417
426 void set (EV_PX) throw () 418 void set (EV_P) throw ()
427 { 419 {
428 this->EV_A = EV_A; 420 this->EV_A = EV_A;
429 } 421 }
430 #endif 422 #endif
431 423
435 #endif 427 #endif
436 { 428 {
437 ev_init (this, 0); 429 ev_init (this, 0);
438 } 430 }
439 431
440 void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () 432 void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw ()
441 { 433 {
442 this->data = data; 434 this->data = (void *)data;
443 ev_set_cb (static_cast<ev_watcher *>(this), cb); 435 ev_set_cb (static_cast<ev_watcher *>(this), cb);
436 }
437
438 // function callback
439 template<void (*function)(watcher &w, int)>
440 void set (void *data = 0) throw ()
441 {
442 set_ (data, function_thunk<function>);
443 }
444
445 template<void (*function)(watcher &w, int)>
446 static void function_thunk (EV_P_ ev_watcher *w, int revents)
447 {
448 function
449 (*static_cast<watcher *>(w), revents);
444 } 450 }
445 451
446 // method callback 452 // method callback
447 template<class K, void (K::*method)(watcher &w, int)> 453 template<class K, void (K::*method)(watcher &w, int)>
448 void set (K *object) throw () 454 void set (K *object) throw ()
449 { 455 {
450 set_ (object, method_thunk<K, method>); 456 set_ (object, method_thunk<K, method>);
451 } 457 }
452 458
459 // default method == operator ()
460 template<class K>
461 void set (K *object) throw ()
462 {
463 set_ (object, method_thunk<K, &K::operator ()>);
464 }
465
453 template<class K, void (K::*method)(watcher &w, int)> 466 template<class K, void (K::*method)(watcher &w, int)>
454 static void method_thunk (EV_P_ ev_watcher *w, int revents) 467 static void method_thunk (EV_P_ ev_watcher *w, int revents)
455 { 468 {
456 K *obj = static_cast<K *>(w->data); 469 (static_cast<K *>(w->data)->*method)
457 (obj->*method) (*static_cast<watcher *>(w), revents);
458 }
459
460 // const method callback
461 template<class K, void (K::*method)(watcher &w, int) const>
462 void set (const K *object) throw ()
463 {
464 set_ (object, const_method_thunk<K, method>);
465 }
466
467 template<class K, void (K::*method)(watcher &w, int) const>
468 static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
469 {
470 K *obj = static_cast<K *>(w->data);
471 (static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
472 }
473
474 // function callback
475 template<void (*function)(watcher &w, int)>
476 void set (void *data = 0) throw ()
477 {
478 set_ (data, function_thunk<function>);
479 }
480
481 template<void (*function)(watcher &w, int)>
482 static void function_thunk (EV_P_ ev_watcher *w, int revents)
483 {
484 function (*static_cast<watcher *>(w), revents); 470 (*static_cast<watcher *>(w), revents);
485 } 471 }
486 472
487 // simple callback 473 // no-argument callback
488 template<class K, void (K::*method)()> 474 template<class K, void (K::*method)()>
489 void set (K *object) throw () 475 void set (K *object) throw ()
490 { 476 {
491 set_ (object, method_noargs_thunk<K, method>); 477 set_ (object, method_noargs_thunk<K, method>);
492 } 478 }
493 479
494 template<class K, void (K::*method)()> 480 template<class K, void (K::*method)()>
495 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) 481 static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
496 { 482 {
497 K *obj = static_cast<K *>(w->data); 483 static_cast<K *>(w->data)->*method
498 (obj->*method) (); 484 ();
499 } 485 }
500 486
501 void operator ()(int events = EV_UNDEF) 487 void operator ()(int events = EV_UNDEF)
502 { 488 {
489 return
503 return ev_cb (static_cast<ev_watcher *>(this)) 490 ev_cb (static_cast<ev_watcher *>(this))
504 (static_cast<ev_watcher *>(this), events); 491 (static_cast<ev_watcher *>(this), events);
505 } 492 }
506 493
507 bool is_active () const throw () 494 bool is_active () const throw ()
508 { 495 {
509 return ev_is_active (static_cast<const ev_watcher *>(this)); 496 return ev_is_active (static_cast<const ev_watcher *>(this));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines