[C++-sig] exposing properties with getters and setters

David Abrahams david.abrahams at rcn.com
Wed Jun 26 02:07:59 CEST 2002


----- Original Message -----
From: "Achim Domma" <achim.domma at syynx.de>
To: "C++-Sig at Python. Org" <c++-sig at python.org>
Sent: Sunday, June 23, 2002 12:37 PM
Subject: [C++-sig] exposing properties with getters and setters


> Hi,
>
> what is the correct way to expose properties in boost.python V2, if I
have a
> function pair for getting and setting the property? Can/Should I use
> '__setattr__propertyname'

No, that's a v1 idiom

> or something else?

Yes, something else.

> I tried to use add_property,
> but it expects two handles, not functionpointers. The only example I
found
> was iterator.cpp, but I didn't understand it.

You can use make_function() to create a callable Python object from a
function or member function pointer, so:

    .add_property(
        handle<>(make_function(my_get_func))
       , handle<>(make_function(my_set_func))))







More information about the Cplusplus-sig mailing list