[C++-sig] Re: def() vs. add_property()

David Abrahams dave at boost-consulting.com
Wed Jul 16 22:55:55 CEST 2003


Stefan Seefeld <seefeld at sympatico.ca> writes:

> David Abrahams wrote:
>> 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.
>> 
>
> make_getter seems to expect a pointer-to-member, while I
> want a pointer-to-member-function. Am I missing something ?

http://www.boost.org/libs/python/doc/v2/make_function.html?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list