0
我正在swigging到Java。我試圖讓一個模板化的成員func使用一些模板化的返回類型,我必須給出一個名稱當然(因爲否則SWIG不會創建所需的源)。SWIG2模板返回類型命名空間沒有檢測到
test.i是這樣的:
%module Test
%{
#include <vector>
namespace ns
{
class C
{
public:
template <class T>
void doit(const std::vector<T>& v) {}; // will need std:vector<int> version of that
};
}
%}
%include "std_vector.i"
%template(Ivec) std::vector<int>; // here I'm defining an std::vector<int> to use ...
%nspace ns::C;
namespace ns
{
class C
{
public:
template <class T>
void doit(const std::vector<T>& v);
};
}
%extend ns::C
{
%template(Idoit) doit<int>; // ... here
}
當調用:
swig -c++ -java -outdir mypack -package mypack test.i
mypack/NS/C.java樣子:
package mypack.ns;
public class C {
private long swigCPtr;
protected boolean swigCMemOwn;
public C(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public static long getCPtr(C obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
mypack.TestJNI.delete_ns_C(swigCPtr);
}
swigCPtr = 0;
}
}
public void Idoit(Ivec v) { // OK, Ivec is beeing used ... but not with its fqn
mypack.TestJNI.ns_C_Idoit(swigCPtr, this, Ivec.getCPtr(v), v);
}
public C() {
this(mypack.TestJNI.new_ns_C(), true);
}
}
這是很好的,但IVEC是在mypack/Ivec.java中定義,位於'global'包中,因此編譯源失敗。我如何才能讓SWIG使用Ivec的全名?
我也試圖推動IVEC到同一個命名空間爲C,如:
%module Test
%{
#include <vector>
namespace ns
{
class C
{
public:
template <class T>
void doit(const std::vector<T>& v) {}; // will need std:vector<int> version of that
};
}
%}
%include "std_vector.i"
%nspace ns::C;
%nspace ns::Ivec;
namespace ns
{
%template("ns.Ivec") std::vector<int>;
class C
{
public:
template <class T>
void doit(const std::vector<T>& v);
};
}
%extend ns::C
{
%template(Idoit) doit<int>;
}
但有IVEC仍然位於mypack和mypack/NS效用/ C.java現在是:
package mypack.ns;
public class C {
private long swigCPtr;
protected boolean swigCMemOwn;
public C(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public static long getCPtr(C obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
mypack.TestJNI.delete_ns_C(swigCPtr);
}
swigCPtr = 0;
}
}
public void Idoit(SWIGTYPE_p_ns__std__vectorT_int_t v) { // aaaaaaaaah
mypack.TestJNI.ns_C_Idoit(swigCPtr, this, SWIGTYPE_p_ns__std__vectorT_int_t.getCPtr(v));
}
public C() {
this(mypack.TestJNI.new_ns_C(), true);
}
}
現在痛飲甚至不承認酷IVEC :(
有沒有人遇到類似的困難,並給我一些暗示?
B I克叔高x BBB