views:

58

answers:

0

Hi, I'm using SWIG to wrap C++ code to Python code. I'm trying to wrap a vector of vectors.

The method is:

std::vector<std::vector<MyClass*>*> GetMyClassVectorOfVectors();

I'm able to wrap the first vector without adding lines to the file "MyAplication.i": The method is

std::vector<MyClass*> GetMyClassVector();

And this is working properly.

To wrap the vector of vectors, the following lines were needed in the file "MyApplication.i"

%include "std_vector.i"
%{ 
#include <vector> 
%} 

namespace std {
   %template(VectorOfMyClassVector) vector<vector<MyClass*>*>;
}

Question1: Does it possible to wrap a vector of vector without using the reference to the vector?

Questions2: I'm getting a vector of vectors, but the problem is that the items of the second vectors aren't the required. I'm getting a vector of the BaseClass, not a vector of the MyClass objects.

The C++ methods are:

(This is working properly)

std::vector<MyClass*> MyClass::GetMyClassVector()
{

      static std::vector<MyClass*> list;
      list.clear(); 

      list.push_back(new MyClass());

      return list;
}

(This is returning a vector of vector of the BaseClass of My Class, and it should return a vector of vectors of MyClass items).

std::vector<std::vector<MyClass*>*> MyClass::GetMyClassVectorOfVectors()
{

      static std::vector<MyClass*> list;
      list.clear(); 

      list.push_back(new MyClass());


      static std::vector<std::vector<MyClass*>*> list2;
      list2.clear();

      list2.push_back(&list);
      return list2;
}

Thanks for the help!!! Regards, Javier