假设我编写了以下映射:
/* File : gmpy.i */
%module gmpy
%{ #include "gmpy.h" %};
%include <stl.i>
namespace std {
%template(_string_list) vector< string >;
}
%newobject makeRunCalibrationParam;
%delobject delRunCalibrationParam;
%typemap(in) _string_list {
/* Check if is a list */
if (PyList_Check($input)) {
int size = PyList_Size($input);
$1.resize(size);
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
if (PyString_Check(o))
$1[i] = PyString_AsString(PyList_GetItem($input,i));
else {
PyErr_SetString(PyExc_TypeError,"list must contain strings");
return NULL;
}
}
} else {
PyErr_SetString(PyExc_TypeError,"not a list");
return NULL;
}
}
%include "gmpy.h"
当我将python字符串列表映射到void foo(const std::vector<std::string>& arr)
等函数参数时,它确实有效。但是,我不知道如何将它映射到结构域:
struct Foo {
std::vector<std::string> field;
};
它说
TypeError: in method 'Foo_field_set', argument 2 of type 'std::vector< std::string,std::allocator< std::string > > *'
AFAIU它应该识别setter方法的参数类型并匹配approriate类型转换器。为什么它没有以及如何在没有多余代码重复的情况下扩展此转换?