Używanie Boost Python & std :: shared_ptr
Staram się, aby Boost Python ładnie grał ze std :: shared_ptr. Obecnie otrzymuję ten błąd:
Traceback (most recent call last):
File "test.py", line 13, in <module>
comp.place_annotation(circle.centre())
TypeError: No to_python (by-value) converter found for C++ type: std::shared_ptr<cgl::Anchor>
Z wywołania circle.centre (), które zwraca std :: shared_ptr. Mogłem zmienić każdy std :: shared_ptr na boost :: shared_ptr (z którym ładnie gra Boost Python), ale ilość kodu do zmiany w dość znacznym stopniu i chciałbym użyć standardowej biblioteki.
Metoda okręgu jest opisana w ten sposób:
const std::shared_ptr<Anchor> centre() const
{
return Centre;
}
Klasa kotwicy taka jak ta:
class Anchor
{
Point Where;
Annotation* Parent;
public:
Anchor(Annotation* parent) :
Parent(parent)
{
// Do nothing.
}
void update(const Renderer& renderer)
{
if(Parent)
{
Parent->update(renderer);
}
}
void set(Point point)
{
Where = point;
}
Point where() const
{
return Where;
}
};
A odpowiedni kod Pythona Boost to:
class_<Circle, bases<Annotation> >("Circle", init<float>())
.def("radius", &Circle::radius)
.def("set_radius", &Circle::set_radius)
.def("diameter", &Circle::diameter)
.def("top_left", &Circle::top_left)
.def("centre", &Circle::centre);
// The anchor base class.
class_<Anchor, boost::noncopyable>("Anchor", no_init)
.def("where", &Anchor::where);
Używam Boost 1.48.0. Jakieś pomysły?