1
假設我有一個簡單的結構,單場:的Python:痛飲:將訪問封裝到一個struct
typedef struct {
MY_UNICODE value[512];
} TEST_STRUCTURE
凡MY_UNICODE
是一個自定義的Unicode實現。 另外我有兩種方法:
int UTF8ToMyUnicode(char *utf8, MY_UNICODE *unicode);
int MyUnicodeToUTF8(MY_UNICODE *unicode, char *utf8);
要和這個自定義類型轉換。 現在我可以使用SWIG
爲此生成一個Python接口。 但是,當我嘗試訪問Python中的TESTSTRUCTURE.value
。我總是得到一個指向MY_UNICODE
對象的點。
我的問題是:如何包裝對結構成員的訪問,以便獲得python字符串並可以使用python字符串設置值?
我知道SWIG的文檔說了一些關於memberin
typemap的內容。 但我的例子不工作:
%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;
}
}
在生成的封裝文件,地圖上還沒有得到應用。
任何幫助,將不勝感激!謝謝!
PS:我正在使用swig 2.0.10