我有这个结构
struct License
{
time_t creationTime;
...
};
我想将time_t转换为java.util.Calendar。
%typemap(jni) time_t "jobject"
%typemap(jtype) time_t "java.util.Calendar"
%typemap(jstype) time_t "java.util.Calendar"
%typemap(javain) time_t "$javainput"
%typemap(freearg) time_t ""
%typemap(in) time_t {
if ($input) {
jclass cls = JCALL1(GetObjectClass, jenv, $input);
jmethodID f = JCALL3(GetMethodID, jenv, cls, "getTimeInMillis", "()J");
$1 = JCALL2(CallLongMethod, jenv, $input, f)/1000;
}
}
%typemap(out) time_t {
jclass cls = JCALL1(FindClass, jenv, "Ljava/util/Calendar;");
jmethodID f = JCALL3(GetStaticMethodID, jenv, cls, "getInstance", "()Ljava/util/Calendar;");
$result = JCALL2(CallStaticObjectMethod, jenv, cls, f);
f = JCALL3(GetMethodID, jenv, cls, "setTimeInMillis", "(J)V");
JCALL3(CallVoidMethod, jenv, $result, f, $1*1000L);
}
这是生成的License.java
public class License {
public void setCreationTime(java.util.Calendar value) {
eveusb_javaJNI.License_creationTime_set(swigCPtr, this, value);
}
public java.util.Calendar getCreationTime() {
return new SWIGTYPE_p_time_t(eveusb_javaJNI.License_creationTime_get(swigCPtr, this), true);
}
getCreationTime错误地使用了SWIGTYPE_p_time_t。如何解决此错误?
答案 0 :(得分:0)
我找到了决定。原因是没有宣布time_t。根据swig文档,所有未指定的类型都在内部处理为指向结构或类的指针。该声明修复了我的问题
typedef long time_t;
现在生成了正确的代码:
public java.util.Calendar getCreationTime() {
return eveusb_javaJNI.License_creationTime_get(swigCPtr, this);
}