Re: [pygccxml-development] indexing suite
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2006-10-13 18:38:10
|
On 10/13/06, Neal Becker <ndb...@gm...> wrote: > I want to try out pyplusplus to wrap boost::ublas::vector (and maybe > eventually matrix). > > I was reading about indexing suite 2. It sounds interesting. > > I read pygccxml/pyplusplus_dev/docs/documentation/containers.rest. It talks > about how py++ will automatically recognize stl containers. > > Can I use it for my own containers? How? You will have to understand few implementation details. 1. How to recognize that the class is container? 1. pygccxml/declarations/container_traits.py file defines functionality that allows Py++ to recognize std containers. You have to implement class with the same interface 2. pygccxml/declarations/__init__.py defines variable - all_container_traits. Add instance of your class to it. This will allow Py++ to work with your container as it was one of the built-in containers 2. By default Py++ uses the indexing suite Boost.Python comes with, you will have to switch to next version: mb = module_builder_t( ..., indexing_suite_version=2 ) 3. How to teach Py++ generate the right code? 1. pyplusplus/module_creator/creator.py contains definition of INDEXING_SUITE_2_CONTAINERS variable. This is a dictionary, that maps between class name ( part of it ) to the header file that should be included. You will have to add your header file to it. That's all. Possible I missed something. If you find this technique useful we can work together on making it more user friendly. By the way, containers is not the only functionality you can customize this way: Py++ svn introduced is_immutable function - this function returns true if C++ type will be mapped to immutable type in Python. If you will tell to Py++ that this and that types are immutable, it will save you time. Smart pointers is another area, where you can teach Py++. After this it will be able to generate write HeldType and to generate "register_ptr_to_python" and "implicitly_convertible" code. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |