I just wanted to add one more clarification, because actually there is
a bug in the code I posted..

For this late binding to work properly..
You really want to have something like this  (sorry, ripping from
non-test code):

template<typename T>
struct PAccessorConverter
{
    static PyObject* convert(const T &x)
    {
                if (x==0)
// i believe this is sending back None, not sure have to verify
                        return 
boost::python::incref(boost::python::object().ptr());

                return boost::python::incref(x->getPtr().ptr());
    }
};


and have that instantiated something like

#define IMPLEMENT_PYTHON_CONVERTER(x) \
        boost::python::to_python_converter<x *, PAccessorConverter<x *> >();


IMPLEMENT_PYTHON_CONVERTER(myclass)


and then when you're doing a class.def, don't return the
"existing_reference" because that will somehow cause boost python not
to look up the converter..

instead do a return by value... something like:

                        .def("getParentUser", &PCamera::getParentUser,
return_value_policy<return_by_value>())

this return_value_policy<return_by_value> queues boost python to
search the converters..
which will eventually hit the converter that uses the embedded python object..

(which allows you to have a 1-to-1 relationship between python and c++)

-tim
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to