2009/8/18 OvermindDL1
On Mon, Aug 17, 2009 at 10:53 AM, Igor Mikushkin
wrote: Hello Boosters,
I'm trying to use Boost Python that way:
template<class Key> struct Node { Node(Key key): key(key) {} Node* parent; Node* left; Node* right; Key key; };
.....
BOOST_PYTHON_MODULE(tree) { class_<Node>("Node", init<int>()) .def_readwrite("parent", &Node::parent) .def_readwrite("left", &Node::left) .def_readwrite("right", &Node::right) .def_readwrite("key", &Node::key); };
But then I can't use parent, left and right properties in Python code. Is there a way to convert these raw pointers to common object reference in Python?
I do not know what the 'proper' way is, but any time I had that issue I either changed all Node* to shared_ptr<Node> if I had access to change the class, or I added wrapper set/get functions if I did not.
Thanks a lot. I wrapped all my pointers with shared_ptr and it works well. I've also found that I can wrap raw pointers with opaque<Node>. But my null pointers are still converted to valid Python's objects. What I expect is that they should be converted to None. Is it possible to set up such behavior with set/get functions or with opaque<T>? Thanks, Igor