From 69279317e8626dfa1b0d6719ac4e0d68d525645b Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Nov 2007 22:31:52 +0000 Subject: great idea. radically simplify the method callbacks --- ev++.h | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'ev++.h') diff --git a/ev++.h b/ev++.h index f335926..5133af0 100644 --- a/ev++.h +++ b/ev++.h @@ -8,39 +8,26 @@ namespace ev { template class callback { - struct object { }; + struct klass; // it is vital that this is never defined - void *obj; - void (object::*meth)(watcher &, int); - - /* a proxy is a kind of recipe on how to call a specific class method */ - struct proxy_base { - virtual void call (void *obj, void (object::*meth)(watcher &, int), watcher &w, int) const = 0; - }; - template - struct proxy : proxy_base { - virtual void call (void *obj, void (object::*meth)(watcher &, int), watcher &w, int e) const - { - ((reinterpret_cast(obj)) ->* (reinterpret_cast(meth))) - (w, e); - } - }; - - proxy_base *prxy; + klass *o; + void (klass::*m)(watcher &, int); public: template explicit callback (O1 *object, void (O2::*method)(watcher &, int)) { - static proxy p; - obj = reinterpret_cast(object); - meth = reinterpret_cast(method); - prxy = &p; + o = reinterpret_cast(object); + m = reinterpret_cast(method); } - void call (watcher *w, int e) const + // this works because a standards-compliant C++ compiler + // basically can't help it: it doesn't have the knowledge + // required to miscompile (klass is not defined anywhere + // and nothing is known about the constructor arguments) :) + void call (watcher *w, int revents) { - return prxy->call (obj, meth, *w, e); + (o->*m) (*w, revents); } }; -- cgit v1.2.3