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