From: Ayman H. <aha...@gm...> - 2013-02-07 20:34:40
|
Thanks Alan, Yes, I tried the instantiation in the .i file and got Array3.java but the rest of the wrapping does not use Array3 instead it uses SWIG_ArrayT_double_t (or similar cryptic name) so the follow up question was whether I need to define a typemap to tell SWIG to use Array3 wherever SWIG_ArrayT_double_t is used and if there are examples to show the process. Thanks much for your help, -Ayman On Thu, Feb 7, 2013 at 12:01 PM, Alan Woodland <ala...@gm...>wrote: > On 6 February 2013 21:08, Ayman Habib <aha...@gm...> wrote: > > > > I'm trying to use SWIG to wrap a library of C++ classes that uses > templates. > > I'm using version 2.0.9 and I'm doing the wrapping to Java. Here's the > code > > snippet from the headers I'm wrapping: > > > > // Array.h > > template <int size, class type, int STEP> class Array{ > > ..... > > } > > > > //VarArray.h > > // (forward declaration and defaults for last two template parameters) > > template <int M, class E=double, int STEP=1> class Array; > > > > > > // ArrayN.h > > typedef Array<2> Array2; > > typedef Array<3> Array3; > > > > The rest of the code uses Array2, Array3, Array<> extensively. > > > > The interface file includes these lines: > > > > %include <Array.h> > > %include <VarArray.h> > > %include <ArrayN.h> > > > > SWIG processes the interface file but produces no Array2, Array3.java. I > > tried doing the template instantiation for Array3 in the .i file, and > that > > produced the correct Array3.java but the type was not identified as the > > corresponding C++ type so it wasn't useful. Is there a way to tell SWIG > that > > two types are same? > > > > Any suggestions regarding how to fix this problem would be greatly > > appreciated. > > > > If I've understood your problem correctly you've discovered that > typedefs alone are never sufficient to create a new type with SWIG - > that would create strong typedef semantics in strongly typed target > languages like Java which doesn't map onto the C++ very well and is > pointless for weakly typed ones. > > Instead you want to add something like: > > %template(Array2) Array<2>; > %template(Array3) Array<3>; > > to your interface file after the corresponding %include to instruct > SWIG to instantiate the template with specific values for its > arugments, with a specific name in the target language. > > Alan > |