|
Boost Users : |
Subject: Re: [Boost-users] Boost.Python: wrapping OpenSceneGraph smart pointers, again
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-10-20 00:58:12
On Mon, Oct 19, 2009 at 10:46 PM, Randolph Fritz <rfritz333_at_[hidden]> wrote:
> It's surprisingly simple, it turns out.
>
> First, you have to tag the OSG smart pointer type, as follows:
> -------------------
> #ifndef REF_PTR_TRAIT_
> #define REF_PTR_TRAIT_
>
> #include <boost/python.hpp>
> #include <osg/ref_ptr>
>
> namespace boost {
> Â namespace python {
> Â Â template <class T> struct pointee< osg::ref_ptr<T> >
> Â Â { typedef T type; };
> Â }}
>
> #endif
> -------------------
>
> Then, in a BOOST_PYTHON_MODULE, you can write:
>
> Â class_<Node, ref_ptr<Node> >("Node", init<>())
> Â Â ;
>
> You can of course add as many of the Node class's methods as desired.
>
> Randolph
>
> On 2009-10-14, OvermindDL1 <overminddl1_at_[hidden]> wrote:
>> On Tue, Oct 13, 2009 at 7:34 PM, Randolph Fritz <rfritz333_at_[hidden]> wrote:
>>> What is wrong with the following code? Â I suspect I'm doing something
>>> silly, and I suspect the answer is obvious.
>>>
>>> Â #include <osg/Node>
>>> Â #include <osg/ref_ptr>
>>>
>>> Â #include <boost/python.hpp>
>>> Â #include <boost/python/pointee.hpp>
>>>
>>> Â using namespace osg;
>>> Â typedef ref_ptr<Node> NodePtr;
>>>
>>> Â using namespace boost::python;
>>>
>>> Â BOOST_PYTHON_MODULE(NodePtr) {
>>> Â Â class_<NodePtr, pointee<NodePtr> >("NodePtr")
>>> Â Â Â ;
>>> Â }
>>
>> Boost.Python knows Boost and TR1 smart pointers, not any others. Â If
>> you are using any others (ref_ptr in this case I gather) then you need
>> to make Boost.Python aware of it, I am not sure how, reading through
>> the code might reveal how.
Ooo, impressively simple. That should be added to the docs (FAQ at least?).
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