Re: Comment on my adapter concept
I'm working on an adapter for a C plugin API.
Why? What is it good for? :)
Well it irons your shirts, feeds your kids, walks the
dog and pays the mortgage :-)
It's just a C-Style plugin system where each time a new
plugin is meant to be written a couple of function pointers
have to be initialized to NULL or a valid function pointer.
The whole code is very C++-stylish already. They have
structs mimicking a std::string and things that look
like a streambuf. So I'm covering this all under a
C++-layer.
So e.g. something like
int_plugin(*p) {
p->alloc = my_alloc;
p->free = my_free;
p->do_foo1 = NULL;
p->do_foo2 = my_do_foo2;
...
...
...
}
becomes
int_plugin<M>(*p) {
p->alloc = module_adapter<M>::alloc;
p->free = module_adapter<M>::free;
p->do_foo1 = module_adapter<M>::do_foo1;
...
...
}
Notice that the second function is module independent
"do_foo1" will become NULL whenever the module class
doesn't declare a do_foo1 method. Whereas the first
approach has to be rewritten whenever the module interface
changes. This goes down to the module_traits<M>::has_function::do_xyz
enum. In my example code these values are set explicitly, but
I already check via SFINAE if the corresponding method exists.
Hope that explains why
O.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]