2008/11/3 Stefan Seefeld <[EMAIL PROTECTED]> > Alan Baljeu wrote: > >> I just read the tutorial page on pybindgen, but it doesn't talk about >> reference types. 99% of my C++ code involves passing around things like >> foo&, so this is significant to me. How is it done? >> >> > > If you need fine-grained control about argument passing policies (as soon > as you need reference-semantics, you have to be careful about lifetime > management, for example), you are better off writing boost.python bindings > manually, I would suggest.
I know that you're thinking about the custodian_and_ward policy of boost.python, but pybindgen also supports it. For example: class SomeObject { [...] Foobar* get_foobar_with_self_as_custodian (); Foobar* get_foobar_with_other_as_custodian (const SomeObject *other); void set_foobar_with_self_as_custodian (Foobar *foobar); }; Is wrapped by pybindgen code: SomeObject = mod.add_class('SomeObject', allow_subclassing=True) [...] SomeObject.add_method('get_foobar_with_self_as_custodian', retval('Foobar*', custodian=0), []) SomeObject.add_method('get_foobar_with_other_as_custodian', retval('Foobar*', custodian=1), [param('SomeObject*', 'other', transfer_ownership=False)]) SomeObject.add_method('set_foobar_with_self_as_custodian', retval('void'), [param('Foobar*', 'foobar', custodian=0)]) [excerpt from the pybindgen unit tests] Although I personally dislike this sort of practice; I would hate working with APIs this complicated even in C++. -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig