假设我有一个具有单个字段的简单结构:
typedef struct {
MY_UNICODE value[512];
} TEST_STRUCTURE
其中MY_UNICODE
是一个自定义的unicode实现。
另外,我有两种方法:
从和转换为此自定义类型。
现在我可以使用SWIG
为此生成一个Python接口。
但是当我尝试在Python中访问TESTSTRUCTURE.value
时。我总是指向一个MY_UNICODE
对象。在
我的问题是:如何包装对结构成员的访问,以便获取python字符串并使用python字符串设置值?在
我知道SWIG的文档中提到了memberin
类型映射。
但我的例子行不通:
%module test
%include "typemaps.i"
// This is the header file, where the structure and the functions are defined
%include "test.h"
%typemap(memberin) MY_UNICODE [512] {
if(UTF8ToMyUnicode($1, $input) != 0) {
return NULL;
}
}
%typemap(memberout) MY_UNICODE [512] {
if(MyUnicodeToUTF8($1, $input) != 0) {
return NULL;
}
}
在生成的包装文件中,映射尚未应用。在
任何帮助都将不胜感激!谢谢!在
附言:我用的是swig2.0.10
我自己解决了这个问题。重要的是在接口中定义结构之前需要定义类型映射。文档对此并不清楚(或者我没有看到)。此外,还可以使用“in”和“out”类型映射来转换值。 这个例子对我很有用:
相关问题 更多 >
编程相关推荐