Commit 9cf2fa28 authored by David Gobbi's avatar David Gobbi Committed by Marcus D. Hanwell
Browse files

ENH: Add proper vtkStdString support to Java wrappers

parent dcdd01ce
......@@ -37,9 +37,9 @@ JNIEXPORT jlong vtkJavaGetId(JNIEnv *env,jobject obj)
{
jfieldID id;
jlong result;
id = env->GetFieldID(env->GetObjectClass(obj),"vtkId","J");
result = env->GetLongField(obj,id);
return result;
}
......@@ -69,7 +69,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfDoubleFromDouble(JNIEnv *env, double *ptr, i
{
array[i] = ptr[i];
}
env->ReleaseDoubleArrayElements(ret,array,0);
return ret;
}
......@@ -94,7 +94,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfDoubleFromFloat(JNIEnv *env, float *ptr, int
{
array[i] = ptr[i];
}
env->ReleaseDoubleArrayElements(ret,array,0);
return ret;
}
......@@ -119,7 +119,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfIntFromInt(JNIEnv *env, int *ptr, int size)
{
array[i] = ptr[i];
}
env->ReleaseIntArrayElements(ret,array,0);
return ret;
}
......@@ -144,7 +144,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfIntFromIdType(JNIEnv *env, vtkIdType *ptr, i
{
array[i] = (int)ptr[i];
}
env->ReleaseIntArrayElements(ret,array,0);
return ret;
}
......@@ -248,7 +248,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfFloatFromFloat(JNIEnv *env, float *ptr, int
{
array[i] = ptr[i];
}
env->ReleaseFloatArrayElements(ret,array,0);
return ret;
}
......@@ -273,7 +273,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfShortFromShort(JNIEnv *env, short *ptr, int
{
array[i] = ptr[i];
}
env->ReleaseShortArrayElements(ret,array,0);
return ret;
}
......@@ -298,7 +298,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfByteFromUnsignedChar(JNIEnv *env, unsigned c
{
array[i] = ptr[i];
}
env->ReleaseByteArrayElements(ret,array,0);
return ret;
}
......@@ -324,7 +324,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfLongFromLong(JNIEnv *env, long *ptr, int siz
{
array[i] = ptr[i];
}
env->ReleaseLongArrayElements(ret,array,0);
return ret;
}
......@@ -350,7 +350,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfUnsignedLongFromUnsignedLong(JNIEnv *env,uns
{
array[i] = ptr[i];
}
env->ReleaseLongArrayElements(ret,array,0);
return ret;
}
......@@ -376,7 +376,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfUnsignedShortFromUnsignedShort(JNIEnv *env,u
{
array[i] = ptr[i];
}
env->ReleaseShortArrayElements(ret,array,0);
return ret;
}
......@@ -402,7 +402,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfUnsignedCharFromUnsignedChar(JNIEnv *env,uns
{
array[i] = ptr[i];
}
env->ReleaseByteArrayElements(ret,array,0);
return ret;
}
......@@ -428,7 +428,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfUnsignedIntFromUnsignedInt(JNIEnv *env,unsig
{
array[i] = ptr[i];
}
env->ReleaseIntArrayElements(ret,array,0);
return ret;
}
......@@ -454,7 +454,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfCharFromChar(JNIEnv *env, char *ptr, int siz
{
array[i] = ptr[i];
}
env->ReleaseCharArrayElements(ret,array,0);
return ret;
}
......@@ -480,7 +480,7 @@ JNIEXPORT jarray vtkJavaMakeJArrayOfIntFromBool(JNIEnv *env, bool *ptr,int size)
{
array[i] = ptr[i];
}
env->ReleaseIntArrayElements(ret,array,0);
return ret;
}
......@@ -491,15 +491,15 @@ JNIEXPORT char *vtkJavaUTFToChar(JNIEnv *env, jstring in)
const char *inBytes;
int length, i;
int resultLength = 1;
if( in == NULL )
{
return NULL;
return NULL;
}
length = env->GetStringUTFLength(in);
inBytes = env->GetStringUTFChars(in,NULL);
for (i = 0; i < length; i++)
{
if ((inBytes[i] & 0x80) == 0) resultLength++;
......@@ -520,6 +520,34 @@ JNIEXPORT char *vtkJavaUTFToChar(JNIEnv *env, jstring in)
return result;
}
JNIEXPORT bool vtkJavaUTFToString(JNIEnv *env, jstring in, vtkStdString out)
{
const char *inBytes;
int length, i;
if( in == NULL )
{
return false;
}
length = env->GetStringUTFLength(in);
inBytes = env->GetStringUTFChars(in,NULL);
out.reserve(out.size() + length);
for (i = 0; i < length; i++)
{
if ((inBytes[i] & 0x80) == 0)
{
out.push_back(inBytes[i]);
}
}
env->ReleaseStringUTFChars(in,inBytes);
return true;
}
JNIEXPORT jstring vtkJavaMakeJavaString(JNIEnv *env, const char *in)
{
if (!in) {
......@@ -533,8 +561,8 @@ JNIEXPORT jstring vtkJavaMakeJavaString(JNIEnv *env, const char *in)
//since the callback must be a method of a class. We make the rash assumption
//that the <this> pointer will anchor any required other elements for the
//called functions. - edited by km
JNIEXPORT void vtkJavaVoidFunc(void* f)
{
JNIEXPORT void vtkJavaVoidFunc(void* f)
{
vtkJavaVoidFuncArg *iprm = (vtkJavaVoidFuncArg *)f;
// make sure we have a valid method ID
if (iprm->mid)
......@@ -546,16 +574,16 @@ JNIEXPORT void vtkJavaVoidFunc(void* f)
#else
iprm->vm->AttachCurrentThread((JNIEnv_**)(&e),NULL);
#endif
e->CallVoidMethod(iprm->uobj,iprm->mid,NULL);
e->CallVoidMethod(iprm->uobj,iprm->mid,NULL);
}
}
JNIEXPORT void vtkJavaVoidFuncArgDelete(void* arg)
JNIEXPORT void vtkJavaVoidFuncArgDelete(void* arg)
{
vtkJavaVoidFuncArg *arg2;
arg2 = (vtkJavaVoidFuncArg *)arg;
JNIEnv *e;
// it should already be atached
#ifdef JNI_VERSION_1_2
......@@ -568,13 +596,13 @@ JNIEXPORT void vtkJavaVoidFuncArgDelete(void* arg)
delete arg2;
}
vtkJavaCommand::vtkJavaCommand()
{
vtkJavaCommand::vtkJavaCommand()
{
this->vm = NULL;
}
vtkJavaCommand::~vtkJavaCommand()
{
vtkJavaCommand::~vtkJavaCommand()
{
JNIEnv *e;
// it should already be atached
#ifdef JNI_VERSION_1_2
......@@ -598,7 +626,7 @@ void vtkJavaCommand::Execute(vtkObject *, unsigned long, void *)
#else
this->vm->AttachCurrentThread((JNIEnv_**)(&e),NULL);
#endif
e->CallVoidMethod(this->uobj,this->mid,NULL);
e->CallVoidMethod(this->uobj,this->mid,NULL);
}
}
......@@ -19,12 +19,14 @@
#include "vtkSystemIncludes.h"
#include <jni.h>
#include "vtkCommand.h"
#include "vtkStdString.h"
extern JNIEXPORT jlong vtkJavaGetId(JNIEnv *env,jobject obj);
extern JNIEXPORT void *vtkJavaGetPointerFromObject(JNIEnv *env,jobject obj);
extern JNIEXPORT char *vtkJavaUTFToChar(JNIEnv *env, jstring in);
extern JNIEXPORT bool vtkJavaUTFToString(JNIEnv *env, jstring in, vtkStdString out);
extern JNIEXPORT jstring vtkJavaMakeJavaString(JNIEnv *env, const char *in);
extern JNIEXPORT jarray vtkJavaMakeJArrayOfFloatFromFloat(JNIEnv *env,
......
......@@ -38,7 +38,7 @@ void output_temp(FILE *fp,int i)
return;
}
if (aType == VTK_PARSE_CHAR_PTR)
if ((aType == VTK_PARSE_CHAR_PTR) || (aType == VTK_PARSE_STRING))
{
fprintf(fp,"String ");
}
......@@ -109,7 +109,10 @@ void return_result(FILE *fp)
case VTK_PARSE_BOOL:
fprintf(fp,"boolean ");
break;
case VTK_PARSE_CHAR_PTR: fprintf(fp,"String "); break;
case VTK_PARSE_CHAR_PTR:
case VTK_PARSE_STRING:
fprintf(fp,"String ");
break;
case VTK_PARSE_VTK_OBJECT_PTR:
fprintf(fp,"%s ",currentFunction->ReturnClass);
break;
......@@ -182,7 +185,10 @@ void return_result_native(FILE *fp)
case VTK_PARSE_BOOL:
fprintf(fp,"boolean ");
break;
case VTK_PARSE_CHAR_PTR: fprintf(fp,"String "); break;
case VTK_PARSE_CHAR_PTR:
case VTK_PARSE_STRING:
fprintf(fp,"String ");
break;
case VTK_PARSE_VTK_OBJECT_PTR:
fprintf(fp,"long ");
break;
......@@ -523,6 +529,7 @@ void outputFunction(FILE *fp, FileInfo *data)
if (aType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0;
if (aType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0;
if (aType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0;
if ((aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNICODE_STRING) args_ok = 0;
}
if ((rType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNKNOWN) args_ok = 0;
if (rType == VTK_PARSE_VTK_OBJECT) args_ok = 0;
......@@ -538,6 +545,8 @@ void outputFunction(FILE *fp, FileInfo *data)
if (rType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0;
if (rType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0;
if ((rType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNICODE_STRING) args_ok = 0;
if (currentFunction->NumberOfArguments &&
(currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)
&&(currentFunction->NumberOfArguments != 1)) args_ok = 0;
......
......@@ -37,7 +37,7 @@ void output_temp(FILE *fp,int i)
return;
}
if (aType == VTK_PARSE_CHAR_PTR)
if ((aType == VTK_PARSE_CHAR_PTR) || (VTK_PARSE_STRING))
{
fprintf(fp,"String ");
}
......@@ -101,7 +101,10 @@ void return_result(FILE *fp)
case VTK_PARSE_UNSIGNED___INT64:
fprintf(fp,"int ");
break;
case VTK_PARSE_CHAR_PTR: fprintf(fp,"String "); break;
case VTK_PARSE_CHAR_PTR:
case VTK_PARSE_STRING:
fprintf(fp,"String ");
break;
case VTK_PARSE_VTK_OBJECT_PTR:
fprintf(fp,"%s ",currentFunction->ReturnClass);
break;
......@@ -358,6 +361,7 @@ void outputFunction(FILE *fp, FileInfo *data)
if (aType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0;
if (aType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0;
if (aType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0;
if ((aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNICODE_STRING) args_ok = 0;
}
if ((rType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNKNOWN) args_ok = 0;
if (rType == VTK_PARSE_VTK_OBJECT) args_ok = 0;
......@@ -373,6 +377,7 @@ void outputFunction(FILE *fp, FileInfo *data)
if (rType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0;
if (rType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0;
if (rType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0;
if ((rType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNICODE_STRING) args_ok = 0;
if (currentFunction->NumberOfArguments &&
(currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)
......@@ -487,7 +492,7 @@ void outputFunction(FILE *fp, FileInfo *data)
fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,",prop);
/* handle basic types */
if (aType == VTK_PARSE_CHAR_PTR)
if ((aType == VTK_PARSE_CHAR_PTR) || (aType == VTK_PARSE_STRING))
{
fprintf(fp," id0");
}
......
......@@ -39,7 +39,7 @@ void output_proto_vars(FILE *fp, int i)
return;
}
if (aType == VTK_PARSE_CHAR_PTR)
if ((aType == VTK_PARSE_CHAR_PTR) || (aType == VTK_PARSE_STRING))
{
fprintf(fp,"jstring ");
fprintf(fp,"id%i",i);
......@@ -205,7 +205,9 @@ void return_result(FILE *fp)
case VTK_PARSE_BOOL:
fprintf(fp,"jboolean ");
break;
case VTK_PARSE_CHAR_PTR: fprintf(fp,"jstring "); break;
case VTK_PARSE_CHAR_PTR:
case VTK_PARSE_STRING:
fprintf(fp,"jstring "); break;
case VTK_PARSE_VTK_OBJECT_PTR:
fprintf(fp,"jlong "); break;
......@@ -244,7 +246,9 @@ void output_temp(FILE *fp, int i, int aType, char *Id, int aCount)
}
/* for const * return types prototype with const */
if ((i == MAX_ARGS) && ((aType & VTK_PARSE_CONST) != 0))
if ((i == MAX_ARGS) &&
((aType & VTK_PARSE_INDIRECT) != 0) &&
((aType & VTK_PARSE_CONST) != 0))
{
fprintf(fp," const ");
}
......@@ -273,6 +277,7 @@ void output_temp(FILE *fp, int i, int aType, char *Id, int aCount)
case VTK_PARSE_SIGNED_CHAR: fprintf(fp,"signed char "); break;
case VTK_PARSE_BOOL: fprintf(fp,"bool "); break;
case VTK_PARSE_VTK_OBJECT: fprintf(fp,"%s ",Id); break;
case VTK_PARSE_STRING: fprintf(fp,"vtkStdString "); break;
case VTK_PARSE_UNKNOWN: return;
}
......@@ -347,6 +352,9 @@ void get_args(FILE *fp, int i)
case VTK_PARSE_CHAR_PTR:
fprintf(fp," temp%i = vtkJavaUTFToChar(env,id%i);\n",i,i);
break;
case VTK_PARSE_STRING:
fprintf(fp," vtkJavaUTFToString(env,id%i,temp%i);\n",i,i);
break;
case VTK_PARSE_VTK_OBJECT_PTR:
fprintf(fp," temp%i = (%s *)(vtkJavaGetPointerFromObject(env,id%i));\n",i,currentFunction->ArgClasses[i],i);
break;
......@@ -441,6 +449,7 @@ void do_return(FILE *fp)
switch (rType)
{
case VTK_PARSE_CHAR_PTR:
case VTK_PARSE_STRING:
{
fprintf(fp," return vtkJavaMakeJavaString(env,temp%i);\n",
MAX_ARGS);
......@@ -842,12 +851,14 @@ void outputFunction(FILE *fp, FileInfo *data)
if (aType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0;
if (aType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0;
if (aType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0;
if ((aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNICODE_STRING) args_ok = 0;
}
if ((rType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNKNOWN) args_ok = 0;
if (rType == VTK_PARSE_VTK_OBJECT) args_ok = 0;
if (((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) &&
((rType & VTK_PARSE_INDIRECT) != 0)) args_ok = 0;
if ((rType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_UNICODE_STRING) args_ok = 0;
/* eliminate unsigned short * usigned int * etc */
if (rType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment