diff options
author | Dave Beazley <dave-swig@dabeaz.com> | 2001-12-10 21:46:21 +0000 |
---|---|---|
committer | Dave Beazley <dave-swig@dabeaz.com> | 2001-12-10 21:46:21 +0000 |
commit | acece98968ec45655940a1fdf8e41854a8991dbb (patch) | |
tree | 326ab02776bf7d2de0dd58d77cbaa28b71acd7bb /Examples/java/typemap | |
parent | 5d82053a3eeaa561cdc13931504ef0fc320a4cb5 (diff) | |
download | swig-acece98968ec45655940a1fdf8e41854a8991dbb.tar.gz |
arg!
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@2084 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/java/typemap')
-rw-r--r-- | Examples/java/typemap/example.i | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/Examples/java/typemap/example.i b/Examples/java/typemap/example.i deleted file mode 100644 index 348202225..000000000 --- a/Examples/java/typemap/example.i +++ /dev/null @@ -1,85 +0,0 @@ -/* File : example.i */ -%module example -%{ -/* Put headers and other declarations here */ - -/* - example of a function that returns a value in the char * argument - normally used like: - - char buf[bigenough]; - f1(buf); -*/ - -void f1(char *s) { - if(s != NULL) { - sprintf(s, "hello world"); - } -} - -void f2(char *s) { - return f1(s); -} - -void f3(char *s) { - return f1(s); -} - -%} - -/* default behaviour is that of input arg, besides java cannot return - a value in a string argument -*/ -void f1(char *s); - -%include typemaps.i - -/* use the BYTE typemap to get around this, but the resulting code is ugly */ -void f2(char *BYTE); - -/* make a StringBuffer typemap to handle this case */ - -/* what type to use in java source code */ -%typemap(java,jtype) char *SBUF {StringBuffer} - -/* what is the corresponding jni type */ -%typemap(java,jni) char *SBUF {jobject} - -/* how to convert java type to requested c type */ -%typemap(java,in) char *SBUF { - jclass sbufClass; - jmethodID toStringID; - jmethodID setLengthID; - jstring js; - - $target = NULL; - if($source != NULL) { - /* get the String from the StringBuffer */ - sbufClass = (*jenv)->GetObjectClass(jenv, $source); - toStringID = (*jenv)->GetMethodID(jenv, sbufClass, "toString", "()Ljava/lang/String;"); - js = (jstring) (*jenv)->CallObjectMethod(jenv, $source, toStringID); - /* convert the String to a char * */ - $target = (char *)(*jenv)->GetStringUTFChars(jenv, js, 0); - /* zero the original StringBuffer, so we can replace it with the result */ - setLengthID = (*jenv)->GetMethodID(jenv, sbufClass, "setLength", "(I)V"); - (*jenv)->CallVoidMethod(jenv, $source, setLengthID, (jint) 0); - } -} - -/* how to convert the c type to the java type */ -%typemap(java,argout) char *SBUF { - jclass sbufClass; - jmethodID appendStringID; - - if($target != NULL) { - /* append the result to the empty StringBuffer */ - sbufClass = (*jenv)->GetObjectClass(jenv, $source); - appendStringID = (*jenv)->GetMethodID(jenv, sbufClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;"); - (*jenv)->CallObjectMethod(jenv, $source, appendStringID, (*jenv)->NewStringUTF(jenv, $target)); - if($source != NULL) (*jenv)->ReleaseStringUTFChars(jenv, $source, $target); - } -} - -/* apply the new typemap to our function */ -void f3(char *SBUF); - |