Thread: [pygccxml-development] Using pyplusplus with indexing suite
Brought to you by:
mbaas,
roman_yakovenko
From: Allen B. <al...@vr...> - 2006-05-17 04:12:51
|
I have a function class method that I am trying to wrap with pyplusplus. The method is similar to: std::vector< boost::shared_ptr< ClassA > > MyClass::getData(); I would like to use the indexing suite or something similar to make it possible to iterate over and use this list from python. Is there any support for this directly in pyplusplus or can anyone tell me what I need to do custom to allow this? -Allen |
From: Roman Y. <rom...@gm...> - 2006-05-17 05:05:31
|
On 5/17/06, Allen Bierbaum <al...@vr...> wrote: > I have a function class method that I am trying to wrap with pyplusplus. > > The method is similar to: > > std::vector< boost::shared_ptr< ClassA > > MyClass::getData(); > > I would like to use the indexing suite or something similar to make it > possible to iterate over and use this list from python. Is there any > support for this directly in pyplusplus or can anyone tell me what I > need to do custom to allow this? There are 2 ways to solve the problem. I will not like both of them. 1. Add custom code to class A: class_<std::vector< boost::shared_ptr<A> > >("AVec") .def(vector_indexing_suite<std::vector< std::vector< boost::shared_ptr<A> > > >()) ; And then from Python create a reference from global scope to it: AVec =3D A.AVec http://boost.org/libs/python/doc/v2/indexing.html 2. I will accept the patch. Now when I think about it, it should be fairly simple. 1. There is a need for vector_indexing_suite_ code creator. 2. After this small modification should be done to types_database_t. It should recognize, that data type is vector or map. pygccxml.declarations.templates parser will do the job easier 3. Modify module_creator.creator_t class I am running out of time, otherwise I would implement the patch by myself. I think it should take like 3-5 hours. --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2006-05-17 14:58:39
|
Roman Yakovenko wrote: > On 5/17/06, Allen Bierbaum <al...@vr...> wrote: > >> I have a function class method that I am trying to wrap with pyplusplus. >> >> The method is similar to: >> >> std::vector< boost::shared_ptr< ClassA > > MyClass::getData(); >> >> I would like to use the indexing suite or something similar to make it >> possible to iterate over and use this list from python. Is there any >> support for this directly in pyplusplus or can anyone tell me what I >> need to do custom to allow this? > > > There are 2 ways to solve the problem. I will not like both of them. > > 1. Add custom code to class A: > > class_<std::vector< boost::shared_ptr<A> > >("AVec") > .def(vector_indexing_suite<std::vector< std::vector< > boost::shared_ptr<A> > > >()) > ; > > And then from Python create a reference from global scope to it: > > AVec = A.AVec > > http://boost.org/libs/python/doc/v2/indexing.html I will have to try this one. I have to admit the code sample above doesn't make sense yet, but I will re-read the indexing documentation and see if I can figure it out. > > 2. I will accept the patch. Now when I think about it, it should be > fairly simple. > 1. There is a need for vector_indexing_suite_ code creator. > 2. After this small modification should be done to types_database_t. > It should recognize, that data type is vector or map. > pygccxml.declarations.templates parser will do the job easier > 3. Modify module_creator.creator_t class > > I am running out of time, otherwise I would implement the patch by > myself. > I think it should take like 3-5 hours. > Unfortunately I am not skilled enough to implement this. It is one thing to make patches that change interfaces slightly or fix small parts of code, it is an entirely different thing to understand the full code base and add a large new capability. :) I wish I had time to learn the code that well, but I do not right now. Sorry. :( Thanks for your help. -Allen |
From: Roman Y. <rom...@gm...> - 2006-05-17 17:13:32
|
On 5/17/06, Allen Bierbaum <al...@vr...> wrote: > Roman Yakovenko wrote: > > > On 5/17/06, Allen Bierbaum <al...@vr...> wrote: > > > >> I have a function class method that I am trying to wrap with pyplusplu= s. > >> > >> The method is similar to: > >> > >> std::vector< boost::shared_ptr< ClassA > > MyClass::getData(); > >> > >> I would like to use the indexing suite or something similar to make it > >> possible to iterate over and use this list from python. Is there any > >> support for this directly in pyplusplus or can anyone tell me what I > >> need to do custom to allow this? > > > > > > There are 2 ways to solve the problem. I will not like both of them. > > > > 1. Add custom code to class A: > > > > class_<std::vector< boost::shared_ptr<A> > >("AVec") > > .def(vector_indexing_suite<std::vector< std::vector< > > boost::shared_ptr<A> > > >()) > > ; > > > > And then from Python create a reference from global scope to it: > > > > AVec =3D A.AVec > > > > http://boost.org/libs/python/doc/v2/indexing.html > > I will have to try this one. I have to admit the code sample above > doesn't make sense yet, but I will re-read the indexing documentation > and see if I can figure it out. > > > > > 2. I will accept the patch. Now when I think about it, it should be > > fairly simple. > > 1. There is a need for vector_indexing_suite_ code creator. > > 2. After this small modification should be done to types_database_t= . > > It should recognize, that data type is vector or map. > > pygccxml.declarations.templates parser will do the job easier > > 3. Modify module_creator.creator_t class > > > > I am running out of time, otherwise I would implement the patch by > > myself. > > I think it should take like 3-5 hours. > > > Unfortunately I am not skilled enough to implement this. It is one > thing to make patches that change interfaces slightly or fix small parts > of code, it is an entirely different thing to understand the full code > base and add a large new capability. :) > > I wish I had time to learn the code that well, but I do not right now. > Sorry. :( You don't have to be sorry. Your comments keeps me in focus. I will impleme= nt this feature in next release. > Thanks for your help. > -Allen > --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2006-05-23 01:06:49
|
> > > 2. I will accept the patch. Now when I think about it, it should be > fairly simple. > 1. There is a need for vector_indexing_suite_ code creator. > 2. After this small modification should be done to types_database_t. > It should recognize, that data type is vector or map. > pygccxml.declarations.templates parser will do the job easier > 3. Modify module_creator.creator_t class > > I am running out of time, otherwise I would implement the patch by > myself. > I think it should take like 3-5 hours. > Any update on this. Is it still something you think can be automated? -Allen |
From: Roman Y. <rom...@gm...> - 2006-05-23 06:52:26
|
On 5/23/06, Allen Bierbaum <al...@vr...> wrote: > Any update on this. Is it still something you think can be automated? :-). Basically, I prepare pygccxml and pyplusplus for next release. This means that source code is almost freeze and the main task is to write documentation. I think I will make a release next week. I do not want to implement complete soluti= on for the problem. Under complete solution, I mean that py++ automatically finds out for which classes and what indexing suite should be registered. So I implemented partial solution, that I hope will make your life easier: mb =3D module_builder_t( ... ) item_cls =3D mb.class_( 'item_t' ) item_cls.indexing_suites.append( module_builder.vector_indexing_suite_t( 'items_t' ) ) I don't promise, that the last line will stay as is in the future( =3D=3D when I implement full support for indexing suite ). But don't worry, I will let you know before I will commit the changes. I know, that you are going to take a look on the code, I wrote, am I right? If so can you add few doc strings and commit? ( Yes, you have SVN access ). Thanks. P.S. vector_indexing_suite requires operators =3D=3D and !=3D. --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |