*** empty log message ***

master
Marc Alexander Lehmann 15 years ago
parent 4bec560b11
commit 5e60624df6

@ -8,6 +8,8 @@ Revision history for libev, a high-performance and full-featured event loop.
- 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.
- replaced loop_ref argument of watcher.set (loop) by a direct
ev_loop * in ev++.h, to avoid clashes with functor patch.
3.49 Wed Nov 19 11:26:53 CET 2008
- ev_stat watchers will now use inotify as a mere hint on

124
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<K, method>, object);
}
template<class K, void (K::*method)(int)>
static void method_thunk (int revents, void* arg)
{
K *obj = static_cast<K *>(arg);
(obj->*method) (revents);
}
// const method callback
template<class K, void (K::*method)(int) const>
void once (int fd, int events, tstamp timeout, const K *object) throw ()
// default method == operator ()
template<class K>
void once (int fd, int events, tstamp timeout, K *object) throw ()
{
once (fd, events, timeout, const_method_thunk<K, method>, object);
once (fd, events, timeout, method_thunk<K, &K::operator ()>, object);
}
template<class K, void (K::*method)(int) const>
static void const_method_thunk (int revents, void* arg)
template<class K, void (K::*method)(int)>
static void method_thunk (int revents, void *arg)
{
K *obj = static_cast<K *>(arg);
(obj->*method) (revents);
static_cast<K *>(arg)->*method
(revents);
}
// simple method callback
// no-argument method callback
template<class K, void (K::*method)()>
void once (int fd, int events, tstamp timeout, K *object) throw ()
{
@ -294,10 +277,10 @@ namespace ev {
}
template<class K, void (K::*method)()>
static void method_noargs_thunk (int revents, void* arg)
static void method_noargs_thunk (int revents, void *arg)
{
K *obj = static_cast<K *>(arg);
(obj->*method) ();
static_cast<K *>(arg)->*method
();
}
// simpler function callback
@ -308,9 +291,10 @@ namespace ev {
}
template<void (*cb)(int)>
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<void (*cb)()>
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<ev_watcher *>(this), cb);
}
// method callback
template<class K, void (K::*method)(watcher &w, int)>
void set (K *object) throw ()
{
set_ (object, method_thunk<K, method>);
}
template<class K, void (K::*method)(watcher &w, int)>
static void method_thunk (EV_P_ ev_watcher *w, int revents)
// function callback
template<void (*function)(watcher &w, int)>
void set (void *data = 0) throw ()
{
K *obj = static_cast<K *>(w->data);
(obj->*method) (*static_cast<watcher *>(w), revents);
set_ (data, function_thunk<function>);
}
// const method callback
template<class K, void (K::*method)(watcher &w, int) const>
void set (const K *object) throw ()
template<void (*function)(watcher &w, int)>
static void function_thunk (EV_P_ ev_watcher *w, int revents)
{
set_ (object, const_method_thunk<K, method>);
function
(*static_cast<watcher *>(w), revents);
}
template<class K, void (K::*method)(watcher &w, int) const>
static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
// method callback
template<class K, void (K::*method)(watcher &w, int)>
void set (K *object) throw ()
{
K *obj = static_cast<K *>(w->data);
(static_cast<K *>(w->data)->*method) (*static_cast<watcher *>(w), revents);
set_ (object, method_thunk<K, method>);
}
// function callback
template<void (*function)(watcher &w, int)>
void set (void *data = 0) throw ()
// default method == operator ()
template<class K>
void set (K *object) throw ()
{
set_ (data, function_thunk<function>);
set_ (object, method_thunk<K, &K::operator ()>);
}
template<void (*function)(watcher &w, int)>
static void function_thunk (EV_P_ ev_watcher *w, int revents)
template<class K, void (K::*method)(watcher &w, int)>
static void method_thunk (EV_P_ ev_watcher *w, int revents)
{
function (*static_cast<watcher *>(w), revents);
(static_cast<K *>(w->data)->*method)
(*static_cast<watcher *>(w), revents);
}
// simple callback
// no-argument callback
template<class K, void (K::*method)()>
void set (K *object) throw ()
{
@ -494,14 +473,15 @@ namespace ev {
template<class K, void (K::*method)()>
static void method_noargs_thunk (EV_P_ ev_watcher *w, int revents)
{
K *obj = static_cast<K *>(w->data);
(obj->*method) ();
static_cast<K *>(w->data)->*method
();
}
void operator ()(int events = EV_UNDEF)
{
return ev_cb (static_cast<ev_watcher *>(this))
(static_cast<ev_watcher *>(this), events);
return
ev_cb (static_cast<ev_watcher *>(this))
(static_cast<ev_watcher *>(this), events);
}
bool is_active () const throw ()

@ -2893,6 +2893,36 @@ Example: simple class declaration and watcher initialisation
ev::io iow;
iow.set <myclass, &myclass::io_cb> (&obj);
=item w->set (object *)
This is an B<experimental> 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<operator ()>, which makes it possible to use
functor objects without having to manually specify the C<operator ()> all
the time. Incidentally, you can then also leave out the template argument
list.
The C<operator ()> method prototype must be C<void operator ()(watcher &w,
int revents)>.
See the method-C<set> 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<function> (void *data = 0)
Also sets a callback, but uses a static method or plain function as

Loading…
Cancel
Save