On 4 November 2010 14:34, Robert Bradshaw <[email protected]> wrote:
> On Wed, Nov 3, 2010 at 8:24 PM, Brett Calcott <[email protected]> wrote:
>> On 3 November 2010 19:24, Dag Sverre Seljebotn
>> <[email protected]> wrote:
>>> cdef class A:
>>>     cdef Vector obj
>>>     x = delegate_property(obj, 'x')
>>>
>>> or similar, without throwing in new syntax. But it may be too late and I
>>> don't care too much. Remember that "x = property(...)" is already in Python.
>>>
>>
>> This looks like an interesting option, especially if it was possible
>> to write your own reusable "xxxx_property" functions that did "the
>> right thing" for the particular object/library being wrapped. This
>> would remove a lot boilerplate code that is normally cut and pasted
>> for setter/getter functions. So, in a case where the C++ members are
>> private, but access is provided via camelcase set/get functions,
>> instead of
>>
>> property value:
>>  def __get__(self):
>>    return self.obj.getValue()
>>  def __set__(self, int x):
>>    self.obj.setValue(x)
>>
>> We could write:
>> x = camelcase_delegate_property(self.obj, 'value')
>
> The one thing that I don't like about this is putting the attribute in
> a String.
>

Is this possible?
x = member_property(self.obj.x)
y = getset_property(self.obj.getY, self.obj.setY)
(the names of these need work I agree)

But I take it that the general idea would be able to roll your own
when there was some repetitive thing you needed to do, so up to you
what you passed.

For example, the obj pointer in some of the classes I am currently
wrapping can sometimes be set to NULL. So in many cases the property
access needs to check that first, and raise an exception. If I could
write my own getset_with_check_property(...), that would be very cool.

Brett
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to