|
Boost Users : |
Subject: Re: [Boost-users] [python] raw pointer data members
From: Igor Mikushkin (igor.mikushkin_at_[hidden])
Date: 2009-08-19 14:31:21
2009/8/18 OvermindDL1 <overminddl1_at_[hidden]>:
> On Mon, Aug 17, 2009 at 10:53 AM, Igor
> Mikushkin<igor.mikushkin_at_[hidden]> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net