2011-12-09 38 views
1

我正在嘗試使用SWIG重命名將自動生成的代理Java類test_cache_t.java的名稱更改爲Example.java。我已經嘗試了下面的內容,因爲它可以按照this question的C結構正常工作,但它不適用於C枚舉。有任何想法嗎?我得到了一些警告,不太引起我的問​​題......如何重命名從C枚舉類型創建的SWIG生成的代理Java類

%module Example 

%rename (Example) test_cache_t_; 
typedef enum test_cache_t_ { 
    CACHE_FALSE = 0, 
    CACHE_TRUE = 1 
} test_cache_t; 

%{ 
    #include "Example.h" 
%} 
%include "Example.h" 
[exec] /test/include/Example.h:84: Warning 302: Identifier 'test_cache_t' redefined (ignored) (Renamed from 'test_cache_t_'), 
[exec] test.i:7: Warning 302: previous definition of 'test_cache_t' (Renamed from 'test_cache_t_'). 
[exec] /test/include/Example.h:82: Warning 302: Identifier 'CACHE_FALSE' redefined (ignored), 
[exec] test.i:5: Warning 302: previous definition of 'CACHE_FALSE'. 
[exec] /test/include/Example.h:84: Warning 302: Identifier 'CACHE_TRUE' redefined (ignored), 
[exec] test.i:7: Warning 302: previous definition of 'CACHE_TRUE'. 

回答

1

這裏有兩個問題,我認爲:

  1. 你的模塊具有相同的名稱( %rename d)類型,所以你有兩件事情想成爲Example.java。

    解決方案:%rename

  2. 改變任何一個模塊或新名稱的名稱看起來您提供SWIG兩個定義相同enum,一旦在接口文件中,一次在頭文件。

    解決方案:可能從接口文件中刪除typedef enum test_cache_t_,所述%include之前可選地使用%ignore,或者完全丟棄%include。當測試結束看起來像

我最後的接口文件:

%module SomeOtherName 

%{ 
    #include "Example.h" 
%} 

%rename (Example) test_cache_t; 

%include "Example.h" 

奇怪的是這個工作,我不得不使用typedef「在%renameð名稱,而不是enum名。我不太清楚爲什麼這似乎與struct/class的情況相反。

+0

#2是我的問題。我使用「示例」名稱代替真名。 – c12