c++ api for libeio

Marc Lehmann schmorp at schmorp.de
Tue Jun 3 10:56:42 CEST 2008

As I said, I probably won't do it, but here is a wrapper that converts
the callback/data combination into a object */method * combo:

This class can be used for all wrapper functions (but only for non-const
objects, due to the horribly useless const semantics in C++, you need a
separate set of wrappers for const objects):

   struct eio_thunk
     template<class K, void (K::*method)(eio_req *)>
     static int thunk (eio_req *req)
       K *obj = static_cast<K *>(req->data);
       (obj->*method) (req);

And this is a single wrapper, here for eio_unlink:

   template<class K, void (K::*method)(eio_req *)>
   eio_req *eio_unlink (const char *path, K *object, int pri = EIO_PRI_DEFAULT)
     eio_unlink (path, pri, eio_thunk::thunk<K, method>, (void *)object);

It could be used like this:

   struct CLASS {
     void METHOD(eio_req *);
   CLASS object;
   eio_unlink<CLASS, &CLASS::METHOD> ("/lib/libc.so.6", &object);

If somebody wants to provide a eio++.h file or which ahs these that is fine with me.

I fact, these could easily be added to the eio.h header file that already
exists, too.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg at goof.com
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list