[C++-sig] Pointer to existing Python object
Andreas Beyer
beyer at imb-jena.de
Thu Apr 14 19:02:05 CEST 2005
Hi,
I just want to bring this issue back on the table. I still didn't get a
brilliant idea how to solve it.
So far, I see only this option:
- Wrap B, in particular wrap B.get().
- In get() create the actual python object, like:
python::object py_a(B::get());
- Store those objects in a map.
- When B_wrap.get() gets called again, check if a python object already
exists and return it.
However, in my real-world application I had to wrap quite a lot of
methods returning As. I also have methods returning vectors of A_ptr,
which makes it even more enoying. (I would have to wrap the
vector<A_ptr>, too.)
What is this has_back_reference doing? Is that somehow related to my
problem? (I regret that I don't really understand what it is doing, as I
don't know what a "predicate metafunction" is.)
Just adopting the example at
http://www.boost.org/libs/python/doc/v2/has_back_reference.html is not
really a solution, because my instances of A are created inside the C++
code (by factory methods in class B). I would have to be very intrusive
and make the actual class B aware of Python/boost::python for adopting
the above solution.
I know that boost::python is collecting the shared pointers somewhere.
Is it possible to use that mechanism somewhow for solving my problem?
Any ideas?
Thanks!!
Andreas
More information about the Cplusplus-sig
mailing list