--- libev/ev++.h 2007/11/27 11:06:03 1.10 +++ libev/ev++.h 2007/11/27 22:31:52 1.11 @@ -8,39 +8,26 @@ 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); } };