[C++-sig] Re: Static, again...

Mike Rovner mike at bindkey.com
Fri Nov 15 02:43:32 CET 2002


"Hugo van der Merwe" <hugo at adept.co.za> wrote in message
news:20021114053940.GB16542 at vervet.localnet...
> On Wed, Nov 13, 2002 at 08:19:53AM -0500, David Abrahams wrote:
> > Hugo van der Merwe <hugo at adept.co.za> writes:
> >
> > Yes, but I'll leave it as an "exercise for the reader". Properties are
> > a Python 2.2 thing, not a Boost.Python feature. Try it in pure
> > Python. If you can get that to work, you can probably get it to work
> > in Boost.Python. Hint: you'll need a proxy class.

If I understand correctly
Pythons
  x.a[3]=1
will go through
__setitem__(__getattr__(x,"a"), 3, 1)

If so, it shall be easy (untested):

struct proxy {
  GetItem();
  SetItem():
};
struct X {
  proxy a;
}

class_<proxy>("proxy")
  .def("__getitem__", &proxy::GetItem)
  .def("__setitem__", &proxy::SetItem)
;

class_<X>("X")
  .add_property("a", &X::a)
;

Right?








More information about the Cplusplus-sig mailing list