On Sun, Feb 7, 2010 at 8:57 PM, Neal Becker <ndbeck...@gmail.com> wrote:
> PyBindGen shows an example wrapping STL containers. What if I need to wrap > my own containers? Is there some generic container machinery? > Yes, there is some generic container machinery, although it currently is duplicating the STL container machinery. I hope some day to converge the two, so that STL container support code simply uses the generic code, but I have not found motivation to do it yet. The generic container support can be used to add container powers to any user class, and can be seen in the unit tests module, file tests/foo.h, classes VectorLike, VectorLike2, and MapLike. The class VectorLike registers methods for getitem/setitem/len slots (see tests/foomodulegen.py): VectorLike.add_method('get_item', 'double', [Parameter.new('size_t', 'index')], custom_name='__getitem__') VectorLike.add_method('set_item', 'void', [Parameter.new('size_t', 'index'), Parameter.new('double', 'value')], custom_name='__setitem__') VectorLike.add_method('get_len', 'size_t', [], custom_name='__len__') The class VectorLike2 instead of the above slots defines begin/end methods and uses iterators (see tests/foomodulegen_common.py). The tp_iter slot is defined: VectorLike2.add_container_traits(ReturnValue.new('double'), begin_method='Begin', end_method='End', iterator_type='Iterator') The class MapLike implements the "mapping protocol": MapLike.add_container_traits((ReturnValue.new('int'), ReturnValue.new('double')), begin_method='Begin', end_method='End', iterator_type='Iterator', is_mapping=True) I'm sorry for the lack of examples and documentation. Anyway, I hope this helps. Regards. -- Gustavo J. A. M. Carneiro INESC Porto, UTM, WiN, http://win.inescporto.pt/gjc "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