The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
407
SWIG/Lib/java/arrays_java.i
Normal file
407
SWIG/Lib/java/arrays_java.i
Normal file
|
|
@ -0,0 +1,407 @@
|
|||
/* arrays_java.i
|
||||
* These typemaps give more natural support for arrays. The typemaps are not efficient
|
||||
* as there is a lot of copying of the array values whenever the array is passed to C/C++
|
||||
* from Java and visa versa.
|
||||
|
||||
Example usage:
|
||||
Wrapping:
|
||||
|
||||
%include "arrays_java.i"
|
||||
%inline %{
|
||||
short FiddleSticks[3];
|
||||
%}
|
||||
|
||||
Use from Java like this:
|
||||
|
||||
short[] fs = new short[] {10, 11, 12};
|
||||
example.setFiddleSticks(fs);
|
||||
fs = example.getFiddleSticks();
|
||||
|
||||
*/
|
||||
|
||||
/* Primitive array support is a combination of SWIG macros and functions in order to reduce
|
||||
* code bloat and aid maintainability. The SWIG preprocessor expands the macros into functions
|
||||
* for inclusion in the generated code. */
|
||||
|
||||
/* Array support functions declarations macro */
|
||||
%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
|
||||
%{
|
||||
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
|
||||
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
|
||||
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
|
||||
%}
|
||||
%enddef
|
||||
|
||||
/* Array support functions macro */
|
||||
%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
|
||||
%{
|
||||
/* CTYPE[] support */
|
||||
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
|
||||
int i;
|
||||
jsize sz;
|
||||
if (!input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
|
||||
return 0;
|
||||
}
|
||||
sz = JCALL1(GetArrayLength, jenv, input);
|
||||
*jarr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, input, 0);
|
||||
if (!*jarr)
|
||||
return 0; %}
|
||||
#if __cplusplus
|
||||
%{ *carr = new CTYPE[sz]; %}
|
||||
#else
|
||||
%{ *carr = (CTYPE*) calloc(sz, sizeof(CTYPE)); %}
|
||||
#endif
|
||||
%{ if (!*carr) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
|
||||
return 0;
|
||||
}
|
||||
for (i=0; i<sz; i++)
|
||||
JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input) {
|
||||
int i;
|
||||
jsize sz;
|
||||
sz = JCALL1(GetArrayLength, jenv, input);
|
||||
for (i=0; i<sz; i++)
|
||||
jarr[i] = (JNITYPE)carr[i];
|
||||
JCALL3(Release##JAVATYPE##ArrayElements, jenv, input, jarr, 0);
|
||||
}
|
||||
|
||||
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz) {
|
||||
JNITYPE *arr;
|
||||
int i;
|
||||
JNITYPE##Array jresult = JCALL1(New##JAVATYPE##Array, jenv, sz);
|
||||
if (!jresult)
|
||||
return NULL;
|
||||
arr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, jresult, 0);
|
||||
if (!arr)
|
||||
return NULL;
|
||||
for (i=0; i<sz; i++)
|
||||
arr[i] = (JNITYPE)result[i];
|
||||
JCALL3(Release##JAVATYPE##ArrayElements, jenv, jresult, arr, 0);
|
||||
return jresult;
|
||||
}
|
||||
%}
|
||||
%enddef
|
||||
|
||||
%{
|
||||
#if defined(SWIG_NOINCLUDE) || defined(SWIG_NOARRAYS)
|
||||
%}
|
||||
|
||||
#ifdef __cplusplus
|
||||
JAVA_ARRAYS_DECL(bool, jboolean, Boolean, Bool) /* bool[] */
|
||||
#endif
|
||||
|
||||
JAVA_ARRAYS_DECL(signed char, jbyte, Byte, Schar) /* signed char[] */
|
||||
JAVA_ARRAYS_DECL(unsigned char, jshort, Short, Uchar) /* unsigned char[] */
|
||||
JAVA_ARRAYS_DECL(short, jshort, Short, Short) /* short[] */
|
||||
JAVA_ARRAYS_DECL(unsigned short, jint, Int, Ushort) /* unsigned short[] */
|
||||
JAVA_ARRAYS_DECL(int, jint, Int, Int) /* int[] */
|
||||
JAVA_ARRAYS_DECL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
|
||||
JAVA_ARRAYS_DECL(long, jint, Int, Long) /* long[] */
|
||||
JAVA_ARRAYS_DECL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
|
||||
JAVA_ARRAYS_DECL(jlong, jlong, Long, Longlong) /* long long[] */
|
||||
JAVA_ARRAYS_DECL(float, jfloat, Float, Float) /* float[] */
|
||||
JAVA_ARRAYS_DECL(double, jdouble, Double, Double) /* double[] */
|
||||
|
||||
%{
|
||||
#else
|
||||
%}
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* Bool array element assignment different to other types to keep Visual C++ quiet */
|
||||
#define JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE) (*carr)[i] = ((*jarr)[i] != 0);
|
||||
JAVA_ARRAYS_IMPL(bool, jboolean, Boolean, Bool) /* bool[] */
|
||||
#undef JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN
|
||||
#endif
|
||||
|
||||
#define JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE) (*carr)[i] = (CTYPE)(*jarr)[i];
|
||||
JAVA_ARRAYS_IMPL(signed char, jbyte, Byte, Schar) /* signed char[] */
|
||||
JAVA_ARRAYS_IMPL(unsigned char, jshort, Short, Uchar) /* unsigned char[] */
|
||||
JAVA_ARRAYS_IMPL(short, jshort, Short, Short) /* short[] */
|
||||
JAVA_ARRAYS_IMPL(unsigned short, jint, Int, Ushort) /* unsigned short[] */
|
||||
JAVA_ARRAYS_IMPL(int, jint, Int, Int) /* int[] */
|
||||
JAVA_ARRAYS_IMPL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
|
||||
JAVA_ARRAYS_IMPL(long, jint, Int, Long) /* long[] */
|
||||
JAVA_ARRAYS_IMPL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
|
||||
JAVA_ARRAYS_IMPL(jlong, jlong, Long, Longlong) /* long long[] */
|
||||
JAVA_ARRAYS_IMPL(float, jfloat, Float, Float) /* float[] */
|
||||
JAVA_ARRAYS_IMPL(double, jdouble, Double, Double) /* double[] */
|
||||
|
||||
%{
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
||||
/* The rest of this file has the array typemaps */
|
||||
|
||||
/* Arrays of primitive types.
|
||||
* These typemaps are applied merely by including this file. */
|
||||
%typemap(jni) bool[ANY] "jbooleanArray"
|
||||
%typemap(jni) signed char[ANY] "jbyteArray"
|
||||
%typemap(jni) unsigned char[ANY] "jshortArray"
|
||||
%typemap(jni) short[ANY] "jshortArray"
|
||||
%typemap(jni) unsigned short[ANY] "jintArray"
|
||||
%typemap(jni) int[ANY] "jintArray"
|
||||
%typemap(jni) unsigned int[ANY] "jlongArray"
|
||||
%typemap(jni) long[ANY] "jintArray"
|
||||
%typemap(jni) unsigned long[ANY] "jlongArray"
|
||||
%typemap(jni) long long[ANY] "jlongArray"
|
||||
/*%typemap(jni) unsigned long long[ANY] "jobjectArray"*/
|
||||
%typemap(jni) float[ANY] "jfloatArray"
|
||||
%typemap(jni) double[ANY] "jdoubleArray"
|
||||
|
||||
%typemap(jtype) bool[ANY] "boolean[]"
|
||||
%typemap(jtype) signed char[ANY] "byte[]"
|
||||
%typemap(jtype) unsigned char[ANY] "short[]"
|
||||
%typemap(jtype) short[ANY] "short[]"
|
||||
%typemap(jtype) unsigned short[ANY] "int[]"
|
||||
%typemap(jtype) int[ANY] "int[]"
|
||||
%typemap(jtype) unsigned int[ANY] "long[]"
|
||||
%typemap(jtype) long[ANY] "int[]"
|
||||
%typemap(jtype) unsigned long[ANY] "long[]"
|
||||
%typemap(jtype) long long[ANY] "long[]"
|
||||
/*%typemap(jtype) unsigned long long[ANY] "java.math.BigInteger[]"*/
|
||||
%typemap(jtype) float[ANY] "float[]"
|
||||
%typemap(jtype) double[ANY] "double[]"
|
||||
|
||||
%typemap(jstype) bool[ANY] "boolean[]"
|
||||
%typemap(jstype) signed char[ANY] "byte[]"
|
||||
%typemap(jstype) unsigned char[ANY] "short[]"
|
||||
%typemap(jstype) short[ANY] "short[]"
|
||||
%typemap(jstype) unsigned short[ANY] "int[]"
|
||||
%typemap(jstype) int[ANY] "int[]"
|
||||
%typemap(jstype) unsigned int[ANY] "long[]"
|
||||
%typemap(jstype) long[ANY] "int[]"
|
||||
%typemap(jstype) unsigned long[ANY] "long[]"
|
||||
%typemap(jstype) long long[ANY] "long[]"
|
||||
/*%typemap(jstype) unsigned long long[ANY] "java.math.BigInteger[]"*/
|
||||
%typemap(jstype) float[ANY] "float[]"
|
||||
%typemap(jstype) double[ANY] "double[]"
|
||||
|
||||
/* Arrays of primitive types use the following macro. The array typemaps use support functions. */
|
||||
%define JAVA_ARRAYS_TYPEMAPS(CTYPE, JNITYPE, JFUNCNAME)
|
||||
|
||||
%typemap(in) CTYPE[ANY] (JNITYPE *jarr)
|
||||
%{ if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, &$1, $input)) return $null; %}
|
||||
%typemap(argout) CTYPE[ANY]
|
||||
%{ SWIG_JavaArrayArgout##JFUNCNAME(jenv, jarr$argnum, $1, $input); %}
|
||||
%typemap(out) CTYPE[ANY]
|
||||
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, $1, $1_dim0); %}
|
||||
%typemap(freearg) CTYPE[ANY]
|
||||
#ifdef __cplusplus
|
||||
%{ delete [] $1; %}
|
||||
#else
|
||||
%{ free($1); %}
|
||||
#endif
|
||||
|
||||
%enddef
|
||||
|
||||
JAVA_ARRAYS_TYPEMAPS(bool, jboolean, Bool) /* bool[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(signed char, jbyte, Schar) /* signed char[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(unsigned char, jshort, Uchar) /* unsigned char[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(short, jshort, Short) /* short[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(unsigned short, jint, Ushort) /* unsigned short[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(int, jint, Int) /* int[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(unsigned int, jlong, Uint) /* unsigned int[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(long, jint, Long) /* long[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(unsigned long, jlong, Ulong) /* unsigned long[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(long long, jlong, Longlong) /* long long[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(float, jfloat, Float) /* float[ANY] */
|
||||
JAVA_ARRAYS_TYPEMAPS(double, jdouble, Double) /* double[ANY] */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_BOOL_ARRAY) /* Java boolean[] */
|
||||
bool[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT8_ARRAY) /* Java byte[] */
|
||||
signed char[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT16_ARRAY) /* Java short[] */
|
||||
unsigned char[ANY],
|
||||
short[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT32_ARRAY) /* Java int[] */
|
||||
unsigned short[ANY],
|
||||
int[ANY],
|
||||
long[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT64_ARRAY) /* Java long[] */
|
||||
unsigned int[ANY],
|
||||
unsigned long[ANY],
|
||||
long long[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT128_ARRAY) /* Java BigInteger[] */
|
||||
unsigned long long[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) /* Java float[] */
|
||||
float[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) /* Java double[] */
|
||||
double[ANY]
|
||||
""
|
||||
|
||||
%typemap(javain) bool[ANY],
|
||||
signed char[ANY],
|
||||
unsigned char[ANY],
|
||||
short[ANY],
|
||||
unsigned short[ANY],
|
||||
int[ANY],
|
||||
unsigned int[ANY],
|
||||
long[ANY],
|
||||
unsigned long[ANY],
|
||||
long long[ANY],
|
||||
/* unsigned long long[ANY], */
|
||||
float[ANY],
|
||||
double[ANY]
|
||||
"$javainput"
|
||||
|
||||
%typemap(javaout) bool[ANY],
|
||||
signed char[ANY],
|
||||
unsigned char[ANY],
|
||||
short[ANY],
|
||||
unsigned short[ANY],
|
||||
int[ANY],
|
||||
unsigned int[ANY],
|
||||
long[ANY],
|
||||
unsigned long[ANY],
|
||||
long long[ANY],
|
||||
/* unsigned long long[ANY], */
|
||||
float[ANY],
|
||||
double[ANY] {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
|
||||
/* Arrays of proxy classes. The typemaps in this macro make it possible to treat an array of
|
||||
* class/struct/unions as an array of Java classes.
|
||||
* Use the following macro to use these typemaps for an array of class/struct/unions called name:
|
||||
* JAVA_ARRAYSOFCLASSES(name) */
|
||||
%define JAVA_ARRAYSOFCLASSES(ARRAYSOFCLASSES)
|
||||
|
||||
%typemap(jni) ARRAYSOFCLASSES[ANY] "jlongArray"
|
||||
%typemap(jtype) ARRAYSOFCLASSES[ANY] "long[]"
|
||||
%typemap(jstype) ARRAYSOFCLASSES[ANY] "$javaclassname[]"
|
||||
|
||||
%typemap(javain) ARRAYSOFCLASSES[ANY] "$javaclassname.cArrayUnwrap($javainput)"
|
||||
%typemap(javaout) ARRAYSOFCLASSES[ANY] {
|
||||
return $javaclassname.cArrayWrap($jnicall, $owner);
|
||||
}
|
||||
|
||||
%typemap(in) ARRAYSOFCLASSES[ANY] (jlong *jarr, jsize sz)
|
||||
{
|
||||
int i;
|
||||
if (!$input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
|
||||
return $null;
|
||||
}
|
||||
sz = JCALL1(GetArrayLength, jenv, $input);
|
||||
jarr = JCALL2(GetLongArrayElements, jenv, $input, 0);
|
||||
if (!jarr) {
|
||||
return $null;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
$1 = new $*1_ltype[sz];
|
||||
#else
|
||||
$1 = ($1_ltype) calloc(sz, sizeof($*1_ltype));
|
||||
#endif
|
||||
if (!$1) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
|
||||
return $null;
|
||||
}
|
||||
for (i=0; i<sz; i++) {
|
||||
$1[i] = **($&1_ltype)&jarr[i];
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(argout) ARRAYSOFCLASSES[ANY]
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<sz$argnum; i++) {
|
||||
jarr$argnum[i] = 0;
|
||||
*($&1_ltype)&jarr$argnum[i] = &$1[i];
|
||||
}
|
||||
JCALL3(ReleaseLongArrayElements, jenv, $input, jarr$argnum, 0);
|
||||
}
|
||||
|
||||
%typemap(out) ARRAYSOFCLASSES[ANY]
|
||||
{
|
||||
jlong *arr;
|
||||
int i;
|
||||
$result = JCALL1(NewLongArray, jenv, $1_dim0);
|
||||
if (!$result) {
|
||||
return $null;
|
||||
}
|
||||
arr = JCALL2(GetLongArrayElements, jenv, $result, 0);
|
||||
if (!arr) {
|
||||
return $null;
|
||||
}
|
||||
for (i=0; i<$1_dim0; i++) {
|
||||
arr[i] = 0;
|
||||
*($&1_ltype)&arr[i] = &$1[i];
|
||||
}
|
||||
JCALL3(ReleaseLongArrayElements, jenv, $result, arr, 0);
|
||||
}
|
||||
|
||||
%typemap(freearg) ARRAYSOFCLASSES[ANY]
|
||||
#ifdef __cplusplus
|
||||
%{ delete [] $1; %}
|
||||
#else
|
||||
%{ free($1); %}
|
||||
#endif
|
||||
|
||||
/* Add some code to the proxy class of the array type for converting between type used in
|
||||
* JNI class (long[]) and type used in proxy class ( ARRAYSOFCLASSES[] ) */
|
||||
%typemap(javacode) ARRAYSOFCLASSES %{
|
||||
protected static long[] cArrayUnwrap($javaclassname[] arrayWrapper) {
|
||||
long[] cArray = new long[arrayWrapper.length];
|
||||
for (int i=0; i<arrayWrapper.length; i++)
|
||||
cArray[i] = $javaclassname.getCPtr(arrayWrapper[i]);
|
||||
return cArray;
|
||||
}
|
||||
|
||||
protected static $javaclassname[] cArrayWrap(long[] cArray, boolean cMemoryOwn) {
|
||||
$javaclassname[] arrayWrapper = new $javaclassname[cArray.length];
|
||||
for (int i=0; i<cArray.length; i++)
|
||||
arrayWrapper[i] = new $javaclassname(cArray[i], cMemoryOwn);
|
||||
return arrayWrapper;
|
||||
}
|
||||
%}
|
||||
|
||||
%enddef /* JAVA_ARRAYSOFCLASSES */
|
||||
|
||||
|
||||
/* Arrays of enums.
|
||||
* Use the following to use these typemaps for an array of enums called name:
|
||||
* %apply ARRAYSOFENUMS[ANY] { name[ANY] }; */
|
||||
%typemap(jni) ARRAYSOFENUMS[ANY] "jintArray"
|
||||
%typemap(jtype) ARRAYSOFENUMS[ANY] "int[]"
|
||||
%typemap(jstype) ARRAYSOFENUMS[ANY] "int[]"
|
||||
|
||||
%typemap(javain) ARRAYSOFENUMS[ANY] "$javainput"
|
||||
%typemap(javaout) ARRAYSOFENUMS[ANY] {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%typemap(in) ARRAYSOFENUMS[ANY] (jint *jarr)
|
||||
%{ if (!SWIG_JavaArrayInInt(jenv, &jarr, (int**)&$1, $input)) return $null; %}
|
||||
%typemap(argout) ARRAYSOFENUMS[ANY]
|
||||
%{ SWIG_JavaArrayArgoutInt(jenv, jarr$argnum, (int*)$1, $input); %}
|
||||
%typemap(out) ARRAYSOFENUMS[ANY]
|
||||
%{$result = SWIG_JavaArrayOutInt(jenv, (int*)$1, $1_dim0); %}
|
||||
%typemap(freearg) ARRAYSOFENUMS[ANY]
|
||||
#ifdef __cplusplus
|
||||
%{ delete [] $1; %}
|
||||
#else
|
||||
%{ free($1); %}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,9 +1,700 @@
|
|||
#include <jni.h>
|
||||
#include <stdlib.h>
|
||||
/* -----------------------------------------------------------------------------
|
||||
* java.swg
|
||||
*
|
||||
* Java typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%include "javahead.swg"
|
||||
|
||||
/* The jni, jtype and jstype typemaps work together and so there should be one of each.
|
||||
* The jni typemap contains the JNI type used in the JNI (C/C++) code.
|
||||
* The jtype typemap contains the Java type used in the Java module class.
|
||||
* The jstype typemap contains the Java type used in the Java proxy class. */
|
||||
|
||||
/* Primitive types */
|
||||
%typemap(jni) bool, const bool & "jboolean"
|
||||
%typemap(jni) char, const char & "jchar"
|
||||
%typemap(jni) signed char, const signed char & "jbyte"
|
||||
%typemap(jni) unsigned char, const unsigned char & "jshort"
|
||||
%typemap(jni) short, const short & "jshort"
|
||||
%typemap(jni) unsigned short, const unsigned short & "jint"
|
||||
%typemap(jni) int, const int & "jint"
|
||||
%typemap(jni) unsigned int, const unsigned int & "jlong"
|
||||
%typemap(jni) long, const long & "jint"
|
||||
%typemap(jni) unsigned long, const unsigned long & "jlong"
|
||||
%typemap(jni) long long, const long long & "jlong"
|
||||
%typemap(jni) unsigned long long, const unsigned long long & "jobject"
|
||||
%typemap(jni) float, const float & "jfloat"
|
||||
%typemap(jni) double, const double & "jdouble"
|
||||
%typemap(jni) char * "jstring"
|
||||
%typemap(jni) void "void"
|
||||
|
||||
%typemap(jtype) bool, const bool & "boolean"
|
||||
%typemap(jtype) char, const char & "char"
|
||||
%typemap(jtype) signed char, const signed char & "byte"
|
||||
%typemap(jtype) unsigned char, const unsigned char & "short"
|
||||
%typemap(jtype) short, const short & "short"
|
||||
%typemap(jtype) unsigned short, const unsigned short & "int"
|
||||
%typemap(jtype) int, const int & "int"
|
||||
%typemap(jtype) unsigned int, const unsigned int & "long"
|
||||
%typemap(jtype) long, const long & "int"
|
||||
%typemap(jtype) unsigned long, const unsigned long & "long"
|
||||
%typemap(jtype) long long, const long long & "long"
|
||||
%typemap(jtype) unsigned long long, const unsigned long long & "java.math.BigInteger"
|
||||
%typemap(jtype) float, const float & "float"
|
||||
%typemap(jtype) double, const double & "double"
|
||||
%typemap(jtype) char * "String"
|
||||
%typemap(jtype) void "void"
|
||||
|
||||
%typemap(jstype) bool, const bool & "boolean"
|
||||
%typemap(jstype) char, const char & "char"
|
||||
%typemap(jstype) signed char, const signed char & "byte"
|
||||
%typemap(jstype) unsigned char, const unsigned char & "short"
|
||||
%typemap(jstype) short, const short & "short"
|
||||
%typemap(jstype) unsigned short, const unsigned short & "int"
|
||||
%typemap(jstype) int, const int & "int"
|
||||
%typemap(jstype) unsigned int, const unsigned int & "long"
|
||||
%typemap(jstype) long, const long & "int"
|
||||
%typemap(jstype) unsigned long, const unsigned long & "long"
|
||||
%typemap(jstype) long long, const long long & "long"
|
||||
%typemap(jstype) unsigned long long, const unsigned long long & "java.math.BigInteger"
|
||||
%typemap(jstype) float, const float & "float"
|
||||
%typemap(jstype) double, const double & "double"
|
||||
%typemap(jstype) char * "String"
|
||||
%typemap(jstype) void "void"
|
||||
|
||||
%typemap(jni) char[ANY] "jstring"
|
||||
%typemap(jtype) char[ANY] "String"
|
||||
%typemap(jstype) char[ANY] "String"
|
||||
|
||||
/* JNI types */
|
||||
%typemap(jni) jboolean "jboolean"
|
||||
%typemap(jni) jchar "jchar"
|
||||
%typemap(jni) jbyte "jbyte"
|
||||
%typemap(jni) jshort "jshort"
|
||||
%typemap(jni) jint "jint"
|
||||
%typemap(jni) jlong "jlong"
|
||||
%typemap(jni) jfloat "jfloat"
|
||||
%typemap(jni) jdouble "jdouble"
|
||||
%typemap(jni) jstring "jstring"
|
||||
%typemap(jni) jobject "jobject"
|
||||
%typemap(jni) jbooleanArray "jbooleanArray"
|
||||
%typemap(jni) jcharArray "jcharArray"
|
||||
%typemap(jni) jbyteArray "jbyteArray"
|
||||
%typemap(jni) jshortArray "jshortArray"
|
||||
%typemap(jni) jintArray "jintArray"
|
||||
%typemap(jni) jlongArray "jlongArray"
|
||||
%typemap(jni) jfloatArray "jfloatArray"
|
||||
%typemap(jni) jdoubleArray "jdoubleArray"
|
||||
%typemap(jni) jobjectArray "jobjectArray"
|
||||
|
||||
%typemap(jtype) jboolean "boolean"
|
||||
%typemap(jtype) jchar "char"
|
||||
%typemap(jtype) jbyte "byte"
|
||||
%typemap(jtype) jshort "short"
|
||||
%typemap(jtype) jint "int"
|
||||
%typemap(jtype) jlong "long"
|
||||
%typemap(jtype) jfloat "float"
|
||||
%typemap(jtype) jdouble "double"
|
||||
%typemap(jtype) jstring "String"
|
||||
%typemap(jtype) jobject "Object"
|
||||
%typemap(jtype) jbooleanArray "boolean[]"
|
||||
%typemap(jtype) jcharArray "char[]"
|
||||
%typemap(jtype) jbyteArray "byte[]"
|
||||
%typemap(jtype) jshortArray "short[]"
|
||||
%typemap(jtype) jintArray "int[]"
|
||||
%typemap(jtype) jlongArray "long[]"
|
||||
%typemap(jtype) jfloatArray "float[]"
|
||||
%typemap(jtype) jdoubleArray "double[]"
|
||||
%typemap(jtype) jobjectArray "Object[]"
|
||||
|
||||
%typemap(jstype) jboolean "boolean"
|
||||
%typemap(jstype) jchar "char"
|
||||
%typemap(jstype) jbyte "byte"
|
||||
%typemap(jstype) jshort "short"
|
||||
%typemap(jstype) jint "int"
|
||||
%typemap(jstype) jlong "long"
|
||||
%typemap(jstype) jfloat "float"
|
||||
%typemap(jstype) jdouble "double"
|
||||
%typemap(jstype) jstring "String"
|
||||
%typemap(jstype) jobject "Object"
|
||||
%typemap(jstype) jbooleanArray "boolean[]"
|
||||
%typemap(jstype) jcharArray "char[]"
|
||||
%typemap(jstype) jbyteArray "byte[]"
|
||||
%typemap(jstype) jshortArray "short[]"
|
||||
%typemap(jstype) jintArray "int[]"
|
||||
%typemap(jstype) jlongArray "long[]"
|
||||
%typemap(jstype) jfloatArray "float[]"
|
||||
%typemap(jstype) jdoubleArray "double[]"
|
||||
%typemap(jstype) jobjectArray "Object[]"
|
||||
|
||||
/* Non primitive types */
|
||||
%typemap(jni) SWIGTYPE "jlong"
|
||||
%typemap(jtype) SWIGTYPE "long"
|
||||
%typemap(jstype) SWIGTYPE "$&javaclassname"
|
||||
|
||||
%typemap(jni) SWIGTYPE [] "jlong"
|
||||
%typemap(jtype) SWIGTYPE [] "long"
|
||||
%typemap(jstype) SWIGTYPE [] "$javaclassname"
|
||||
|
||||
%typemap(jni) SWIGTYPE * "jlong"
|
||||
%typemap(jtype) SWIGTYPE * "long"
|
||||
%typemap(jstype) SWIGTYPE * "$javaclassname"
|
||||
|
||||
%typemap(jni) SWIGTYPE & "jlong"
|
||||
%typemap(jtype) SWIGTYPE & "long"
|
||||
%typemap(jstype) SWIGTYPE & "$javaclassname"
|
||||
|
||||
%typemap(jni) enum SWIGTYPE "jint"
|
||||
%typemap(jtype) enum SWIGTYPE "int"
|
||||
%typemap(jstype) enum SWIGTYPE "int"
|
||||
|
||||
/* pointer to a class member */
|
||||
%typemap(jni) SWIGTYPE (CLASS::*) "jlong"
|
||||
%typemap(jtype) SWIGTYPE (CLASS::*) "long"
|
||||
%typemap(jstype) SWIGTYPE (CLASS::*) "$javaclassname"
|
||||
|
||||
/* The following are the in, out, freearg, argout typemaps. These are the JNI code generating typemaps for converting from Java to C and visa versa. */
|
||||
|
||||
/* primitive types */
|
||||
%typemap(in) bool,
|
||||
char,
|
||||
signed char,
|
||||
unsigned char,
|
||||
short,
|
||||
unsigned short,
|
||||
int,
|
||||
unsigned int,
|
||||
long,
|
||||
unsigned long,
|
||||
long long,
|
||||
float,
|
||||
double,
|
||||
enum SWIGTYPE
|
||||
%{ $1 = ($1_ltype)$input; %}
|
||||
|
||||
%typemap(out) bool %{ $result = (jboolean)$1; %}
|
||||
%typemap(out) char %{ $result = (jchar)$1; %}
|
||||
%typemap(out) signed char %{ $result = (jbyte)$1; %}
|
||||
%typemap(out) unsigned char %{ $result = (jshort)$1; %}
|
||||
%typemap(out) short %{ $result = (jshort)$1; %}
|
||||
%typemap(out) unsigned short %{ $result = (jint)$1; %}
|
||||
%typemap(out) int %{ $result = (jint)$1; %}
|
||||
%typemap(out) unsigned int %{ $result = (jlong)$1; %}
|
||||
%typemap(out) long %{ $result = (jint)$1; %}
|
||||
%typemap(out) unsigned long %{ $result = (jlong)$1; %}
|
||||
%typemap(out) long long %{ $result = (jlong)$1; %}
|
||||
%typemap(out) float %{ $result = (jfloat)$1; %}
|
||||
%typemap(out) double %{ $result = (jdouble)$1; %}
|
||||
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
|
||||
|
||||
|
||||
/* unsigned long long */
|
||||
/* Convert from BigInteger using the toByteArray member function */
|
||||
%typemap(in) unsigned long long {
|
||||
jclass clazz;
|
||||
jmethodID mid;
|
||||
jbyteArray ba;
|
||||
jbyte* bae;
|
||||
jsize sz;
|
||||
int i;
|
||||
|
||||
if (!$input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
|
||||
return $null;
|
||||
}
|
||||
clazz = JCALL1(GetObjectClass, jenv, $input);
|
||||
mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
|
||||
ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
|
||||
bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
|
||||
sz = JCALL1(GetArrayLength, jenv, ba);
|
||||
$1 = 0;
|
||||
if (bae[0] == 0) {
|
||||
for(i=sz-1; i>0; i-- ) {
|
||||
$1 = ($1 << 8) | (unsigned char)bae[sz-i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i=sz; i>=0; i-- ) {
|
||||
$1 = ($1 << 8) | (unsigned char)bae[sz-1-i];
|
||||
}
|
||||
}
|
||||
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
|
||||
}
|
||||
|
||||
/* Convert to BigInteger - byte array holds number in 2's complement big endian format */
|
||||
%typemap(out) unsigned long long {
|
||||
jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
|
||||
jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
|
||||
jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
|
||||
jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V");
|
||||
jobject bigint;
|
||||
int i;
|
||||
|
||||
bae[0] = 0;
|
||||
for(i=1; i<9; i++ ) {
|
||||
bae[i] = (jbyte)($1>>8*(8-i));
|
||||
}
|
||||
|
||||
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
|
||||
bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
|
||||
$result = bigint;
|
||||
}
|
||||
|
||||
/* char * - treat as String */
|
||||
%typemap(in) char * {
|
||||
$1 = 0;
|
||||
if ($input) {
|
||||
$1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
|
||||
if (!$1) return $null;
|
||||
}
|
||||
}
|
||||
%typemap(freearg) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); }
|
||||
%typemap(out) char * { if($1) $result = JCALL1(NewStringUTF, jenv, $1); }
|
||||
|
||||
%typemap(out) void ""
|
||||
|
||||
/* primitive types by reference */
|
||||
%typemap(in) const bool & (bool temp),
|
||||
const char & (char temp),
|
||||
const signed char & (signed char temp),
|
||||
const unsigned char & (unsigned char temp),
|
||||
const short & (short temp),
|
||||
const unsigned short & (unsigned short temp),
|
||||
const int & (int temp),
|
||||
const unsigned int & (unsigned int temp),
|
||||
const long & (long temp),
|
||||
const unsigned long & (unsigned long temp),
|
||||
const long long & (long long temp),
|
||||
const float & (float temp),
|
||||
const double & (double temp)
|
||||
%{ temp = ($*1_ltype)$input;
|
||||
$1 = &temp; %}
|
||||
|
||||
%typemap(out) const bool & %{ $result = (jboolean)*$1; %}
|
||||
%typemap(out) const char & %{ $result = (jchar)*$1; %}
|
||||
%typemap(out) const signed char & %{ $result = (jbyte)*$1; %}
|
||||
%typemap(out) const unsigned char & %{ $result = (jshort)*$1; %}
|
||||
%typemap(out) const short & %{ $result = (jshort)*$1; %}
|
||||
%typemap(out) const unsigned short & %{ $result = (jint)*$1; %}
|
||||
%typemap(out) const int & %{ $result = (jint)*$1; %}
|
||||
%typemap(out) const unsigned int & %{ $result = (jlong)*$1; %}
|
||||
%typemap(out) const long & %{ $result = (jint)*$1; %}
|
||||
%typemap(out) const unsigned long & %{ $result = (jlong)*$1; %}
|
||||
%typemap(out) const long long & %{ $result = (jlong)*$1; %}
|
||||
%typemap(out) const float & %{ $result = (jfloat)*$1; %}
|
||||
%typemap(out) const double & %{ $result = (jdouble)*$1; %}
|
||||
|
||||
/* const unsigned long long & */
|
||||
/* Similar to unsigned long long */
|
||||
%typemap(in) const unsigned long long & (unsigned long long temp) {
|
||||
jclass clazz;
|
||||
jmethodID mid;
|
||||
jbyteArray ba;
|
||||
jbyte* bae;
|
||||
jsize sz;
|
||||
int i;
|
||||
|
||||
if (!$input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
|
||||
return $null;
|
||||
}
|
||||
clazz = JCALL1(GetObjectClass, jenv, $input);
|
||||
mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
|
||||
ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
|
||||
bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
|
||||
sz = JCALL1(GetArrayLength, jenv, ba);
|
||||
$1 = &temp;
|
||||
temp = 0;
|
||||
if (bae[0] == 0) {
|
||||
for(i=sz-1; i>0; i-- ) {
|
||||
temp = (temp << 8) | (unsigned char)bae[sz-i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i=sz; i>=0; i-- ) {
|
||||
temp = (temp << 8) | (unsigned char)bae[sz-1-i];
|
||||
}
|
||||
}
|
||||
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
|
||||
}
|
||||
|
||||
%typemap(out) const unsigned long long & {
|
||||
jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
|
||||
jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
|
||||
jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
|
||||
jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V");
|
||||
jobject bigint;
|
||||
int i;
|
||||
|
||||
bae[0] = 0;
|
||||
for(i=1; i<9; i++ ) {
|
||||
bae[i] = (jbyte)(*$1>>8*(8-i));
|
||||
}
|
||||
|
||||
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
|
||||
bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
|
||||
$result = bigint;
|
||||
}
|
||||
|
||||
/* Default handling. Object passed by value. Convert to a pointer */
|
||||
%typemap(in) SWIGTYPE ($&1_type argp)
|
||||
%{ argp = *($&1_ltype*)&$input;
|
||||
if (!argp) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
|
||||
return $null;
|
||||
}
|
||||
$1 = *argp; %}
|
||||
%typemap(out) SWIGTYPE
|
||||
#ifdef __cplusplus
|
||||
#define JCALL(func, jenv) jenv->func(
|
||||
%{$&1_ltype $1ptr = new $1_ltype(($1_ltype &)$1);
|
||||
*($&1_ltype*)&$result = $1ptr; %}
|
||||
#else
|
||||
#define JCALL(func, jenv) (*jenv)->func(jenv,
|
||||
{
|
||||
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
|
||||
memmove($1ptr, &$1, sizeof($1_type));
|
||||
*($&1_ltype*)&$result = $1ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Generic pointers and references */
|
||||
%typemap(in) SWIGTYPE *, SWIGTYPE (CLASS::*) %{ $1 = *($&1_ltype)&$input; %}
|
||||
%typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input;
|
||||
if(!$1) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
|
||||
return $null;
|
||||
} %}
|
||||
%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE (CLASS::*) %{ *($&1_ltype)&$result = $1; %}
|
||||
|
||||
|
||||
/* Default array handling */
|
||||
%typemap(in) SWIGTYPE [] %{ $1 = *($&1_ltype)&$input; %}
|
||||
%typemap(out) SWIGTYPE [] %{ *($&1_ltype)&$result = $1; %}
|
||||
|
||||
/* char[ANY] - treat as String */
|
||||
%typemap(in) char[ANY] {
|
||||
$1 = 0;
|
||||
if ($input) {
|
||||
$1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
|
||||
if (!$1) return $null;
|
||||
}
|
||||
}
|
||||
%typemap(argout) char[ANY] ""
|
||||
%typemap(freearg) char[ANY] { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); }
|
||||
%typemap(out) char[ANY] { if($1) $result = JCALL1(NewStringUTF, jenv, $1); }
|
||||
|
||||
/* JNI types */
|
||||
%typemap(in) jboolean,
|
||||
jchar,
|
||||
jbyte,
|
||||
jshort,
|
||||
jint,
|
||||
jlong,
|
||||
jfloat,
|
||||
jdouble,
|
||||
jstring,
|
||||
jobject,
|
||||
jbooleanArray,
|
||||
jcharArray,
|
||||
jbyteArray,
|
||||
jshortArray,
|
||||
jintArray,
|
||||
jlongArray,
|
||||
jfloatArray,
|
||||
jdoubleArray,
|
||||
jobjectArray
|
||||
%{ $1 = $input; %}
|
||||
|
||||
%typemap(out) jboolean,
|
||||
jchar,
|
||||
jbyte,
|
||||
jshort,
|
||||
jint,
|
||||
jlong,
|
||||
jfloat,
|
||||
jdouble,
|
||||
jstring,
|
||||
jobject,
|
||||
jbooleanArray,
|
||||
jcharArray,
|
||||
jbyteArray,
|
||||
jshortArray,
|
||||
jintArray,
|
||||
jlongArray,
|
||||
jfloatArray,
|
||||
jdoubleArray,
|
||||
jobjectArray
|
||||
%{ $result = $1; %}
|
||||
|
||||
|
||||
/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions
|
||||
* that cannot be overloaded in Java as more than one C++ type maps to a single Java type */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_BOOL) /* Java boolean */
|
||||
jboolean,
|
||||
bool,
|
||||
const bool &
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_CHAR) /* Java char */
|
||||
jchar,
|
||||
char,
|
||||
const char &
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT8) /* Java byte */
|
||||
jbyte,
|
||||
signed char,
|
||||
const signed char &
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT16) /* Java short */
|
||||
jshort,
|
||||
unsigned char,
|
||||
short,
|
||||
const unsigned char &,
|
||||
const short &
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT32) /* Java int */
|
||||
jint,
|
||||
unsigned short,
|
||||
int,
|
||||
long,
|
||||
const unsigned short &,
|
||||
const int &,
|
||||
const long &,
|
||||
enum SWIGTYPE
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT64) /* Java long */
|
||||
jlong,
|
||||
unsigned int,
|
||||
unsigned long,
|
||||
long long,
|
||||
const unsigned int &,
|
||||
const unsigned long &,
|
||||
const long long &
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT128) /* Java BigInteger */
|
||||
unsigned long long
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_FLOAT) /* Java float */
|
||||
jfloat,
|
||||
float,
|
||||
const float &
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE) /* Java double */
|
||||
jdouble,
|
||||
double,
|
||||
const double &
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_STRING) /* Java String */
|
||||
jstring,
|
||||
char *,
|
||||
char[ANY]
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_BOOL_ARRAY) /* Java boolean[] */
|
||||
jbooleanArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_CHAR_ARRAY) /* Java char[] */
|
||||
jcharArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT8_ARRAY) /* Java byte[] */
|
||||
jbyteArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT16_ARRAY) /* Java short[] */
|
||||
jshortArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT32_ARRAY) /* Java int[] */
|
||||
jintArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT64_ARRAY) /* Java long[] */
|
||||
jlongArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) /* Java float[] */
|
||||
jfloatArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) /* Java double[] */
|
||||
jdoubleArray
|
||||
""
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) /* Default */
|
||||
SWIGTYPE,
|
||||
SWIGTYPE *,
|
||||
SWIGTYPE &,
|
||||
SWIGTYPE [],
|
||||
SWIGTYPE (CLASS::*)
|
||||
""
|
||||
|
||||
|
||||
/* Exception handling */
|
||||
|
||||
%typemap(throws) int,
|
||||
long,
|
||||
short,
|
||||
unsigned int,
|
||||
unsigned long,
|
||||
unsigned short {
|
||||
char error_msg[256];
|
||||
sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, error_msg);
|
||||
return $null;
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
}
|
||||
|
||||
%typemap(throws) char * {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1);
|
||||
return $null;
|
||||
}
|
||||
|
||||
|
||||
/* Typemaps for code generation in proxy classes and Java type wrapper classes */
|
||||
|
||||
/* The javain typemap is used for converting function parameter types from the type
|
||||
* used in the proxy, module or type wrapper class to the type used in the JNI class. */
|
||||
%typemap(javain) bool, const bool &,
|
||||
char, const char &,
|
||||
signed char, const signed char &,
|
||||
unsigned char, const unsigned char &,
|
||||
short, const short &,
|
||||
unsigned short, const unsigned short &,
|
||||
int, const int &,
|
||||
unsigned int, const unsigned int &,
|
||||
long, const long &,
|
||||
unsigned long, const unsigned long &,
|
||||
long long, const long long &,
|
||||
unsigned long long, const unsigned long long &,
|
||||
float, const float &,
|
||||
double, const double &,
|
||||
char *,
|
||||
char[ANY],
|
||||
enum SWIGTYPE
|
||||
"$javainput"
|
||||
%typemap(javain) jboolean,
|
||||
jchar,
|
||||
jbyte,
|
||||
jshort,
|
||||
jint,
|
||||
jlong,
|
||||
jfloat,
|
||||
jdouble,
|
||||
jstring,
|
||||
jobject,
|
||||
jbooleanArray,
|
||||
jcharArray,
|
||||
jbyteArray,
|
||||
jshortArray,
|
||||
jintArray,
|
||||
jlongArray,
|
||||
jfloatArray,
|
||||
jdoubleArray,
|
||||
jobjectArray
|
||||
"$javainput"
|
||||
%typemap(javain) SWIGTYPE "$&javaclassname.getCPtr($javainput)"
|
||||
%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "$javaclassname.getCPtr($javainput)"
|
||||
|
||||
/* The javaout typemap is used for converting function return types from the return type
|
||||
* used in the JNI class to the type returned by the proxy, module or type wrapper class. */
|
||||
%typemap(javaout) bool, const bool &,
|
||||
char, const char &,
|
||||
signed char, const signed char &,
|
||||
unsigned char, const unsigned char &,
|
||||
short, const short &,
|
||||
unsigned short, const unsigned short &,
|
||||
int, const int &,
|
||||
unsigned int, const unsigned int &,
|
||||
long, const long &,
|
||||
unsigned long, const unsigned long &,
|
||||
long long, const long long &,
|
||||
unsigned long long, const unsigned long long &,
|
||||
float, const float &,
|
||||
double, const double &,
|
||||
char *,
|
||||
char[ANY],
|
||||
enum SWIGTYPE {
|
||||
return $jnicall;
|
||||
}
|
||||
%typemap(javaout) jboolean,
|
||||
jchar,
|
||||
jbyte,
|
||||
jshort,
|
||||
jint,
|
||||
jlong,
|
||||
jfloat,
|
||||
jdouble,
|
||||
jstring,
|
||||
jobject,
|
||||
jbooleanArray,
|
||||
jcharArray,
|
||||
jbyteArray,
|
||||
jshortArray,
|
||||
jintArray,
|
||||
jlongArray,
|
||||
jfloatArray,
|
||||
jdoubleArray,
|
||||
jobjectArray {
|
||||
return $jnicall;
|
||||
}
|
||||
%typemap(javaout) void {
|
||||
$jnicall;
|
||||
}
|
||||
%typemap(javaout) SWIGTYPE {
|
||||
return new $&javaclassname($jnicall, true);
|
||||
}
|
||||
%typemap(javaout) SWIGTYPE & {
|
||||
return new $javaclassname($jnicall, $owner);
|
||||
}
|
||||
%typemap(javaout) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new $javaclassname(cPtr, $owner);
|
||||
}
|
||||
|
||||
/* Typemaps used for the generation of proxy and type wrapper class code */
|
||||
%typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||
%typemap(javaclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public"
|
||||
%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||
%typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||
%typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
|
||||
%typemap(javaptrconstructormodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "protected"
|
||||
|
||||
%typemap(javafinalize) SWIGTYPE %{
|
||||
protected void finalize() {
|
||||
delete();
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(javagetcptr) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
|
||||
protected static long getCPtr($javaclassname obj) {
|
||||
return (obj == null) ? 0 : obj.swigCPtr;
|
||||
}
|
||||
%}
|
||||
|
||||
/* Java specific directives */
|
||||
#define %javaconst(flag) %feature("java:const","flag")
|
||||
#define %javamethodmodifiers %feature("java:methodmodifiers")
|
||||
|
||||
%javamethodmodifiers "public";
|
||||
|
||||
|
||||
/* Some ANSI C typemaps */
|
||||
|
||||
%apply long { size_t };
|
||||
|
||||
|
|
|
|||
84
SWIG/Lib/java/javahead.swg
Normal file
84
SWIG/Lib/java/javahead.swg
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* javahead.swg
|
||||
*
|
||||
* Java support code
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* JNI function calls require different calling conventions for C and C++. These JCALL macros are used so
|
||||
* that the same typemaps can be used for generating code for both C and C++. The SWIG preprocessor can expand
|
||||
* the macros thereby generating the correct calling convention. It is thus essential that all typemaps that
|
||||
* use the macros are not within %{ %} brackets as they won't be run through the SWIG preprocessor. */
|
||||
#ifdef __cplusplus
|
||||
# define JCALL0(func, jenv) jenv->func()
|
||||
# define JCALL1(func, jenv, ar1) jenv->func(ar1)
|
||||
# define JCALL2(func, jenv, ar1, ar2) jenv->func(ar1, ar2)
|
||||
# define JCALL3(func, jenv, ar1, ar2, ar3) jenv->func(ar1, ar2, ar3)
|
||||
# define JCALL4(func, jenv, ar1, ar2, ar3, ar4) jenv->func(ar1, ar2, ar3, ar4)
|
||||
#else
|
||||
# define JCALL0(func, jenv) (*jenv)->func(jenv)
|
||||
# define JCALL1(func, jenv, ar1) (*jenv)->func(jenv, ar1)
|
||||
# define JCALL2(func, jenv, ar1, ar2) (*jenv)->func(jenv, ar1, ar2)
|
||||
# define JCALL3(func, jenv, ar1, ar2, ar3) (*jenv)->func(jenv, ar1, ar2, ar3)
|
||||
# define JCALL4(func, jenv, ar1, ar2, ar3, ar4) (*jenv)->func(jenv, ar1, ar2, ar3, ar4)
|
||||
#endif
|
||||
|
||||
%insert(runtime) %{
|
||||
#if defined(__GNUC__)
|
||||
typedef long long __int64; /*For gcc on Windows */
|
||||
#endif
|
||||
#include <jni.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
/* Support for throwing Java exceptions */
|
||||
typedef enum {
|
||||
SWIG_JavaOutOfMemoryError = 1,
|
||||
SWIG_JavaIOException,
|
||||
SWIG_JavaRuntimeException,
|
||||
SWIG_JavaIndexOutOfBoundsException,
|
||||
SWIG_JavaArithmeticException,
|
||||
SWIG_JavaIllegalArgumentException,
|
||||
SWIG_JavaNullPointerException,
|
||||
SWIG_JavaUnknownError
|
||||
} SWIG_JavaExceptionCodes;
|
||||
|
||||
typedef struct {
|
||||
SWIG_JavaExceptionCodes code;
|
||||
const char *java_exception;
|
||||
} SWIG_JavaExceptions_t;
|
||||
|
||||
#if defined(SWIG_NOINCLUDE)
|
||||
void SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg);
|
||||
#else
|
||||
%}
|
||||
%insert(runtime) {
|
||||
void SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
|
||||
jclass excep;
|
||||
static const SWIG_JavaExceptions_t java_exceptions[] = {
|
||||
{ SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
|
||||
{ SWIG_JavaIOException, "java/io/IOException" },
|
||||
{ SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
|
||||
{ SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
|
||||
{ SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
|
||||
{ SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
|
||||
{ SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
|
||||
{ SWIG_JavaUnknownError, "java/lang/UnknownError" },
|
||||
{ (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" } };
|
||||
const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
|
||||
|
||||
while (except_ptr->code != code && except_ptr->code)
|
||||
except_ptr++;
|
||||
|
||||
JCALL0(ExceptionClear, jenv);
|
||||
excep = JCALL1(FindClass, jenv, except_ptr->java_exception);
|
||||
if (excep)
|
||||
JCALL2(ThrowNew, jenv, excep, msg);
|
||||
}
|
||||
}
|
||||
%insert(runtime) %{
|
||||
#endif
|
||||
%}
|
||||
|
||||
183
SWIG/Lib/java/std_string.i
Normal file
183
SWIG/Lib/java/std_string.i
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
//
|
||||
// SWIG typemaps for std::string
|
||||
// Luigi Ballabio, Tal Shalif and William Fulton
|
||||
// May 7, 2002
|
||||
//
|
||||
// Java implementation
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
// These are mapped to a Java String and are passed around by value.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%include exception.i
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
// std::string
|
||||
%typemap(jni) std::string "jstring"
|
||||
%typemap(jtype) std::string "String"
|
||||
%typemap(jstype) std::string "String"
|
||||
|
||||
%typemap(in) std::string
|
||||
%{if($input) {
|
||||
const char *pstr = (const char *)jenv->GetStringUTFChars($input, 0);
|
||||
if (!pstr) return $null;
|
||||
$1 = std::string(pstr);
|
||||
jenv->ReleaseStringUTFChars($input, pstr);
|
||||
}
|
||||
else {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
|
||||
return $null;
|
||||
} %}
|
||||
|
||||
%typemap(out) std::string
|
||||
%{ $result = jenv->NewStringUTF($1.c_str()); %}
|
||||
|
||||
%typemap(javain) std::string "$javainput"
|
||||
|
||||
%typemap(javaout) std::string {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%typemap(typecheck) std::string = char *;
|
||||
|
||||
// const std::string &
|
||||
%typemap(jni) const std::string & "jstring"
|
||||
%typemap(jtype) const std::string & "String"
|
||||
%typemap(jstype) const std::string & "String"
|
||||
|
||||
%typemap(in) const std::string &
|
||||
%{$1 = NULL;
|
||||
if($input) {
|
||||
const char *pstr = (const char *)jenv->GetStringUTFChars($input, 0);
|
||||
if (!pstr) return $null;
|
||||
$1 = new std::string(pstr);
|
||||
jenv->ReleaseStringUTFChars($input, pstr);
|
||||
}
|
||||
else {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
|
||||
return $null;
|
||||
} %}
|
||||
|
||||
%typemap(freearg) const std::string &
|
||||
%{ delete $1; %}
|
||||
|
||||
%typemap(out) const std::string &
|
||||
%{ $result = jenv->NewStringUTF($1->c_str()); %}
|
||||
|
||||
%typemap(javain) const std::string & "$javainput"
|
||||
|
||||
%typemap(javaout) const std::string & {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%typemap(typecheck) const std::string & = char *;
|
||||
|
||||
// For using std::string in the global namespace
|
||||
%apply const std::string & {const string &};
|
||||
%apply std::string {string};
|
||||
|
||||
/* To use non-const std::string references use the following %apply. Note that they are passed by value.
|
||||
// std::string &
|
||||
%apply const std::string & {std::string &};
|
||||
%apply std::string & {string &};
|
||||
*/
|
||||
|
||||
#ifdef SWIGJAVA_WSTRING
|
||||
// Warning: Unicode / multibyte characters are handled differently on different OSs so the std::wstring
|
||||
// typemaps may not always work as intended. Therefore a #define is required to use them.
|
||||
// std::wstring
|
||||
%typemap(jni) std::wstring "jstring"
|
||||
%typemap(jtype) std::wstring "String"
|
||||
%typemap(jstype) std::wstring "String"
|
||||
|
||||
%typemap(in) std::wstring
|
||||
%{if($input) {
|
||||
const jchar *pstr = jenv->GetStringChars($input, 0);
|
||||
if (!pstr) return $null;
|
||||
jsize len = jenv->GetStringLength($input);
|
||||
if (len) {
|
||||
wchar_t *conv_buf = new wchar_t[len];
|
||||
for (jsize i = 0; i < len; ++i) {
|
||||
conv_buf[i] = pstr[i];
|
||||
}
|
||||
$1 = std::wstring(conv_buf, len);
|
||||
delete [] conv_buf;
|
||||
}
|
||||
jenv->ReleaseStringChars($input, pstr);
|
||||
}
|
||||
else {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
|
||||
return $null;
|
||||
} %}
|
||||
|
||||
%typemap(out) std::wstring
|
||||
%{jsize len = $1.length();
|
||||
jchar *conv_buf = new jchar[len];
|
||||
for (jsize i = 0; i < len; ++i) {
|
||||
conv_buf[i] = (jchar)$1[i];
|
||||
}
|
||||
$result = jenv->NewString(conv_buf, len);
|
||||
delete [] conv_buf; %}
|
||||
|
||||
%typemap(javain) std::wstring "$javainput"
|
||||
|
||||
%typemap(javaout) std::wstring {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
// const std::wstring &
|
||||
%typemap(jni) const std::wstring & "jstring"
|
||||
%typemap(jtype) const std::wstring & "String"
|
||||
%typemap(jstype) const std::wstring & "String"
|
||||
|
||||
%typemap(in) const std::wstring &
|
||||
%{$1 = NULL;
|
||||
if($input) {
|
||||
const jchar *pstr = jenv->GetStringChars($input, 0);
|
||||
if (!pstr) return $null;
|
||||
jsize len = jenv->GetStringLength($input);
|
||||
if (len) {
|
||||
wchar_t *conv_buf = new wchar_t[len];
|
||||
for (jsize i = 0; i < len; ++i) {
|
||||
conv_buf[i] = pstr[i];
|
||||
}
|
||||
$1 = new std::wstring(conv_buf, len);
|
||||
delete [] conv_buf;
|
||||
}
|
||||
jenv->ReleaseStringChars($input, pstr);
|
||||
}
|
||||
else {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
|
||||
return $null;
|
||||
} %}
|
||||
|
||||
%typemap(out) const std::wstring &
|
||||
%{jsize len = $1->length();
|
||||
jchar *conv_buf = new jchar[len];
|
||||
for (jsize i = 0; i < len; ++i) {
|
||||
conv_buf[i] = (jchar)(*$1)[i];
|
||||
}
|
||||
$result = jenv->NewString(conv_buf, len);
|
||||
delete [] conv_buf; %}
|
||||
|
||||
%typemap(javain) const std::wstring & "$javainput"
|
||||
|
||||
%typemap(javaout) const std::wstring & {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
// For using std::wstring in the global namespace
|
||||
%apply const std::wstring & {const wstring &};
|
||||
%apply std::wstring {wstring};
|
||||
|
||||
/* To use non-const std::wstring references use the following %apply. Note that they are passed by value.
|
||||
// std::wstring &
|
||||
%apply const std::wstring & {std::wstring &};
|
||||
%apply std::wstring & {wstring &};
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
137
SWIG/Lib/java/std_vector.i
Normal file
137
SWIG/Lib/java/std_vector.i
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
//
|
||||
// SWIG typemaps for std::vector
|
||||
// Luigi Ballabio
|
||||
// May 7, 2002
|
||||
//
|
||||
// Java implementation
|
||||
|
||||
|
||||
%include exception.i
|
||||
|
||||
// containers
|
||||
|
||||
// methods which can raise are caused to throw an IndexError
|
||||
%exception std::vector::get {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception std::vector::set {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::vector
|
||||
//
|
||||
// The aim of all that follows would be to integrate std::vector with
|
||||
// Java as much as possible, namely, to allow the user to pass and
|
||||
// be returned Java (arrays? containers?)
|
||||
// const declarations are used to guess the intent of the function being
|
||||
// exported; therefore, the following rationale is applied:
|
||||
//
|
||||
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
|
||||
// the parameter being read-only, either a Java sequence or a
|
||||
// previously wrapped std::vector<T> can be passed.
|
||||
// -- f(std::vector<T>&), f(std::vector<T>*):
|
||||
// the parameter must be modified; therefore, only a wrapped std::vector
|
||||
// can be passed.
|
||||
// -- std::vector<T> f():
|
||||
// the vector is returned by copy; therefore, a Java sequence of T:s
|
||||
// is returned which is most easily used in other Java functions
|
||||
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
|
||||
// const std::vector<T>* f():
|
||||
// the vector is returned by reference; therefore, a wrapped std::vector
|
||||
// is returned
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
// exported class
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class T> class vector {
|
||||
// add generic typemaps here
|
||||
public:
|
||||
vector(unsigned int size = 0);
|
||||
unsigned int size() const;
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(add) push_back;
|
||||
void push_back(const T& x);
|
||||
%extend {
|
||||
T& get(int i) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const T& x) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = x;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// specializations for built-ins
|
||||
|
||||
%define specialize_std_vector(T)
|
||||
template<> class vector<T> {
|
||||
// add specialized typemaps here
|
||||
public:
|
||||
vector(unsigned int size = 0);
|
||||
unsigned int size() const;
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(add) push_back;
|
||||
void push_back(int x);
|
||||
%extend {
|
||||
T get(int i) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, T x) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = x;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
%enddef
|
||||
|
||||
specialize_std_vector(bool);
|
||||
specialize_std_vector(int);
|
||||
specialize_std_vector(short);
|
||||
specialize_std_vector(long);
|
||||
specialize_std_vector(unsigned int);
|
||||
specialize_std_vector(unsigned short);
|
||||
specialize_std_vector(unsigned long);
|
||||
specialize_std_vector(float);
|
||||
specialize_std_vector(double);
|
||||
|
||||
}
|
||||
|
||||
9
SWIG/Lib/java/stl.i
Normal file
9
SWIG/Lib/java/stl.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//
|
||||
// SWIG typemaps for STL types
|
||||
// Luigi Ballabio and Manu ???
|
||||
// Apr 26, 2002
|
||||
//
|
||||
|
||||
%include std_string.i
|
||||
%include std_vector.i
|
||||
|
||||
|
|
@ -1,209 +1,400 @@
|
|||
//-*-c++-*-
|
||||
//
|
||||
// SWIG Typemap library
|
||||
// for Java
|
||||
// William Fulton
|
||||
// 4 January 2002
|
||||
//
|
||||
// Java implementation
|
||||
//
|
||||
|
||||
%typemap(java,jtype) char *STRING {String}
|
||||
%typemap(java,in) char *STRING {
|
||||
$target = JCALL(GetStringUTFChars, jenv) $source, 0);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
// Pointer and reference handling
|
||||
//
|
||||
// These mappings provide support for input/output arguments and common
|
||||
// uses for C/C++ pointers and C++ references.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%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<l; i++) {
|
||||
jstring js;
|
||||
char *cs;
|
||||
|
||||
js = (jstring) JCALL(GetObjectArrayElement, jenv) $source, i);
|
||||
cs = (char *) JCALL(GetStringUTFChars, jenv) js, 0);
|
||||
$target[i] = cs;
|
||||
}
|
||||
$target[l] = '\0';
|
||||
}
|
||||
|
||||
%typemap(java,argout) char **STRING_IN {
|
||||
/* should release strings obtained from GetStringUTFChars */
|
||||
free($target);
|
||||
}
|
||||
|
||||
/* result must be a null terminated string */
|
||||
%typemap(java,jtype) char **STRING_OUT {String[]}
|
||||
%typemap(java,jni) char **STRING_OUT {jobjectArray}
|
||||
%typemap(java,in) char **STRING_OUT (char *s) {
|
||||
$target = &s;
|
||||
}
|
||||
%typemap(java,argout) char **STRING_OUT {
|
||||
if($target != NULL)
|
||||
JCALL(SetObjectArrayElement, jenv) $source, 0, JCALL(NewStringUTF, jenv) *$target));
|
||||
}
|
||||
|
||||
/* a NULL terminated array of char* */
|
||||
%typemap(java,jtype) char **STRING_RET {String[]}
|
||||
%typemap(java,jni) char **STRING_RET {jarray}
|
||||
%typemap(java,out) char **STRING_RET {
|
||||
if($source != NULL) {
|
||||
char **p = $source;
|
||||
jsize size = 0;
|
||||
int i = 0;
|
||||
jclass strClass;
|
||||
|
||||
while (*p++) size++; /* determine size */
|
||||
strClass = JCALL(FindClass, jenv) "java/lang/String");
|
||||
$target = JCALL(NewObjectArray, jenv) size, strClass, NULL);
|
||||
p = $source;
|
||||
while (*p) {
|
||||
jstring js = JCALL(NewStringUTF, jenv) *p);
|
||||
JCALL(SetObjectArrayElement, jenv) $target, i++, js);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(java,jni) int *INT_OUT {jintArray}
|
||||
%typemap(java,jtype) int *INT_OUT {int[]}
|
||||
%typemap(java,in) int *INT_OUT (int i) {
|
||||
$target = (int *)&i;
|
||||
}
|
||||
|
||||
%typemap(java,argout) int *INT_OUT {
|
||||
jint ji;
|
||||
i = (jint) *$target;
|
||||
JCALL(SetIntArrayRegion, jenv) $source, 0, 1, (jint *) &i);
|
||||
}
|
||||
|
||||
%typemap(java,out) float * FLOAT_ARRAY_RETURN {
|
||||
if($source != NULL) {
|
||||
float *fp = $source;
|
||||
jfloat *jfp;
|
||||
int size = 0;
|
||||
int i;
|
||||
|
||||
/* determine size of array */
|
||||
while(*fp++) size++;
|
||||
|
||||
/* new float array */
|
||||
$target = JCALL(NewFloatArray, jenv) size);
|
||||
|
||||
/* copy elements to float array */
|
||||
jfp = JCALL(GetFloatArrayElements, jenv) $target, 0);
|
||||
for(i=0; i<size; i++ )
|
||||
jfp[i] = (jfloat) $source[i];
|
||||
|
||||
JCALL(ReleaseFloatArrayElements, jenv) $target, jfp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(java,jni) char *BYTE {jbyteArray}
|
||||
%typemap(java,jtype) char *BYTE {byte[]}
|
||||
%typemap(java,in) char *BYTE {
|
||||
$target = (char *) JCALL(GetByteArrayElements, jenv) $source, 0);
|
||||
}
|
||||
|
||||
%typemap(java,argout) char *BYTE {
|
||||
JCALL(ReleaseByteArrayElements, jenv) $source, (jbyte *) $target, 0);
|
||||
}
|
||||
|
||||
%typemap(java,ignore) JNIEnv * {
|
||||
$target = jenv;
|
||||
}
|
||||
|
||||
%typemap(java,ignore) jclass jcls {
|
||||
$target = jcls;
|
||||
}
|
||||
|
||||
%typemap(java,ignore) jobject jobj {
|
||||
$target = jobj;
|
||||
}
|
||||
// INPUT typemaps.
|
||||
// These remap a C pointer or C++ reference to be an "INPUT" value which is passed by value
|
||||
// instead of reference.
|
||||
|
||||
/*
|
||||
* typemaps for standard C++ string and wstring
|
||||
* by: Tal Shalif <tal@slt.atr.co.jp>
|
||||
*/
|
||||
/* what type to use in java source code */
|
||||
%typemap(java,jtype) const string & {String}
|
||||
The following methods can be applied to turn a pointer or reference into a simple
|
||||
"input" value. That is, instead of passing a pointer or reference to an object,
|
||||
you would use a real value instead.
|
||||
|
||||
/* what is the corresponding jni type */
|
||||
%typemap(java,jni) const string & {jstring}
|
||||
bool *INPUT, bool &INPUT
|
||||
signed char *INPUT, signed char &INPUT
|
||||
unsigned char *INPUT, unsigned char &INPUT
|
||||
short *INPUT, short &INPUT
|
||||
unsigned short *INPUT, unsigned short &INPUT
|
||||
int *INPUT, int &INPUT
|
||||
unsigned int *INPUT, unsigned int &INPUT
|
||||
long *INPUT, long &INPUT
|
||||
unsigned long *INPUT, unsigned long &INPUT
|
||||
long long *INPUT, long long &INPUT
|
||||
unsigned long long *INPUT, unsigned long long &INPUT
|
||||
float *INPUT, float &INPUT
|
||||
double *INPUT, double &INPUT
|
||||
|
||||
To use these, suppose you had a C function like this :
|
||||
|
||||
/* how to convert the c++ type to the java type */
|
||||
%typemap(java,out) const string & {
|
||||
$target = JCALL(NewStringUTF, jenv) $source->c_str());
|
||||
}
|
||||
double fadd(double *a, double *b) {
|
||||
return *a+*b;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
JCALL(ReleaseStringUTFChars, jenv) $source, p);
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
double fadd(double *INPUT, double *INPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *INPUT { double *a, double *b };
|
||||
double fadd(double *a, double *b);
|
||||
|
||||
In Java you could then use it like this:
|
||||
double answer = modulename.fadd(10.0 + 20.0);
|
||||
|
||||
*/
|
||||
|
||||
%define INPUT_TYPEMAP(CTYPE, JNITYPE, JTYPE)
|
||||
%typemap(jni) CTYPE *INPUT "JNITYPE"
|
||||
%typemap(jtype) CTYPE *INPUT "JTYPE"
|
||||
%typemap(jstype) CTYPE *INPUT "JTYPE"
|
||||
%typemap(javain) CTYPE *INPUT "$javainput"
|
||||
|
||||
%typemap(jni) CTYPE &INPUT "JNITYPE"
|
||||
%typemap(jtype) CTYPE &INPUT "JTYPE"
|
||||
%typemap(jstype) CTYPE &INPUT "JTYPE"
|
||||
%typemap(javain) CTYPE &INPUT "$javainput"
|
||||
|
||||
%typemap(in) CTYPE *INPUT, CTYPE &INPUT
|
||||
%{ $1 = ($1_ltype)&$input; %}
|
||||
|
||||
%typemap(typecheck) CTYPE *INPUT = CTYPE;
|
||||
%typemap(typecheck) CTYPE &INPUT = CTYPE;
|
||||
%enddef
|
||||
|
||||
INPUT_TYPEMAP(bool, jboolean, boolean);
|
||||
INPUT_TYPEMAP(signed char, jbyte, byte);
|
||||
INPUT_TYPEMAP(unsigned char, jshort, short);
|
||||
INPUT_TYPEMAP(short, jshort, short);
|
||||
INPUT_TYPEMAP(unsigned short, jint, int);
|
||||
INPUT_TYPEMAP(int, jint, int);
|
||||
INPUT_TYPEMAP(unsigned int, jlong, long);
|
||||
INPUT_TYPEMAP(long, jint, int);
|
||||
INPUT_TYPEMAP(unsigned long, jlong, long);
|
||||
INPUT_TYPEMAP(long long, jlong, long);
|
||||
INPUT_TYPEMAP(unsigned long long, jobject, java.math.BigInteger);
|
||||
INPUT_TYPEMAP(float, jfloat, float);
|
||||
INPUT_TYPEMAP(double, jdouble, double);
|
||||
|
||||
#undef INPUT_TYPEMAP
|
||||
|
||||
/* Convert from BigInteger using the toByteArray member function */
|
||||
/* Overrides the typemap in the INPUT_TYPEMAP macro */
|
||||
%typemap(in) unsigned long long *INPUT($*1_type temp), unsigned long long &INPUT(unsigned long long temp) {
|
||||
jclass clazz;
|
||||
jmethodID mid;
|
||||
jbyteArray ba;
|
||||
jbyte* bae;
|
||||
jsize sz;
|
||||
int i;
|
||||
|
||||
if (!$input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
/* free resource once finished using */
|
||||
%typemap(java,freearg) 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,freearg) string & = const string &;
|
||||
|
||||
/* what type to use in java source code */
|
||||
%typemap(java,jtype) const wstring & {String}
|
||||
|
||||
/* what is the corresponding jni type */
|
||||
%typemap(java,jni) const wstring & {jstring}
|
||||
|
||||
/* how to convert the c++ type to the java type */
|
||||
%typemap(java,out) const wstring & {
|
||||
unsigned int len = $source->length();
|
||||
jchar *conv_buf = new jchar[len];
|
||||
for (unsigned int i = 0; i < len; ++i) {
|
||||
conv_buf[i] = (jchar)(*$source)[i];
|
||||
}
|
||||
$target = JCALL(NewString, jenv) conv_buf, len);
|
||||
delete [] conv_buf;
|
||||
}
|
||||
|
||||
/* how to convert java type to requested c++ type */
|
||||
%typemap(java,in) const wstring & {
|
||||
$target = NULL;
|
||||
if($source != NULL) {
|
||||
/* get the String from the StringBuffer */
|
||||
const jchar *jchar_p = jenv->GetStringChars($source, 0);
|
||||
unsigned int len;
|
||||
for (len = 0; jchar_p[len]; ++len);
|
||||
if (len) {
|
||||
wchar_t *conv_buf = new wchar_t[len];
|
||||
for (unsigned int i = 0; i < len; ++i) {
|
||||
conv_buf[i] = jchar_p[i];
|
||||
}
|
||||
$target = new wstring(conv_buf, len);
|
||||
delete [] conv_buf;
|
||||
clazz = JCALL1(GetObjectClass, jenv, $input);
|
||||
mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
|
||||
ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
|
||||
bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
|
||||
sz = JCALL1(GetArrayLength, jenv, ba);
|
||||
temp = 0;
|
||||
if (bae[0] == 0) {
|
||||
for(i=sz-1; i>0; i-- ) {
|
||||
temp = (temp << 8) | (unsigned char)bae[sz-i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i=sz; i>=0; i-- ) {
|
||||
temp = (temp << 8) | (unsigned char)bae[sz-1-i];
|
||||
}
|
||||
|
||||
JCALL(ReleaseStringChars, jenv) $source, jchar_p);
|
||||
}
|
||||
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||
// are output only. An array replaces the c pointer or reference parameter.
|
||||
// The output value is returned in this array passed in.
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer or reference into an "output"
|
||||
value. When calling a function, no input value would be given for
|
||||
a parameter, but an output value would be returned. This works by a
|
||||
Java array being passed as a parameter where a c pointer or reference is required.
|
||||
As with any Java function, the array is passed by reference so that
|
||||
any modifications to the array will be picked up in the calling function.
|
||||
Note that the array passed in MUST have at least one element, but as the
|
||||
c function does not require any input, the value can be set to anything.
|
||||
|
||||
bool *OUTPUT, bool &OUTPUT
|
||||
signed char *OUTPUT, signed char &OUTPUT
|
||||
unsigned char *OUTPUT, unsigned char &OUTPUT
|
||||
short *OUTPUT, short &OUTPUT
|
||||
unsigned short *OUTPUT, unsigned short &OUTPUT
|
||||
int *OUTPUT, int &OUTPUT
|
||||
unsigned int *OUTPUT, unsigned int &OUTPUT
|
||||
long *OUTPUT, long &OUTPUT
|
||||
unsigned long *OUTPUT, unsigned long &OUTPUT
|
||||
long long *OUTPUT, long long &OUTPUT
|
||||
unsigned long long *OUTPUT, unsigned long long &OUTPUT
|
||||
float *OUTPUT, float &OUTPUT
|
||||
double *OUTPUT, double &OUTPUT
|
||||
|
||||
For example, suppose you were trying to wrap the modf() function in the
|
||||
C math library which splits x into integral and fractional parts (and
|
||||
returns the integer part in one of its parameters):
|
||||
|
||||
double modf(double x, double *ip);
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
double modf(double x, double *OUTPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *OUTPUT { double *ip };
|
||||
double modf(double x, double *ip);
|
||||
|
||||
The Java output of the function would be the function return value and the
|
||||
value in the single element array. In Java you would use it like this:
|
||||
|
||||
double[] intptr = {0};
|
||||
double fraction = modulename.modf(5,intptr);
|
||||
|
||||
*/
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INT128_ARRAY) SWIGBIGINTEGERARRAY "" /* Java BigInteger[] */
|
||||
|
||||
%define OUTPUT_TYPEMAP(CTYPE, JNITYPE, JTYPE, JAVATYPE, TYPECHECKTYPE)
|
||||
%typemap(jni) CTYPE *OUTPUT %{JNITYPE##Array%}
|
||||
%typemap(jtype) CTYPE *OUTPUT "JTYPE[]"
|
||||
%typemap(jstype) CTYPE *OUTPUT "JTYPE[]"
|
||||
%typemap(javain) CTYPE *OUTPUT "$javainput"
|
||||
|
||||
%typemap(jni) CTYPE &OUTPUT %{JNITYPE##Array%}
|
||||
%typemap(jtype) CTYPE &OUTPUT "JTYPE[]"
|
||||
%typemap(jstype) CTYPE &OUTPUT "JTYPE[]"
|
||||
%typemap(javain) CTYPE &OUTPUT "$javainput"
|
||||
|
||||
%typemap(in) CTYPE *OUTPUT($*1_type temp), CTYPE &OUTPUT(CTYPE temp)
|
||||
{
|
||||
if (!$input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
|
||||
return $null;
|
||||
}
|
||||
if (JCALL1(GetArrayLength, jenv, $input) == 0) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
|
||||
return $null;
|
||||
}
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(argout) CTYPE *OUTPUT, CTYPE &OUTPUT
|
||||
{ JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, (JNITYPE *)&temp$argnum); }
|
||||
|
||||
%typemap(typecheck) CTYPE *INOUT = TYPECHECKTYPE;
|
||||
%typemap(typecheck) CTYPE &INOUT = TYPECHECKTYPE;
|
||||
%enddef
|
||||
|
||||
OUTPUT_TYPEMAP(bool, jboolean, boolean, Boolean, jbooleanArray);
|
||||
OUTPUT_TYPEMAP(signed char, jbyte, byte, Byte, jbyteArray);
|
||||
OUTPUT_TYPEMAP(unsigned char, jshort, short, Short, jshortArray);
|
||||
OUTPUT_TYPEMAP(short, jshort, short, Short, jshortArray);
|
||||
OUTPUT_TYPEMAP(unsigned short, jint, int, Int, jintArray);
|
||||
OUTPUT_TYPEMAP(int, jint, int, Int, jintArray);
|
||||
OUTPUT_TYPEMAP(unsigned int, jlong, long, Long, jlongArray);
|
||||
OUTPUT_TYPEMAP(long, jint, int, Int, jintArray);
|
||||
OUTPUT_TYPEMAP(unsigned long, jlong, long, Long, jlongArray);
|
||||
OUTPUT_TYPEMAP(long long, jlong, long, Long, jlongArray);
|
||||
OUTPUT_TYPEMAP(unsigned long long, jobject, java.math.BigInteger, NOTUSED, SWIGBIGINTEGERARRAY);
|
||||
OUTPUT_TYPEMAP(float, jfloat, float, Float, jfloatArray);
|
||||
OUTPUT_TYPEMAP(double, jdouble, double, Double, jdoubleArray);
|
||||
|
||||
#undef OUTPUT_TYPEMAP
|
||||
|
||||
/* Convert to BigInteger - byte array holds number in 2's complement big endian format */
|
||||
/* Use first element in BigInteger array for output */
|
||||
/* Overrides the typemap in the OUTPUT_TYPEMAP macro */
|
||||
%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT {
|
||||
jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
|
||||
jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
|
||||
jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
|
||||
jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V");
|
||||
jobject bigint;
|
||||
int i;
|
||||
|
||||
bae[0] = 0;
|
||||
for(i=1; i<9; i++ ) {
|
||||
bae[i] = (jbyte)(temp$argnum>>8*(8-i));
|
||||
}
|
||||
|
||||
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
|
||||
bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
|
||||
JCALL3(SetObjectArrayElement, jenv, $input, 0, bigint);
|
||||
}
|
||||
|
||||
// INOUT
|
||||
// Mappings for an argument that is both an input and output
|
||||
// parameter
|
||||
|
||||
/*
|
||||
The following methods can be applied to make a function parameter both
|
||||
an input and output value. This combines the behavior of both the
|
||||
"INPUT" and "OUTPUT" methods described earlier. Output values are
|
||||
returned as an element in a Java array.
|
||||
|
||||
bool *INOUT, bool &INOUT
|
||||
signed char *INOUT, signed char &INOUT
|
||||
unsigned char *INOUT, unsigned char &INOUT
|
||||
short *INOUT, short &INOUT
|
||||
unsigned short *INOUT, unsigned short &INOUT
|
||||
int *INOUT, int &INOUT
|
||||
unsigned int *INOUT, unsigned int &INOUT
|
||||
long *INOUT, long &INOUT
|
||||
unsigned long *INOUT, unsigned long &INOUT
|
||||
long long *INOUT, long long &INOUT
|
||||
unsigned long long *INOUT, unsigned long long &INOUT
|
||||
float *INOUT, float &INOUT
|
||||
double *INOUT, double &INOUT
|
||||
|
||||
For example, suppose you were trying to wrap the following function :
|
||||
|
||||
void neg(double *x) {
|
||||
*x = -(*x);
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
void neg(double *INOUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *INOUT { double *x };
|
||||
void neg(double *x);
|
||||
|
||||
This works similarly to C in that the mapping directly modifies the
|
||||
input value - the input must be an array with a minimum of one element.
|
||||
The element in the array is the input and the output is the element in
|
||||
the array.
|
||||
|
||||
double x[] = {5};
|
||||
neg(x);
|
||||
|
||||
The implementation of the OUTPUT and INOUT typemaps is different to other
|
||||
languages in that other languages will return the output value as part
|
||||
of the function return value. This difference is due to Java being a typed language.
|
||||
|
||||
*/
|
||||
|
||||
%define INOUT_TYPEMAP(CTYPE, JNITYPE, JTYPE, JAVATYPE, TYPECHECKTYPE)
|
||||
%typemap(jni) CTYPE *INOUT %{JNITYPE##Array%}
|
||||
%typemap(jtype) CTYPE *INOUT "JTYPE[]"
|
||||
%typemap(jstype) CTYPE *INOUT "JTYPE[]"
|
||||
%typemap(javain) CTYPE *INOUT "$javainput"
|
||||
|
||||
%typemap(jni) CTYPE &INOUT %{JNITYPE##Array%}
|
||||
%typemap(jtype) CTYPE &INOUT "JTYPE[]"
|
||||
%typemap(jstype) CTYPE &INOUT "JTYPE[]"
|
||||
%typemap(javain) CTYPE &INOUT "$javainput"
|
||||
|
||||
%typemap(in) CTYPE *INOUT, CTYPE &INOUT {
|
||||
if (!$input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
|
||||
return $null;
|
||||
}
|
||||
if (JCALL1(GetArrayLength, jenv, $input) == 0) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
|
||||
return $null;
|
||||
}
|
||||
$1 = ($1_ltype) JCALL2(Get##JAVATYPE##ArrayElements, jenv, $input, 0);
|
||||
}
|
||||
|
||||
%typemap(argout) CTYPE *INOUT, CTYPE &INOUT
|
||||
{ JCALL3(Release##JAVATYPE##ArrayElements, jenv, $input, (JNITYPE *)$1, 0); }
|
||||
|
||||
%typemap(typecheck) CTYPE *INOUT = TYPECHECKTYPE;
|
||||
%typemap(typecheck) CTYPE &INOUT = TYPECHECKTYPE;
|
||||
%enddef
|
||||
|
||||
INOUT_TYPEMAP(bool, jboolean, boolean, Boolean, jbooleanArray);
|
||||
INOUT_TYPEMAP(signed char, jbyte, byte, Byte, jbyteArray);
|
||||
INOUT_TYPEMAP(unsigned char, jshort, short, Short, jshortArray);
|
||||
INOUT_TYPEMAP(short, jshort, short, Short, jshortArray);
|
||||
INOUT_TYPEMAP(unsigned short, jint, int, Int, jintArray);
|
||||
INOUT_TYPEMAP(int, jint, int, Int, jintArray);
|
||||
INOUT_TYPEMAP(unsigned int, jlong, long, Long, jlongArray);
|
||||
INOUT_TYPEMAP(long, jint, int, Int, jintArray);
|
||||
INOUT_TYPEMAP(unsigned long, jlong, long, Long, jlongArray);
|
||||
INOUT_TYPEMAP(long long, jlong, long, Long, jlongArray);
|
||||
INOUT_TYPEMAP(unsigned long long, jobject, java.math.BigInteger, NOTUSED, SWIGBIGINTEGERARRAY);
|
||||
INOUT_TYPEMAP(float, jfloat, float, Float, jfloatArray);
|
||||
INOUT_TYPEMAP(double, jdouble, double, Double, jdoubleArray);
|
||||
|
||||
#undef INOUT_TYPEMAP
|
||||
|
||||
/* Override the typemap in the INOUT_TYPEMAP macro */
|
||||
%typemap(in) unsigned long long *INOUT ($*1_type temp), unsigned long long &INOUT (unsigned long long temp) {
|
||||
jobject bigint;
|
||||
jclass clazz;
|
||||
jmethodID mid;
|
||||
jbyteArray ba;
|
||||
jbyte* bae;
|
||||
jsize sz;
|
||||
int i;
|
||||
|
||||
if (!$input) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
|
||||
return $null;
|
||||
}
|
||||
if (JCALL1(GetArrayLength, jenv, $input) == 0) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
|
||||
return $null;
|
||||
}
|
||||
bigint = JCALL2(GetObjectArrayElement, jenv, $input, 0);
|
||||
if (!bigint) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array element null");
|
||||
return $null;
|
||||
}
|
||||
clazz = JCALL1(GetObjectClass, jenv, bigint);
|
||||
mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
|
||||
ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, bigint, mid);
|
||||
bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
|
||||
sz = JCALL1(GetArrayLength, jenv, ba);
|
||||
temp = 0;
|
||||
if (bae[0] == 0) {
|
||||
for(i=sz-1; i>0; i-- ) {
|
||||
temp = (temp << 8) | (unsigned char)bae[sz-i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i=sz; i>=0; i-- ) {
|
||||
temp = (temp << 8) | (unsigned char)bae[sz-1-i];
|
||||
}
|
||||
}
|
||||
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
|
||||
%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
|
||||
|
||||
|
||||
%typemap(java,jtype) wstring & = const wstring &;
|
||||
%typemap(java,jni) wstring & = const wstring &;
|
||||
%typemap(java,in) wstring & = const wstring &;
|
||||
%typemap(java,out) wstring & = const wstring &;
|
||||
%typemap(java,freearg) wstring & = const wstring &;
|
||||
|
||||
|
|
|
|||
106
SWIG/Lib/java/various.i
Normal file
106
SWIG/Lib/java/various.i
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* SWIG Typemap library for Java
|
||||
* Various useful typemaps.
|
||||
*
|
||||
*/
|
||||
|
||||
/* char **STRING_IN */
|
||||
%typemap(jni) char **STRING_IN "jobjectArray"
|
||||
%typemap(jtype) char **STRING_IN "String[]"
|
||||
%typemap(jstype) char **STRING_IN "String[]"
|
||||
%typemap(in) char **STRING_IN {
|
||||
int i;
|
||||
jsize sz = JCALL1(GetArrayLength, jenv, $input);
|
||||
$1 = (char **) calloc((sz+1), sizeof(char *));
|
||||
for(i=0; i<sz; i++) {
|
||||
jstring js;
|
||||
char *cs;
|
||||
|
||||
js = (jstring) JCALL2(GetObjectArrayElement, jenv, $input, i);
|
||||
cs = (char *) JCALL2(GetStringUTFChars, jenv, js, 0);
|
||||
$1[i] = cs;
|
||||
}
|
||||
$1[sz] = '\0';
|
||||
}
|
||||
%typemap(argout) char **STRING_IN %{
|
||||
/* should copy changes in char ** back into array and release strings obtained from GetStringUTFChars */
|
||||
%}
|
||||
%typemap(freearg) char **STRING_IN
|
||||
%{ free($1); %}
|
||||
|
||||
/* char **STRING_OUT - result must be a null terminated string */
|
||||
%typemap(jni) char **STRING_OUT "jobjectArray"
|
||||
%typemap(jtype) char **STRING_OUT "String[]"
|
||||
%typemap(jstype) char **STRING_OUT "String[]"
|
||||
%typemap(in) char **STRING_OUT (char *s)
|
||||
%{ $1 = &s; %}
|
||||
%typemap(argout) char **STRING_OUT {
|
||||
if($1) {
|
||||
JCALL3(SetObjectArrayElement, jenv, $input, 0, JCALL1(NewStringUTF, jenv, *$1));
|
||||
}
|
||||
}
|
||||
|
||||
/* char **STRING_RET - a NULL terminated array of char* */
|
||||
%typemap(jni) char **STRING_RET "jarray"
|
||||
%typemap(jtype) char **STRING_RET "String[]"
|
||||
%typemap(jstype) char **STRING_RET "String[]"
|
||||
%typemap(out) char **STRING_RET {
|
||||
if($1 != NULL) {
|
||||
char **p = $1;
|
||||
jsize size = 0;
|
||||
int i = 0;
|
||||
jclass strClass;
|
||||
|
||||
while (*p++) size++; /* determine size */
|
||||
strClass = JCALL1(FindClass, jenv, "java/lang/String");
|
||||
$result = JCALL3(NewObjectArray, jenv, size, strClass, NULL);
|
||||
p = $1;
|
||||
while (*p) {
|
||||
jstring js = JCALL1(NewStringUTF, jenv, *p);
|
||||
JCALL3(SetObjectArrayElement, jenv, $result, i++, js);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* float *FLOAT_ARRAY_RETURN */
|
||||
%typemap(jni) float *FLOAT_ARRAY_RETURN "jfloatArray"
|
||||
%typemap(jtype) float *FLOAT_ARRAY_RETURN "float[]"
|
||||
%typemap(jstype) float *FLOAT_ARRAY_RETURN "float[]"
|
||||
%typemap(out) float *FLOAT_ARRAY_RETURN {
|
||||
if($1) {
|
||||
float *fp = $1;
|
||||
jfloat *jfp;
|
||||
int size = 0;
|
||||
int i;
|
||||
|
||||
/* determine size of array */
|
||||
while(*fp++) size++;
|
||||
|
||||
/* new float array */
|
||||
$result = JCALL1(NewFloatArray, jenv, size);
|
||||
|
||||
/* copy elements to float array */
|
||||
jfp = JCALL2(GetFloatArrayElements, jenv, $result, 0);
|
||||
for(i=0; i<size; i++ )
|
||||
jfp[i] = (jfloat) $1[i];
|
||||
|
||||
JCALL3(ReleaseFloatArrayElements, jenv, $result, jfp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* char *BYTE */
|
||||
%typemap(jni) char *BYTE "jbyteArray"
|
||||
%typemap(jtype) char *BYTE "byte[]"
|
||||
%typemap(jstype) char *BYTE "byte[]"
|
||||
%typemap(in) char *BYTE {
|
||||
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
|
||||
}
|
||||
|
||||
%typemap(argout) char *BYTE {
|
||||
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
|
||||
}
|
||||
|
||||
/* Prevent default freearg typemap from being used */
|
||||
%typemap(freearg) char *BYTE ""
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue