From: Tapio T. <tap...@tk...> - 2009-01-30 16:45:02
|
Thank you for your tip Martin, But how can I use this to wrap functions that use std::vector of these structs as a parameter? like: bool processData(std::vector<Ttest> &aPunchOfTests); or typedef std::vector<Ttest> TtestArray2; bool processData(TtestArray2 &aPunchOfTests); Thanks for any input, Tapio Michael Martin wrote: > I think your best option would be to: > > 1) Break each struct definition out into separate header files. > 2) write a dirt simple swig wrapper for each type of struct. > 3) import those into your application. > > I.E: > > Ttest.h: > > struct Ttest{ > Ttest(int ai=0): > i(ai){} > int i; > }; > > Ttest.i: > > %module Ttest > %[ > #include "Ttest.h" > %} > %include Ttest.h > > Python: > > import Ttest > myTtest = Ttest() > self.i = myTtest.i > > In short, separate wrappers for the struct and the library. > > > --- On *Thu, 1/29/09, Tapio Taipalus /<tap...@tk...>/* wrote: > > From: Tapio Taipalus <tap...@tk...> > Subject: [Swig-user] wrapping c++ struct vector for python > To: swi...@li... > Date: Thursday, January 29, 2009, 3:51 PM > > Greetings to all avid coders, > > My problem is this: > I need to wrap some c++ libraries that handles lots of data in structs > and data sets of those structs in std::vectors. > > Example given in swig documentation > http://www.swig.org/Doc1.3/Library.html#Library_nn15 > is using just basic data types in vectors. > > > ---------8<--------------8<--------- > > %module test > > %include "std_vector.i" > > %{ > #include <vector> > %} > > > //this works > typedef std::vector<int> TtestArray1; > namespace std { > %template(TtestArray1) vector<int>; > } > > > //and this does not work. Why o why? Is this supposed to work or not? > struct Ttest{ > Ttest(int ai=0): > i(ai){} > int i; > }; > > typedef std::vector<Ttest> TtestArray2; > namespace std { > %template(TtestArray2) > vector<Ttest>; > } > > ---------8<--------------8<--------- > > The funny thing is that this still works but more or less randomly with > some structs. I mean swig creates test_wrap.cpp without problem every > time but produced file does not usually compile. > > Can anyone please shed some light on this topic, > > Tapio > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > > |