2011-12-12 30 views
1

我在我的SWIG接口文件中有以下結構,因此也是我的sample.h頭文件。我假設這個結構中的sockaddr,ios_boolean和unsigned char定義是我得到下面生成的類的原因。如果我知道在Java端的ios_boolean和unsigned char映射的類型有沒有辦法使用%apply去掉生成的指針類?我試過%apply int {ios_boolean};但後來我得到了一個SWIGTYPE_p_boolean.java。有任何想法嗎?使用SWIG重命名C結構屬性%apply

%rename (Sample) sample_details_t_; 
typedef struct sample_details_t_ {    
    ios_boolean     is_allowed;   
    unsigned char     mac[11];   
} sample_t; 


generates: 
SWIGTYPE_p_unsigned_char.java 
SWIGTYPE_p_ios_boolean.java 

例外:

[exec] ewapi_wrap.c:982: error: `true' undeclared (first use in this function) 
[exec] ewapi_wrap.c:982: error: (Each undeclared identifier is reported only once 
[exec] ewapi_wrap.c:982: error: for each function it appears in.) 
[exec] ewapi_wrap.c:982: error: `false' undeclared (first use in this function 

回答

2

你可能想這樣做:

%include <arrays_java.i> 
%rename (Sample) sample_details_t_; 
%apply bool { ios_boolean }; 
typedef struct sample_details_t_ {    
    ios_boolean     is_allowed;   
    unsigned char     mac[11];   
} sample_t; 

這種包裝macshort[](與數組的大小限制)在和is_allowedboolean Java方面和結果在這些文件中:

Sample.java test.java testJNI.java

確保在刪除任何舊SWIGTYPE_*.java文件,這些文件從舊版本的SWIG接口躺在附近,他們將不會自動刪除,可能會失敗編譯如果你做了類似javac *.java

+0

我剛剛嘗試了ios_boolean的建議,並在SWIG生成期間出現錯誤,它似乎無法將ios_boolean轉換爲bool。我在原始問題中添加了異常,因爲如果我在此處添加它,它會變得很糟糕。有任何想法嗎? – c12

+0

@ c12要#include stdbool.h或定義true和false常量或將庫的bool頭包含在接口頂部的%{%}中。 – Flexo