X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/a4abdd1b14e94e79de614c7ea5a7fa754725b988..69279317e8626dfa1b0d6719ac4e0d68d525645b:/ev%20%20.h/software/libev.git/blobdiff_plain/a4abdd1b14e94e79de614c7ea5a7fa754725b988..69279317e8626dfa1b0d6719ac4e0d68d525645b:/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); } };