Swig Wrapping C++ For Python: Translating A List Of Strings To An Stl Vector Of Stl Strings
I would like to wrap a C++ function with SWIG which accepts a vector of STL strings as an input argument: #include #include #include
Solution 1:
You need to tell SWIG that you want a vector string typemap. It does not magically guess all the different vector types that can exist.
This is at the link provided by Schollii:
//To wrap with SWIG, you might write the following:
%module example
%{
#include"example.h"
%}
%include "std_vector.i"
%include "std_string.i"// Instantiate templates used by examplenamespace std {
%template(IntVector) vector<int>;
%template(DoubleVector) vector<double>;
%template(StringVector) vector<string>;
%template(ConstCharVector) vector<constchar*>;
}
// Include the header file with above prototypes
%include "example.h"
Solution 2:
SWIG does support passing a list to a function that takes a vector as value, or a const vector reference. The example at http://www.swig.org/Doc2.0/Library.html#Library_std_vector shows this, I can't see anything wrong with what you posted. Something else is wrong; DLL found by python was't the latest, the using namespace std in the header is confusing the SWIG wrapper code that does the type checking (note that "using namespace" statements in .hpp is a no-no in general as it pulls everything from std into global namespace), etc.
Post a Comment for "Swig Wrapping C++ For Python: Translating A List Of Strings To An Stl Vector Of Stl Strings"