如何为std :: set创建Swig自定义类型映射,以被本机python集合包装?

时间:2020-03-24 08:36:12

标签: swig

swig提供的默认类型映射期望将python列表作为构建集而不是本机Python集的输入(请参见here)。确实,

%include "std_set.i"
%template(IntSet) std::set<int>;

将在python中触发以下行为:

>>> import MyClass
>>> MyClass.IntSet([1,2,3,4]) # works
>>> MyClass.IntSet({1,2,3,4}) # does not work

我试图创建一个自定义的类型映射,但是到目前为止我还是失败了。这是我当前的Swig文件:

%module MyClass

%{
    #include "MyClass.h"
%}

%include <typemaps.i>

%typemap(in) setin {$1 = PySequence_List($input);}
%typemap(out) setout {$result = PySet_New($1);}

%include "std_set.i"
%template(IntSet) std::set<int>;

%include "MyClass.h"

你知道怎么做吗?

0 个答案:

没有答案
相关问题