Hi Philippe,
On Mon, 2007-05-21 at 16:57 -0500, Philippe Canal wrote:
> Hi Robert,
>
> The last time I looked there was no easy way around it (the problem is
> to pass a pointer to a member function down to a C function thus needing
> to cast it to a void* ... which is more or so illegal in C++).
>
> On the other hand we are working to revamp the dictionary back end of
> CINT. In the process we will update the dictionary format (it will
> use a C++ API) that should take care of the problem.
A suggestion: Wrap the member function call in a Functor object (a class template, deriving from some base class, say FunctorBase), and pass that down. Alexandrescrus book "Modern C++ Design" [1] has more on this. Code for this is available as the Loki project from sourceforge.net [2]. Boost.org [3] has a "function" library that looks like it could be used for this, which I think is considered for inclusion into the ISO C++ 0x standard [4 - chapter 3].
There's a lot of cool stuff in Andreis book. For example, the factory pattern could be used to substitute the (many) C functions implemented.
// Factory.h
template <T, Lock>
struct Factory : FactoryBase
{
FactoryBase& Instance() {
if (!_instance) {
_lock.Lock();
if (!_instance) _instance = new Factory<Foo>;
_lock.Unlock();
}
return _instance;
}
ObjectPtr* Create();
Result* Call(ObjectPtr* o, const std::string& fun, ...);
private:
Factory() {
BaseFactory::Register(this);
}
static Lock _lock;
static Factory<T>* _instance;
}
...
// In created dictionary for type Foo
Factory<Foo>* Factory<Foo>::_instance = new Factory<Foo>;
...
// When called upon to make a Foo object
FactoryBase& factory =
FactoryBase::Instance().GetFactory("Foo");
ObjectPtr* ptr = new ObjectPtr(factory->Create());
...
and so on.
[1] http://www.moderncppdesign.com/
[2] http://loki-lib.sourceforge.net/
Yours,
--
___ | Christian Holm Christensen
|_| | -------------------------------------------------------------
| | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91
_| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91
_| Denmark Office: (+45) 353 25 404
____| Email: cholm_at_nbi.dk Web: www.nbi.dk/~cholm
| |
Received on Wed May 23 2007 - 10:17:11 CEST
This archive was generated by hypermail 2.2.0 : Wed May 23 2007 - 17:50:02 CEST