//-*-c++-*- // SWIG Typemap library // for Java %typemap(java,jtype) char *STRING {String} %typemap(java,in) char *STRING { $target = JCALL(GetStringUTFChars, jenv) $source, 0); } %typemap(java,argout) char *STRING { JCALL(ReleaseStringUTFChars, jenv) $source, $target); } %typemap(java,out) char *STRING { $target = (jarray) JCALL(NewStringUTF, jenv) $source); } %typemap(java,jtype) char **STRING_IN {String[]} %typemap(java,jni) char **STRING_IN {jobjectArray} %typemap(java,in) char **STRING_IN { int i; jsize l = JCALL(GetArrayLength, jenv) $source); $target = (char **) malloc((l+1) * sizeof(char *)); for(i=0; i */ /* what type to use in java source code */ %typemap(java,jtype) const string & {String} /* what is the corresponding jni type */ %typemap(java,jni) const string & {jstring} /* how to convert the c++ type to the java type */ %typemap(java,out) const string & { $target = JCALL(NewStringUTF, jenv) $source->c_str()); } /* how to convert java type to requested c++ type */ %typemap(java,in) const string & { $target = NULL; if($source != NULL) { /* get the String from the StringBuffer */ char *p = (char *)jenv->GetStringUTFChars($source, 0); $target = new string(p); /* free(p); HdH assuming string constructor makes a copy */ JCALL(ReleaseStringUTFChars, jenv) $source, p); } } /* free resource once finished using */ %typemap(java,argout) const string & { delete $target; } %typemap(java,jtype) string & = const string &; %typemap(java,jni) string & = const string &; %typemap(java,in) string & = const string &; %typemap(java,out) string & = const string &; %typemap(java,argout) string & = const string &;