[C++-sig] Re: wrapping complex attributes

David Abrahams dave at boost-consulting.com
Wed Nov 13 23:33:02 CET 2002


"Mike Rovner" <mike at bindkey.com> writes:

> David,
>
> Thanks for your invaluable help. You fast answers greatly smooth BPL leaning
> curve.
>
> As you suggested many times before I first experimented with pure Python
> code first.
>
> So I have two working variants of what I want:
>
> 1) with implicit self
>
> class cTcn:
>   # suppose it's some c++ member functions
>   def getX(self,n): print 'getX(%s)'%n
>   def delX(self,n): print 'delX(%s)'%n
>   def newX(self,n): print 'newX(%s)'%n
>   def getXall(self):print '[getXall()]'
>
>   def getY(self,n): print 'getY(%s)'%n
>   def delY(self,n): print 'delY(%s)'%n
>   def newY(self,n): print 'newY(%s)'%n
>   def getYall(self):print '[getYall()]'
>
>   def getZ(self,n): print 'getZ(%s)'%n
>   def delZ(self,n): print 'delZ(%s)'%n
>   def newZ(self,n): print 'newZ(%s)'%n
>   def getZall(self):print '[getZall()]'
>
>   # now I want 3 more members
>   def __init__(self):
>     self.x=tcn_helper(self.getX, self.delX, self.newX, self.getXall)
>     self.y=tcn_helper(self.getY, self.delY, self.newY, self.getYall)
>     self.z=tcn_helper(self.getZ, self.delZ, self.newZ, self.getZall)

In order for the Pure Python code to help you with the C++ version,
you need to use the same idioms. You'll need x,y, and z to be
properties on the class instead of attributes on the instance. Make
them into properties and try again. See

   http://www.python.org/doc/current/whatsnew/sect-rellinks.html#SECTION000340000000000000000

If you need a description of properties

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list