Boost.Python: wrapping OpenSceneGraph smart pointers, again

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") ; } -- Randolph Fritz design machine group, architecture department, university of washington rfritz@u.washington.edu -or- rfritz333@gmail.com

On Tue, Oct 13, 2009 at 7:34 PM, Randolph Fritz <rfritz333@gmail.com> 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.

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@gmail.com> wrote:
On Tue, Oct 13, 2009 at 7:34 PM, Randolph Fritz <rfritz333@gmail.com> 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. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org
-- Randolph Fritz design machine group, architecture department, university of washington rfritz@u.washington.edu -or- rfritz333@gmail.com

On Mon, Oct 19, 2009 at 10:46 PM, Randolph Fritz <rfritz333@gmail.com> 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@gmail.com> wrote:
On Tue, Oct 13, 2009 at 7:34 PM, Randolph Fritz <rfritz333@gmail.com> 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?).

On 2009-10-20, OvermindDL1 <overminddl1@gmail.com> wrote:
Ooo, impressively simple. That should be added to the docs (FAQ at least?).
I've put up an improved version at the bottom of: <http://wiki.python.org/moin/boost.python/PointersAndSmartPointers> Hopefully, the next person to come along will have an easier time of it. Randolph
On Mon, Oct 19, 2009 at 10:46 PM, Randolph Fritz <rfritz333@gmail.com> 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@gmail.com> wrote:
On Tue, Oct 13, 2009 at 7:34 PM, Randolph Fritz <rfritz333@gmail.com> 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.
participants (2)
-
OvermindDL1
-
Randolph Fritz