[C++-sig] Re: def() vs. add_property()
David Abrahams
dave at boost-consulting.com
Wed Jul 16 18:09:59 CEST 2003
Stefan Seefeld <stefan.seefeld at orthosoft.ca> writes:
> hi there,
>
> I'v got a class that holds a reference to an external
> object, which is accessible through a simple method:
>
> class Origin {};
>
> class Event
> {
> public:
> Event(const Origin *o) : my_origin(o) {}
> const Origin *GetOrigin() { return my_origin;}
> private:
> const Origin *my_origin;
> };
>
> I can expose the 'Event' and 'Origin' classes, as well
> as &Event::GetOrigin, to python.
> However, I'd rather like to make the origin accessible
> as a (read-only) property. The problem is that the
> 'add_property' method doesn't take a return value policy,
> so I have no way of telling python how to wrap the pointer.
>
> What is the suggested way to do that ?
See make_getter/make_setter. You can pass their results to
add_property.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list