[C++-sig] weave plus boost?

Martin Casado casado2 at llnl.gov
Mon Jan 21 20:40:29 CET 2002


>
> > working prototype and it was.. if nothing else.. neat.
>
> Sounds cool, but if you're working from the Python side anyway, wouldn't
> you want std::vector<generalized_python_object> so you didn't have to pay
> to convert std::string to/from Python strings at ever access?
>
> -Dave
>

The point, originally, was not to create a templated class from the python
side but to be able to easily wrap existing templated c++ classes without 
having to
create seperate "thin" classes for each instantiation.

If I wanted to wrap a pre-existing class

template <typename type>
class Foo{..};


I though it would be interesting to be able to create instances of foo
at runtime by passing in the typename of the instance

f1 = Foo("Goo")
f2 = Foo("std::string")
f3 = Foo("GeneralizedPythonObject")
etc...

The classes I have in mind to be wrapped were not created to be templated
over a generalized python object.

Of course to do this you would have to compile the instantiation on the fly,
and I think it would be highly error prone (read dangerous to use in a
production environment), but with caching out the instances the performance
may be manageable and it could make for a neat project.

The process for doing this could be pretty complicated, for example on 
AIX you need full closure to create a shared library, therefore to
compile foo_type_inst.so you would need to link it with the export files
of all libraries whose symbols it uses (blech!).  

The function of the wrapper code is pretty straightforward, 
instead of getting a type Foo() you get a factory creation function named 
Foo()
that pops out instances of class Foo (much like most pre-python 2.2 wrappers).
The instantiations, once created, are cached (keyed by type) in the creation
function.

Really, you only need to instantiate a type once, and it will persist as a
shared object on disk, so that subsequent runs can check to see if an 
instance exists, by first checking cache, then disk... and finally creating
the instance.


     ~~m




More information about the Cplusplus-sig mailing list