Re: [pygccxml-development] [py++] vector of vectors trouble
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2009-01-16 19:17:14
|
On Fri, Jan 16, 2009 at 3:22 PM, Maik Beckmann <bec...@go...> wrote: > Hello, > > I got two problems with vector of vectors > 1. nested vector type isn't exported > 2. renaming of "vector<vector<> >" doesn't work as expected > > =============================================== > =============================================== > > 1. nested vector type isn't exported > > test.hpp (include guards omitted) > {{{ > #include <vector> > void bar(std::vector<std::vector<double> > vv) > { ... } > }}} > > This is how I expect it to work in python > {{{ > from pyMaik import vector_less__double__greater_ as vector_double > from pyMaik import > vector_less__std_scope_vector_less__double__greater___greater_ as > vvector_double > from pyMaik import foo > > v1 = vector_double() > v1.append(1) > v2 = vector_double() > v2.append(2) > > vv = vvector_double() > vv.append(v1) > vv.append(v2) > > foo(vv) > }}} > However, it doesn't work because > std::vector<std::vector<double> > > is exported, but > std::vector<double> > not. Adding a dummy to test.hpp > void dummy(std::vector<double> v) { } > solves this problem, but I wonder if there is a better way to do this. Not really, all other solutions are variations of the found one. > > ================================================ > > 2. renaming of "vector<vector<> >" doesn't work as expected. > > To change this > {{{ > from pyMaik import vector_less__double__greater_ as vector_double > from pyMaik import > vector_less__std_scope_vector_less__double__greater___greater_ as > vvector_double > from pyMaik import foo > }}} > to > {{{ > from pyMaik import vector_double, vvector_double, foo > }}} > I've added the following to generate_code.py > {{{ > std = mb.namespace('std'); > > # do work: > #mb.class_('::std::vector<double>').rename('vector_double') > std.class_('vector<double>').rename('vector_double') > > # doesn't work: > #std.class_('vector<vector<double> >').rename('vvector_double') > #mb.class_('::std::vector<::std::vector< double > >>').rename('vvector_double')# doesn't work > #works: > mb.class_('::std::vector< std::vector< double > >').rename('vvector_double') > }}} > > As you can see from the comment vector<double> works nicely with, where > std.class_('vector<double>').rename('vector_double') > is what I prefer. For vector<vector<double> > I tried > std.class_('vector<vector<double> >').rename('vvector_double') > but it doesn't work. Then I tried > mb.class_('::std::vector<::std::vector< double > >>').rename('vvector_double') > because because ::std::vector<double> worked above, but I it doesn't work > either. The only statement I've found to get what I want is > mb.class_('::std::vector< std::vector< double > >').rename('vvector_double') > What are the rules (give me a RTFM with and a link if I missed it) ? The RTFM will not help :-). Mainly because you have to specify the exact name of the class as it reports gccxml. Also, I tried very hard to simplify those things, but as you can see there are still problems. The relevant source code link: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pygccxml_dev/pygccxml/declarations/matchers.py?revision=1428&view=markup Take a look on class declaration_matcher_t. If you will be able to improve this - I will gladly accept your patch. Py++ propose other solution to the same problem - much easier and less error prone: http://language-binding.net/pyplusplus/documentation/how_to/hints.html HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |