From c80a9f5d507071c8ca31b8134f2a1662f306ef28 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Dec 2008 15:23:44 +0000 Subject: *** empty log message *** --- Changes | 3 ++ ev++.h | 124 +++++++++++++++++++++++++++------------------------------------- ev.pod | 30 ++++++++++++++++ 3 files changed, 85 insertions(+), 72 deletions(-) diff --git a/Changes b/Changes index 7e7e8a3..bcb41f4 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,9 @@ Revision history for libev, a high-performance and full-featured event loop. - assume negative return values != -1 signals success of port_getn (http://cvs.epicsol.org/cgi/viewcvs.cgi/epic5/source/newio.c?rev=1.52) (no known failure reports, but it doesn't hurt). + - EXPERIMENTAL: default the method to operator () in ev++.h, + to make it nicer to use functors (requested by Benedek László). + - fixed const object callbacks in ev++.h. 3.49 Wed Nov 19 11:26:53 CET 2008 - ev_stat watchers will now use inotify as a mere hint on diff --git a/ev++.h b/ev++.h index b461f98..f1b4c6f 100644 --- a/ev++.h +++ b/ev++.h @@ -162,24 +162,14 @@ namespace ev { } #if EV_MULTIPLICITY - bool operator == (struct ev_loop *other) const throw () + bool operator == (const EV_P) const throw () { - return this->EV_AX == other; + return this->EV_AX == EV_A; } - bool operator != (struct ev_loop *other) const throw () + bool operator != (const EV_P) const throw () { - return ! (*this == other); - } - - bool operator == (const struct ev_loop *other) const throw () - { - return this->EV_AX == other; - } - - bool operator != (const struct ev_loop *other) const throw () - { - return (*this == other); + return (*this == EV_A); } operator struct ev_loop * () const throw () @@ -253,7 +243,7 @@ namespace ev { } // function callback - void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void* arg = 0) throw () + void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) throw () { ev_once (EV_AX_ fd, events, timeout, cb, arg); } @@ -265,28 +255,21 @@ namespace ev { once (fd, events, timeout, method_thunk, object); } - template - static void method_thunk (int revents, void* arg) - { - K *obj = static_cast(arg); - (obj->*method) (revents); - } - - // const method callback - template - void once (int fd, int events, tstamp timeout, const K *object) throw () + // default method == operator () + template + void once (int fd, int events, tstamp timeout, K *object) throw () { - once (fd, events, timeout, const_method_thunk, object); + once (fd, events, timeout, method_thunk, object); } - template - static void const_method_thunk (int revents, void* arg) + template + static void method_thunk (int revents, void *arg) { - K *obj = static_cast(arg); - (obj->*method) (revents); + static_cast(arg)->*method + (revents); } - // simple method callback + // no-argument method callback template void once (int fd, int events, tstamp timeout, K *object) throw () { @@ -294,10 +277,10 @@ namespace ev { } template - static void method_noargs_thunk (int revents, void* arg) + static void method_noargs_thunk (int revents, void *arg) { - K *obj = static_cast(arg); - (obj->*method) (); + static_cast(arg)->*method + (); } // simpler function callback @@ -308,9 +291,10 @@ namespace ev { } template - static void simpler_func_thunk (int revents, void* arg) + static void simpler_func_thunk (int revents, void *arg) { - (*cb) (revents); + (*cb) + (revents); } // simplest function callback @@ -321,9 +305,10 @@ namespace ev { } template - static void simplest_func_thunk (int revents, void* arg) + static void simplest_func_thunk (int revents, void *arg) { - (*cb) (); + (*cb) + (); } void feed_fd_event (int fd, int revents) throw () @@ -423,7 +408,7 @@ namespace ev { #if EV_MULTIPLICITY EV_PX; - void set (EV_PX) throw () + void set (EV_P) throw () { this->EV_A = EV_A; } @@ -437,54 +422,48 @@ namespace ev { ev_init (this, 0); } - void set_ (void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () + void set_ (const void *data, void (*cb)(EV_P_ ev_watcher *w, int revents)) throw () { - this->data = data; + this->data = (void *)data; ev_set_cb (static_cast(this), cb); } - // method callback - template - void set (K *object) throw () - { - set_ (object, method_thunk); - } - - template - static void method_thunk (EV_P_ ev_watcher *w, int revents) + // function callback + template + void set (void *data = 0) throw () { - K *obj = static_cast(w->data); - (obj->*method) (*static_cast(w), revents); + set_ (data, function_thunk); } - // const method callback - template - void set (const K *object) throw () + template + static void function_thunk (EV_P_ ev_watcher *w, int revents) { - set_ (object, const_method_thunk); + function + (*static_cast(w), revents); } - template - static void const_method_thunk (EV_P_ ev_watcher *w, int revents) + // method callback + template + void set (K *object) throw () { - K *obj = static_cast(w->data); - (static_cast(w->data)->*method) (*static_cast(w), revents); + set_ (object, method_thunk); } - // function callback - template - void set (void *data = 0) throw () + // default method == operator () + template + void set (K *object) throw () { - set_ (data, function_thunk); + set_ (object, method_thunk); } - template - static void function_thunk (EV_P_ ev_watcher *w, int revents) + template + static void method_thunk (EV_P_ ev_watcher *w, int revents) { - function (*static_cast(w), revents); + (static_cast(w->data)->*method) + (*static_cast(w), revents); } - // simple callback + // no-argument callback template void set (K *object) throw () { @@ -494,14 +473,15 @@ namespace ev { template static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents) { - K *obj = static_cast(w->data); - (obj->*method) (); + static_cast(w->data)->*method + (); } void operator ()(int events = EV_UNDEF) { - return ev_cb (static_cast(this)) - (static_cast(this), events); + return + ev_cb (static_cast(this)) + (static_cast(this), events); } bool is_active () const throw () diff --git a/ev.pod b/ev.pod index 23942c0..a6f6854 100644 --- a/ev.pod +++ b/ev.pod @@ -2893,6 +2893,36 @@ Example: simple class declaration and watcher initialisation ev::io iow; iow.set (&obj); +=item w->set (object *) + +This is an B feature that might go away in a future version. + +This is a variation of a method callback - leaving out the method to call +will default the method to C, which makes it possible to use +functor objects without having to manually specify the C all +the time. Incidentally, you can then also leave out the template argument +list. + +The C method prototype must be C. + +See the method-C above for more details. + +Example: use a functor object as callback. + + struct myfunctor + { + void operator() (ev::io &w, int revents) + { + ... + } + } + + myfunctor f; + + ev::io w; + w.set (&f); + =item w->set (void *data = 0) Also sets a callback, but uses a static method or plain function as -- cgit v1.2.3