If you have raw pointer to some C++ object mapped into Python then you can make another Python object around original pointer using adapter in such way:
template<typename PtrT>
struct PtrAdapter {
auto& get(PtrT ptr) { return *ptr; }
};
Then make it's Python mapped type and allow implicit conversion:
class_<Cluster<LinksT>*, noncopyable>(typpedName<LinksT>("ClusterPtr", true, true)
, "Raw hierarchy cluster pointer\n")
.def("__call__", &PtrAdapter<Cluster<LinksT>*>::get,
return_internal_reference<>(),
"referenced cluster")
;
register_ptr_to_python<Cluster<LinksT>*>();
Note that referenced type (in this case Cluster<LinksT>
) also must be mapped to the appropriate Python object.
Then for such C++ code:
Cluster<LinksT>* cl = clusters.head();
process(cl);
Id cid = cl->id();
You can use similar Python code:
cl = clusters.head()
process(cl)
cid = cl.id()
But if you don't need some special processing of pointer to C++ object then it's obviously better to use boost::python::ptr
.
Also you should consider alternatives mentioned here: boost::python: howto call a function that expects a pointer?