From: wim <wi...@te...> - 2014-02-25 21:10:27
|
Hi, I've posted a different, minimal example of my problem on StackOverflow: http://tinyurl.com/lt4fx8v Thanks for any help! On 02/20/2014 02:21 PM, wim wrote: > Hi all, > > I'm having problems with customs typemaps. Basically I don't know what > typemaps should be defined for a given wrapped C++ class, in order to be > able to iterate over the vector in Python ("for item in myVector: ..."). > > If I do "for i in xrange(len(myVector)): print(myVector[i])" then there > is no problem. But iterators don't work. > > I've written a fairly comprehensive piece of test code that shows the > problem, it's all at http://tinyurl.com/nys333f > > The test code defines a "Variant" in C++, that can take multiple data > types (primitive ones such as bool and int, and custom ones such as > Fraction): see "variant.h". > The code is wrapped by "test.i", which uses "conversions.h" for > converting a Variant <-> PyObject. > When running a test ("play.py"), it's easy to see that iterators in > Python are not wrapped (see "console output"). > Even when I define a whole bunch of other typemaps ("more_typemaps.i"), > the output remains the same. > > So my questions are: > - What typemap(s) do I have to define, in order for the iterators to > work in Python? > - Is my approach of creating helper functions ("check()", > "convertPyToCpp()", "convertCppToPy()") a reasonable thing to do? > Obviously the point of these functions is to reuse some code when > creating for instance "out" and "argout" typemaps. > - Does my approach of calling "convertCppToPy()" with "$owner" > prevents memory leaks? > - Can my code be simplified? Do I really have to deal with things like > "SWIG_ConvertPtr" and "SWIG_NewPointerObj", or can I avoid them in some way? > > Sorry for the lengthy example, but it addresses some problems that I > have spent many many hours on, and I just don't see a solution. > > Thanks a lot in advance! > > Wim > > ------------------------------------------------------------------------------ > Managing the Performance of Cloud-Based Applications > Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. > Read the Whitepaper. > http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > |