How to add a reference of one python object to another?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
mlampert
Posts: 1460
Joined: Fri Sep 16, 2016 9:28 pm

How to add a reference of one python object to another?

Postby mlampert » Wed Feb 05, 2020 5:44 am

I have a class in C++, let's call it A. A has a member function which returns objects of class B. 'thing is, B has a pointer to A.

I know how to wrap A and all its members into a python class, APy - and I know how to wrap B into BPy. But what I can't figure out is how to add a reference from BPy to APy - in order to make sure A exists until all APy and BPy are destroyed.

I thought about implementing A and B to both use a boost::shared_ptr to the actual data object, but somehow I have the feeling there should be a simpler way. If somebody could point me in the right direction, that would be great!

Thanks a lot