I would like to expose objects wrapped in custom smart pointers in python using Boost::Python
The caveats
- existing usage of the custom smart pointer is too pervasive to economically upgrade to the boost smart pointers
- i would like to use the automatic dereferencing technique as described in several locations
The problem is that I cannot seem to get it quite right. Here's a sample code:
LegacyCode::Ptr -> legacy smart pointer code
LegacyCode::Session -> legacy object that's wrapped in the legacy smart pointer
namespace boost { namespace python
{
template <class T> T* get_pointer(LegacyCode::Ptr<T> const& p)
{
return p.get();
}
template <typename T>
struct pointee<LegacyCode::Ptr<T> >
{
typedef T type;
};
}}*
BOOST_PYTHON_MODULE(pyro)
{
using namespace boost::python;
class_<LegacyCode::Session,LegacyCode::Ptr<LegacyCode::Session>>("Session")
.def("get_type",&LegacyCode::Session::getType);
}