Connecting Tech Pros Worldwide Help | Site Map

Vector and SWIG java problem

Newbie
 
Join Date: Jun 2007
Posts: 21
#1: Jun 8 '07
I would appreciate if someone can help me dealing with wrapping java around c++ using SWIG. I have wrapped simple classes without any problem but I had some difficulties getting a vector function working. Here is what I have. I have two classes in C++; Fold class and Subs class. In the Subs class there is a method called get_all_folds that returns a vector of Fold objects. I compiled my c++ code and wrote a c++ driver and everything works just fine.
and here what I had in my c++ driver:

subs mySubs=new subs();
vector<Fold> myV=mySubs.get_all_folds("by name");
for everyitem in myV{
myV[i].get_length();
etc...
}

Now I used the SWIG to wrap java around it. Everything compiles fine except when I tried to read out the objects of this function. I noticed that there is no vector returned even though there was no error compiling or even running. It just will not return anything. Here is what I have in my java driver.

System.loadLibrary("mylib");/c++ library
subs newSubs=new subs(); //my subs class
SWIGTYPE_Fold_vector newV=newSubs.get_all_folds("by name");//SWIGType is the vector of Fold objects built by SWIG
System.out.println("Size:"+newV.size());
...Results
Size:0

I have tried other approaches but I would get errors. Can someone help me or see what I am doing wrong? If you have suggestions on how you will go about doing it please let me know.

I appreciate your help,
Jaz
Reply