|
Boost : |
From: Alcides Viamontes Esquivel (alve_at_[hidden])
Date: 2008-02-14 21:29:21
Hello all.
I would like to know if there's a boost library for solving this
problem, or if not, if it would be of general interest one.
Suppose you have a function in an external library that you want to use,
and it have this prototype:
...
/* mad_library.h
*/
/* external library function prototype */
double qk15( double(*f)(double), double a, double b);
(this example mimics QUADPACK, a great and wonderful library for
numerical integration)
If you want to have a (good) chance of using qk15 with a reentrant
function, then the correct prototype would be, at least
...
double qk15( double(*f)(double, void*), double a, double b,
void* params);
...
which is something that for example gsl
(http://www.gnu.org/software/gsl/ ) does. But that's not the case and
modifying qk15 is out of the question.
So, the "solution" library I'm asking for should be a C++ header library
that would, for example, bring this interface to the user:
...
#include <mad_library.h>
// Hypothetical library
#include <boost/enable_reentrant.hpp>
// client functor supplied by the user, to be used in some
// way with 'qk15'
struct any_functor{
...
double operator()(double x)
...
};
...
// an instance of the functor
any_functor cpp_f;
...
// first parameter is the legacy function, following parameter
// types are deduced from the prototype of qk15 (if
// possible), being each one of the same original type that
// qk15 requires but changing raw function pointers by generic
// functors (automatic type replacement or user-guided).
boost::enable_reentrant(qk15, cpp_f, a, b);
// As a postcondition to this call, function qk15 should
// be called once with a function pointer to something that
// ensures that operator() on 'any_functor' instance get's
// called with the corresponding 'this'.
If I'm missing something terrible obvious please signal it to me. I
think enable_reentrant can be implemented in at least one (almost)
portable way, using a stack in thread local storage. Boost.Thread
already give access to such feature in a satisfactory way.
__________________________________________________________________
Servicio de Correos del Grupo de Redes. UCLV
- Universidad 2008 del 11 al 15 de febrero del 2008.
Palacio de Convenciones. La Habana. Cuba. http: //www.universidad2008.cu
- II Taller internacional -Virtualización en la Educación Superior-, del 11 al 15 de febrero de 2008
Palacio de Convenciones. La Habana, Cuba. http://virtual-es.uclv.edu.cu
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk