我设法从我的 C++ 实现中生成了一个 Java 类。为此,我有一个SubwordEncoder.i:
/* File : example.i */
%module encoder
%{
#include "SubwordEncoder.h"
%}
/* Let's just grab the original header file here */
%include "SubwordEncoder.h"
界面看起来像这样:
class SubwordEncoder {
public:
int* encode(char* decoded);
char* decode(int* encoded);
};
生成的代码是这样的:
public class SubwordEncoder {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected SubwordEncoder(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr(SubwordEncoder obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
encoderJNI.delete_SubwordEncoder(swigCPtr);
}
swigCPtr = 0;
}
}
public SWIGTYPE_p_int encode(String decoded) {
long cPtr = encoderJNI.SubwordEncoder_encode(swigCPtr, this, decoded);
return (cPtr == 0) ? null : new SWIGTYPE_p_int(cPtr, false);
}
public String decode(SWIGTYPE_p_int encoded) {
return encoderJNI.SubwordEncoder_decode(swigCPtr, this, SWIGTYPE_p_int.getCPtr(encoded));
}
public SubwordEncoder() {
this(encoderJNI.new_SubwordEncoder(), true);
}
}
但是是否也可以从 SWIG获得List<Integer>、ArrayList<int>或类似的东西?Iterable<int>
char*已经转换为 Java String(来自文档)但是扩展这些映射的最简单方法是什么?
SWIG 版本为 4.0.0 (Ubuntu)
守候你守候我
相关分类