📄 typemaps_java.i
字号:
%typemap(jni) (int nList, int* pList) "jintArray"%typemap(jtype) (int nList, int* pList) "int[]"%typemap(jstype) (int nList, int* pList) "int[]"%typemap(javain) (int nLen, int *pList ) "$javainput"%typemap(javaout) (int nLen, int *pList ) { return $jnicall; }%typemap(in) char **dict{ /* %typemap(in) char **dict */ /* Convert the Hashtable to a char array */ $1 = NULL; if($input != 0) { const jclass hashtable = jenv->FindClass("java/util/Hashtable"); const jclass enumeration = jenv->FindClass("java/util/Enumeration"); const jmethodID get = jenv->GetMethodID(hashtable, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); const jmethodID keys = jenv->GetMethodID(hashtable, "keys", "()Ljava/lang/Enumeration;"); const jmethodID hasMoreElements = jenv->GetMethodID(enumeration, "hasMoreElements", "()Z"); const jmethodID getNextElement = jenv->GetMethodID(enumeration, "getNextElement", "()Ljava/lang/Object;"); for (jobject keyset = jenv->CallObjectMethod($input, keys); jenv->CallBooleanMethod(keyset, hasMoreElements) == JNI_TRUE;) { jstring key = (jstring)jenv->CallObjectMethod(keyset, getNextElement); jstring value = (jstring)jenv->CallObjectMethod($input, get, key); const char *keyptr = jenv->GetStringUTFChars(key, 0); const char *valptr = jenv->GetStringUTFChars(value, 0); $1 = CSLAddNameValue($1, keyptr, valptr); jenv->ReleaseStringUTFChars(key, keyptr); jenv->ReleaseStringUTFChars(value, valptr); } }}%typemap(out) char **dict{ /* %typemap(out) char ** -> to hash */ /* Convert a char array to a Hashtable */ char **stringarray = $1; const jclass hashtable = jenv->FindClass("java/util/Hashtable"); const jmethodID constructor = jenv->GetMethodID(hashtable, "<init>", "()V"); const jmethodID put = jenv->GetMethodID(hashtable, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); $result = jenv->NewObject(hashtable, constructor); if ( stringarray != NULL ) { while (*stringarray != NULL ) { char const *valptr; char *keyptr; /*printf("working on pair: %s\n", *stringarray);*/ valptr = CPLParseNameValue( *stringarray, &keyptr ); if ( valptr != 0 ) { jstring name = jenv->NewStringUTF(keyptr); jstring value = jenv->NewStringUTF(valptr); jenv->CallObjectMethod($result, put, name, value); CPLFree( keyptr ); } stringarray++; } }}%typemap(freearg) char **dict{ /* %typemap(freearg) char **dict */ CSLDestroy( $1 );}%typemap(jni) (char **dict) "jobject"%typemap(jtype) (char **dict) "java.util.Hashtable"%typemap(jstype) (char **dict) "java.util.Hashtable"%typemap(javain) (char **dict) "$javainput"%typemap(javaout) (char **dict) { return $jnicall; }/* * Typemap maps char** arguments from a Vector */%typemap(in) char **options{ /* %typemap(in) char **options */ $1 = NULL; if($input != 0) { const jclass vector = jenv->FindClass("java/util/Vector"); const jclass enumeration = jenv->FindClass("java/util/Enumeration"); const jmethodID elements = jenv->GetMethodID(vector, "elements", "()Ljava/util/Enumeration;"); const jmethodID hasMoreElements = jenv->GetMethodID(enumeration, "hasMoreElements", "()Z"); const jmethodID getNextElement = jenv->GetMethodID(enumeration, "nextElement", "()Ljava/lang/Object;"); if(vector == NULL || enumeration == NULL || elements == NULL || hasMoreElements == NULL || getNextElement == NULL) { fprintf(stderr, "Could not load (options **) jni types.\n"); return $null; } for (jobject keys = jenv->CallObjectMethod($input, elements); jenv->CallBooleanMethod(keys, hasMoreElements) == JNI_TRUE;) { jstring value = (jstring)jenv->CallObjectMethod(keys, getNextElement); const char *valptr = jenv->GetStringUTFChars(value, 0); $1 = CSLAddString($1, valptr); jenv->ReleaseStringUTFChars(value, valptr); } }}%typemap(freearg) char **options{ /* %typemap(freearg) char **options */ CSLDestroy( $1 );}%typemap(out) char **options{ /* %typemap(out) char ** -> ( string ) */ char **stringarray = $1; const jclass vector = jenv->FindClass("java/util/Vector"); const jmethodID constructor = jenv->GetMethodID(vector, "<init>", "()V"); const jmethodID add = jenv->GetMethodID(vector, "add", "(Ljava/lang/Object;)Z"); $result = jenv->NewObject(vector, constructor); if ( stringarray != NULL ) { while(*stringarray != NULL) { /*printf("working on string %s\n", *stringarray);*/ jstring value = (jstring)jenv->NewStringUTF(*stringarray); jenv->CallBooleanMethod($result, add, value); stringarray++; } }}%typemap(jni) (char **options) "jobject"%typemap(jtype) (char **options) "java.util.Vector"%typemap(jstype) (char **options) "java.util.Vector"%typemap(javain) (char **options) "$javainput"%typemap(javaout) (char **options) { return $jnicall; }%define OPTIONAL_POD(type,argstring)%typemap(in) (type *optional_##type){ /* %typemap(in) (type *optional_##type) */ $1 = ($1_type)$input;}%typemap(argout) (type *optional_##type){ /* %typemap(in) (type *optional_##type) */}%typemap(typecheck,precedence=0) (type *optional_##type){ /* %typemap(typecheck,precedence=0) (type *optionalInt) */}%typemap(jni) (type *optional_##type) "jintArray"%typemap(jtype) (type *optional_##type) "int[]"%typemap(jstype) (type *optional_##type) "int[]"%typemap(javain) (type *optional_##type) "$javainput"%typemap(javaout) (type *optional_##type) { return $jnicall; }%enddefOPTIONAL_POD(int,i);/* * Typemap for char **argout. */%typemap(in) (char **argout) ( char *argout=0 ){ /* %typemap(in) (char **argout) */ $1 = &argout;}%typemap(argout) (char **argout){ /* %typemap(argout) (char **argout) */ jstring temp_string; if((int)jenv->GetArrayLength($input) >= 1) { temp_string = jenv->NewStringUTF(argout$argnum); jenv->SetObjectArrayElement($input, 0, temp_string); jenv->DeleteLocalRef(temp_string); }}%typemap(freearg) (char **argout){ /* %typemap(freearg) (char **argout) */ if($1) { free((void *)argout$argnum); }}%typemap(jni) (char **argout) "jobjectArray"%typemap(jtype) (char **argout) "String[]"%typemap(jstype) (char **argout) "String[]"%typemap(javain) (char **argout) "$javainput"%typemap(javaout) (char **argout) { return $jnicall; }%typemap(in) (double *argout[ANY]) (double *argout[$dim0]){ /* %typemap(in) (double *argout[ANY]) */ $1 = argout;}%typemap(argout) (double *argout[ANY]){ /* %typemap(argout) (double *argout[ANY]) */ jenv->SetDoubleArrayRegion($input, (jsize)0, (jsize)$dim0, $1[0]);}%typemap(freearg) (double *argout[ANY]){ /* %typemap(freearg) (double *argout[ANY]) */ CPLFree($1);}%typemap(jni) (double *argout[ANY]) "jdoubleArray"%typemap(jtype) (double *argout[ANY]) "double[]"%typemap(jstype) (double *argout[ANY]) "double[]"%typemap(javain) (double *argout[ANY]) "$javainput"%typemap(javaout) (double *argout[ANY]) { return $jnicall; }%typemap(in) (double argin[ANY]) (jboolean isCopy){ /* %typemap(in) (double argin[ANY]) */ $1 = (double *)jenv->GetDoubleArrayElements($input, &isCopy);}%typemap(argout) (double argin[ANY]){ /* %typemap(argout) (double argin[ANY]) */}%typemap(freearg) (double argin[ANY]){ /* %typemap(in) (double argin[ANY]) */ if(isCopy$argnum == JNI_TRUE) { jenv->ReleaseDoubleArrayElements($input, (jdouble *)$1, 0); }}%typemap(jni) (double argin[ANY]) "jdoubleArray"%typemap(jtype) (double argin[ANY]) "double[]"%typemap(jstype) (double argin[ANY]) "double[]"%typemap(javain) (double argin[ANY]) "$javainput"%typemap(javaout) (double argin[ANY]) { return $jnicall; }/* This tells SWIG to treat char ** as a special case when used as a parameter in a function call */%typemap(in) char ** (jint size) { /* %typemap(in) char ** (jint size) */ int i = 0; size = jenv->GetArrayLength($input); $1 = (char **) malloc((size+1)*sizeof(char *)); /* make a copy of each string */ for (i = 0; i<size; i++) { jstring j_string = (jstring)jenv->GetObjectArrayElement($input, i); const char * c_string = jenv->GetStringUTFChars(j_string, 0); $1[i] = (char *)malloc(strlen((c_string)+1)*sizeof(const char *)); strcpy($1[i], c_string); jenv->ReleaseStringUTFChars(j_string, c_string); jenv->DeleteLocalRef(j_string); } $1[i] = 0;}/* This cleans up the memory we malloc'd before the function call */%typemap(freearg) char ** { /* %typemap(freearg) char ** */ int i; for (i=0; i<size$argnum-1; i++) free($1[i]); free($1);}/* This allows a C function to return a char ** as a Java String array */%typemap(out) char ** { /* %typemap(out) char ** */ int i; int len=0; jstring temp_string; const jclass clazz = jenv->FindClass("java/lang/String"); while ($1[len]) len++; jresult = jenv->NewObjectArray(len, clazz, NULL); /* exception checking omitted */ for (i=0; i<len; i++) { temp_string = jenv->NewStringUTF(*result++); jenv->SetObjectArrayElement(jresult, i, temp_string); jenv->DeleteLocalRef(temp_string); }}/* These 3 typemaps tell SWIG what JNI and Java types to use */%typemap(jni) char ** "jobjectArray"%typemap(jtype) char ** "String[]"%typemap(jstype) char ** "String[]"%typemap(javain) char ** "$javainput"%typemap(javaout) char ** { return $jnicall; }%typemap(in) void * { /* %typemap(in) void * */ $1 = jenv->GetDirectBufferAddress($input);}/* These 3 typemaps tell SWIG what JNI and Java types to use */%typemap(jni) void * "jobject"%typemap(jtype) void * "java.nio.ByteBuffer"%typemap(jstype) void * "java.nio.ByteBuffer"%typemap(javain) void * "$javainput"%typemap(javaout) void * { return $jnicall; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -