1
/* -----------------------------------------------------------------------------
2
* See the LICENSE file for information on copyright, usage and redistribution
3
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
7
* These typemaps give more natural support for arrays. The typemaps are not efficient
8
* as there is a lot of copying of the array values whenever the array is passed to C/C++
9
* from Java and visa versa. The Java array is expected to be the same size as the C array.
10
* An exception is thrown if they are not.
15
* %include <arrays_java.i>
17
* short FiddleSticks[3];
20
* Use from Java like this:
22
* short[] fs = new short[] {10, 11, 12};
23
* example.setFiddleSticks(fs);
24
* fs = example.getFiddleSticks();
25
* ----------------------------------------------------------------------------- */
27
/* Primitive array support is a combination of SWIG macros and functions in order to reduce
28
* code bloat and aid maintainability. The SWIG preprocessor expands the macros into functions
29
* for inclusion in the generated code. */
31
/* Array support functions declarations macro */
32
%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
34
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
35
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
36
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
40
/* Array support functions macro */
41
%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
44
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
48
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
51
sz = JCALL1(GetArrayLength, jenv, input);
52
*jarr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, input, 0);
56
%{ *carr = new CTYPE[sz]; %}
58
%{ *carr = (CTYPE*) calloc(sz, sizeof(CTYPE)); %}
61
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
65
JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE)
69
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input) {
71
jsize sz = JCALL1(GetArrayLength, jenv, input);
73
jarr[i] = (JNITYPE)carr[i];
74
JCALL3(Release##JAVATYPE##ArrayElements, jenv, input, jarr, 0);
77
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz) {
80
JNITYPE##Array jresult = JCALL1(New##JAVATYPE##Array, jenv, sz);
83
arr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, jresult, 0);
87
arr[i] = (JNITYPE)result[i];
88
JCALL3(Release##JAVATYPE##ArrayElements, jenv, jresult, arr, 0);
95
#if defined(SWIG_NOINCLUDE) || defined(SWIG_NOARRAYS)
99
JAVA_ARRAYS_DECL(bool, jboolean, Boolean, Bool) /* bool[] */
102
JAVA_ARRAYS_DECL(signed char, jbyte, Byte, Schar) /* signed char[] */
103
JAVA_ARRAYS_DECL(unsigned char, jshort, Short, Uchar) /* unsigned char[] */
104
JAVA_ARRAYS_DECL(short, jshort, Short, Short) /* short[] */
105
JAVA_ARRAYS_DECL(unsigned short, jint, Int, Ushort) /* unsigned short[] */
106
JAVA_ARRAYS_DECL(int, jint, Int, Int) /* int[] */
107
JAVA_ARRAYS_DECL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
108
JAVA_ARRAYS_DECL(long, jint, Int, Long) /* long[] */
109
JAVA_ARRAYS_DECL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
110
JAVA_ARRAYS_DECL(jlong, jlong, Long, Longlong) /* long long[] */
111
JAVA_ARRAYS_DECL(float, jfloat, Float, Float) /* float[] */
112
JAVA_ARRAYS_DECL(double, jdouble, Double, Double) /* double[] */
119
/* Bool array element assignment different to other types to keep Visual C++ quiet */
120
#define JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE) (*carr)[i] = ((*jarr)[i] != 0);
121
JAVA_ARRAYS_IMPL(bool, jboolean, Boolean, Bool) /* bool[] */
122
#undef JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN
125
#define JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE) (*carr)[i] = (CTYPE)(*jarr)[i];
126
JAVA_ARRAYS_IMPL(signed char, jbyte, Byte, Schar) /* signed char[] */
127
JAVA_ARRAYS_IMPL(unsigned char, jshort, Short, Uchar) /* unsigned char[] */
128
JAVA_ARRAYS_IMPL(short, jshort, Short, Short) /* short[] */
129
JAVA_ARRAYS_IMPL(unsigned short, jint, Int, Ushort) /* unsigned short[] */
130
JAVA_ARRAYS_IMPL(int, jint, Int, Int) /* int[] */
131
JAVA_ARRAYS_IMPL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
132
JAVA_ARRAYS_IMPL(long, jint, Int, Long) /* long[] */
133
JAVA_ARRAYS_IMPL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
134
JAVA_ARRAYS_IMPL(jlong, jlong, Long, Longlong) /* long long[] */
135
JAVA_ARRAYS_IMPL(float, jfloat, Float, Float) /* float[] */
136
JAVA_ARRAYS_IMPL(double, jdouble, Double, Double) /* double[] */
143
/* The rest of this file has the array typemaps */
145
/* Arrays of primitive types use the following macro. The array typemaps use support functions. */
146
%define JAVA_ARRAYS_TYPEMAPS(CTYPE, JTYPE, JNITYPE, JFUNCNAME, JNIDESC)
148
%typemap(jni) CTYPE[ANY], CTYPE[] %{JNITYPE##Array%}
149
%typemap(jtype) CTYPE[ANY], CTYPE[] %{JTYPE[]%}
150
%typemap(jstype) CTYPE[ANY], CTYPE[] %{JTYPE[]%}
152
%typemap(in) CTYPE[] (JNITYPE *jarr)
153
%{ if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, &$1, $input)) return $null; %}
154
%typemap(in) CTYPE[ANY] (JNITYPE *jarr)
155
%{ if ($input && JCALL1(GetArrayLength, jenv, $input) != $1_size) {
156
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
159
if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, &$1, $input)) return $null; %}
160
%typemap(argout) CTYPE[ANY], CTYPE[]
161
%{ SWIG_JavaArrayArgout##JFUNCNAME(jenv, jarr$argnum, $1, $input); %}
162
%typemap(out) CTYPE[ANY]
163
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, $1, $1_dim0); %}
164
%typemap(out) CTYPE[]
165
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, $1, FillMeInAsSizeCannotBeDeterminedAutomatically); %}
166
%typemap(freearg) CTYPE[ANY], CTYPE[]
173
%typemap(javain) CTYPE[ANY], CTYPE[] "$javainput"
174
%typemap(javaout) CTYPE[ANY], CTYPE[] {
180
JAVA_ARRAYS_TYPEMAPS(bool, boolean, jboolean, Bool, "[Z") /* bool[ANY] */
181
JAVA_ARRAYS_TYPEMAPS(signed char, byte, jbyte, Schar, "[B") /* signed char[ANY] */
182
JAVA_ARRAYS_TYPEMAPS(unsigned char, short, jshort, Uchar, "[S") /* unsigned char[ANY] */
183
JAVA_ARRAYS_TYPEMAPS(short, short, jshort, Short, "[S") /* short[ANY] */
184
JAVA_ARRAYS_TYPEMAPS(unsigned short, int, jint, Ushort, "[I") /* unsigned short[ANY] */
185
JAVA_ARRAYS_TYPEMAPS(int, int, jint, Int, "[I") /* int[ANY] */
186
JAVA_ARRAYS_TYPEMAPS(unsigned int, long, jlong, Uint, "[J") /* unsigned int[ANY] */
187
JAVA_ARRAYS_TYPEMAPS(long, int, jint, Long, "[I") /* long[ANY] */
188
JAVA_ARRAYS_TYPEMAPS(unsigned long, long, jlong, Ulong, "[J") /* unsigned long[ANY] */
189
JAVA_ARRAYS_TYPEMAPS(long long, long, jlong, Longlong, "[J") /* long long[ANY] */
190
JAVA_ARRAYS_TYPEMAPS(float, float, jfloat, Float, "[F") /* float[ANY] */
191
JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] */
194
%typecheck(SWIG_TYPECHECK_BOOL_ARRAY) /* Java boolean[] */
198
%typecheck(SWIG_TYPECHECK_INT8_ARRAY) /* Java byte[] */
199
signed char[ANY], signed char[]
202
%typecheck(SWIG_TYPECHECK_INT16_ARRAY) /* Java short[] */
203
unsigned char[ANY], unsigned char[],
207
%typecheck(SWIG_TYPECHECK_INT32_ARRAY) /* Java int[] */
208
unsigned short[ANY], unsigned short[],
213
%typecheck(SWIG_TYPECHECK_INT64_ARRAY) /* Java long[] */
214
unsigned int[ANY], unsigned int[],
215
unsigned long[ANY], unsigned long[],
216
long long[ANY], long long[]
219
%typecheck(SWIG_TYPECHECK_INT128_ARRAY) /* Java BigInteger[] */
220
unsigned long long[ANY], unsigned long long[]
223
%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) /* Java float[] */
227
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) /* Java double[] */
228
double[ANY], double[]
232
/* Arrays of proxy classes. The typemaps in this macro make it possible to treat an array of
233
* class/struct/unions as an array of Java classes.
234
* Use the following macro to use these typemaps for an array of class/struct/unions called name:
235
* JAVA_ARRAYSOFCLASSES(name) */
236
%define JAVA_ARRAYSOFCLASSES(ARRAYSOFCLASSES)
238
%typemap(jni) ARRAYSOFCLASSES[ANY] "jlongArray"
239
%typemap(jtype) ARRAYSOFCLASSES[ANY] "long[]"
240
%typemap(jstype) ARRAYSOFCLASSES[ANY] "$javaclassname[]"
242
%typemap(javain) ARRAYSOFCLASSES[ANY] "$javaclassname.cArrayUnwrap($javainput)"
243
%typemap(javaout) ARRAYSOFCLASSES[ANY] {
244
return $javaclassname.cArrayWrap($jnicall, $owner);
247
%typemap(in) ARRAYSOFCLASSES[] (jlong *jarr, jsize sz)
251
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
254
sz = JCALL1(GetArrayLength, jenv, $input);
255
jarr = JCALL2(GetLongArrayElements, jenv, $input, 0);
260
$1 = new $*1_ltype[sz];
262
$1 = ($1_ltype) calloc(sz, sizeof($*1_ltype));
265
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
268
for (i=0; i<sz; i++) {
269
$1[i] = **($&1_ltype)&jarr[i];
273
%typemap(in) ARRAYSOFCLASSES[ANY] (jlong *jarr, jsize sz)
277
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
280
sz = JCALL1(GetArrayLength, jenv, $input);
282
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
285
jarr = JCALL2(GetLongArrayElements, jenv, $input, 0);
290
$1 = new $*1_ltype[sz];
292
$1 = ($1_ltype) calloc(sz, sizeof($*1_ltype));
295
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
298
for (i=0; i<sz; i++) {
299
$1[i] = **($&1_ltype)&jarr[i];
303
%typemap(argout) ARRAYSOFCLASSES[ANY]
306
for (i=0; i<sz$argnum; i++) {
308
*($&1_ltype)&jarr$argnum[i] = &$1[i];
310
JCALL3(ReleaseLongArrayElements, jenv, $input, jarr$argnum, 0);
313
%typemap(out) ARRAYSOFCLASSES[ANY]
317
$result = JCALL1(NewLongArray, jenv, $1_dim0);
321
arr = JCALL2(GetLongArrayElements, jenv, $result, 0);
325
for (i=0; i<$1_dim0; i++) {
327
*($&1_ltype)&arr[i] = &$1[i];
329
JCALL3(ReleaseLongArrayElements, jenv, $result, arr, 0);
332
%typemap(freearg) ARRAYSOFCLASSES[ANY]
339
/* Add some code to the proxy class of the array type for converting between type used in
340
* JNI class (long[]) and type used in proxy class ( ARRAYSOFCLASSES[] ) */
341
%typemap(javacode) ARRAYSOFCLASSES %{
342
protected static long[] cArrayUnwrap($javaclassname[] arrayWrapper) {
343
long[] cArray = new long[arrayWrapper.length];
344
for (int i=0; i<arrayWrapper.length; i++)
345
cArray[i] = $javaclassname.getCPtr(arrayWrapper[i]);
349
protected static $javaclassname[] cArrayWrap(long[] cArray, boolean cMemoryOwn) {
350
$javaclassname[] arrayWrapper = new $javaclassname[cArray.length];
351
for (int i=0; i<cArray.length; i++)
352
arrayWrapper[i] = new $javaclassname(cArray[i], cMemoryOwn);
357
%enddef /* JAVA_ARRAYSOFCLASSES */
361
* Use the following to use these typemaps for an array of enums called name:
362
* %apply ARRAYSOFENUMS[ANY] { name[ANY] }; */
363
%typemap(jni) ARRAYSOFENUMS[ANY] "jintArray"
364
%typemap(jtype) ARRAYSOFENUMS[ANY] "int[]"
365
%typemap(jstype) ARRAYSOFENUMS[ANY] "int[]"
367
%typemap(javain) ARRAYSOFENUMS[ANY] "$javainput"
368
%typemap(javaout) ARRAYSOFENUMS[ANY] {
372
%typemap(in) ARRAYSOFENUMS[] (jint *jarr)
373
%{ if (!SWIG_JavaArrayInInt(jenv, &jarr, (int **)&$1, $input)) return $null; %}
374
%typemap(in) ARRAYSOFENUMS[ANY] (jint *jarr) {
375
if ($input && JCALL1(GetArrayLength, jenv, $input) != $1_size) {
376
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
379
if (!SWIG_JavaArrayInInt(jenv, &jarr, (int **)&$1, $input)) return $null;
381
%typemap(argout) ARRAYSOFENUMS[ANY]
382
%{ SWIG_JavaArrayArgoutInt(jenv, jarr$argnum, (int *)$1, $input); %}
383
%typemap(out) ARRAYSOFENUMS[ANY]
384
%{$result = SWIG_JavaArrayOutInt(jenv, (int *)$1, $1_dim0); %}
385
%typemap(freearg) ARRAYSOFENUMS[ANY]
1
/* -----------------------------------------------------------------------------
2
* See the LICENSE file for information on copyright, usage and redistribution
3
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
7
* These typemaps give more natural support for arrays. The typemaps are not efficient
8
* as there is a lot of copying of the array values whenever the array is passed to C/C++
9
* from Java and vice versa. The Java array is expected to be the same size as the C array.
10
* An exception is thrown if they are not.
15
* %include <arrays_java.i>
17
* short FiddleSticks[3];
20
* Use from Java like this:
22
* short[] fs = new short[] {10, 11, 12};
23
* example.setFiddleSticks(fs);
24
* fs = example.getFiddleSticks();
25
* ----------------------------------------------------------------------------- */
27
/* Primitive array support is a combination of SWIG macros and functions in order to reduce
28
* code bloat and aid maintainability. The SWIG preprocessor expands the macros into functions
29
* for inclusion in the generated code. */
31
/* Array support functions declarations macro */
32
%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
34
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
35
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
36
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
40
/* Array support functions macro */
41
%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
44
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
48
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
51
sz = JCALL1(GetArrayLength, jenv, input);
52
*jarr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, input, 0);
56
%{ *carr = new CTYPE[sz]; %}
58
%{ *carr = (CTYPE*) calloc(sz, sizeof(CTYPE)); %}
61
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
65
JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE)
69
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input) {
71
jsize sz = JCALL1(GetArrayLength, jenv, input);
73
jarr[i] = (JNITYPE)carr[i];
74
JCALL3(Release##JAVATYPE##ArrayElements, jenv, input, jarr, 0);
77
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz) {
80
JNITYPE##Array jresult = JCALL1(New##JAVATYPE##Array, jenv, sz);
83
arr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, jresult, 0);
87
arr[i] = (JNITYPE)result[i];
88
JCALL3(Release##JAVATYPE##ArrayElements, jenv, jresult, arr, 0);
95
#if defined(SWIG_NOINCLUDE) || defined(SWIG_NOARRAYS)
99
JAVA_ARRAYS_DECL(bool, jboolean, Boolean, Bool) /* bool[] */
102
JAVA_ARRAYS_DECL(signed char, jbyte, Byte, Schar) /* signed char[] */
103
JAVA_ARRAYS_DECL(unsigned char, jshort, Short, Uchar) /* unsigned char[] */
104
JAVA_ARRAYS_DECL(short, jshort, Short, Short) /* short[] */
105
JAVA_ARRAYS_DECL(unsigned short, jint, Int, Ushort) /* unsigned short[] */
106
JAVA_ARRAYS_DECL(int, jint, Int, Int) /* int[] */
107
JAVA_ARRAYS_DECL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
108
JAVA_ARRAYS_DECL(long, jint, Int, Long) /* long[] */
109
JAVA_ARRAYS_DECL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
110
JAVA_ARRAYS_DECL(jlong, jlong, Long, Longlong) /* long long[] */
111
JAVA_ARRAYS_DECL(float, jfloat, Float, Float) /* float[] */
112
JAVA_ARRAYS_DECL(double, jdouble, Double, Double) /* double[] */
119
/* Bool array element assignment different to other types to keep Visual C++ quiet */
120
#define JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE) (*carr)[i] = ((*jarr)[i] != 0);
121
JAVA_ARRAYS_IMPL(bool, jboolean, Boolean, Bool) /* bool[] */
122
#undef JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN
125
#define JAVA_TYPEMAP_ARRAY_ELEMENT_ASSIGN(CTYPE) (*carr)[i] = (CTYPE)(*jarr)[i];
126
JAVA_ARRAYS_IMPL(signed char, jbyte, Byte, Schar) /* signed char[] */
127
JAVA_ARRAYS_IMPL(unsigned char, jshort, Short, Uchar) /* unsigned char[] */
128
JAVA_ARRAYS_IMPL(short, jshort, Short, Short) /* short[] */
129
JAVA_ARRAYS_IMPL(unsigned short, jint, Int, Ushort) /* unsigned short[] */
130
JAVA_ARRAYS_IMPL(int, jint, Int, Int) /* int[] */
131
JAVA_ARRAYS_IMPL(unsigned int, jlong, Long, Uint) /* unsigned int[] */
132
JAVA_ARRAYS_IMPL(long, jint, Int, Long) /* long[] */
133
JAVA_ARRAYS_IMPL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */
134
JAVA_ARRAYS_IMPL(jlong, jlong, Long, Longlong) /* long long[] */
135
JAVA_ARRAYS_IMPL(float, jfloat, Float, Float) /* float[] */
136
JAVA_ARRAYS_IMPL(double, jdouble, Double, Double) /* double[] */
143
/* The rest of this file has the array typemaps */
145
/* Arrays of primitive types use the following macro. The array typemaps use support functions. */
146
%define JAVA_ARRAYS_TYPEMAPS(CTYPE, JTYPE, JNITYPE, JFUNCNAME, JNIDESC)
148
%typemap(jni) CTYPE[ANY], CTYPE[] %{JNITYPE##Array%}
149
%typemap(jtype) CTYPE[ANY], CTYPE[] %{JTYPE[]%}
150
%typemap(jstype) CTYPE[ANY], CTYPE[] %{JTYPE[]%}
152
%typemap(in) CTYPE[] (JNITYPE *jarr)
153
%{ if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, &$1, $input)) return $null; %}
154
%typemap(in) CTYPE[ANY] (JNITYPE *jarr)
155
%{ if ($input && JCALL1(GetArrayLength, jenv, $input) != $1_size) {
156
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
159
if (!SWIG_JavaArrayIn##JFUNCNAME(jenv, &jarr, &$1, $input)) return $null; %}
160
%typemap(argout) CTYPE[ANY], CTYPE[]
161
%{ SWIG_JavaArrayArgout##JFUNCNAME(jenv, jarr$argnum, $1, $input); %}
162
%typemap(out) CTYPE[ANY]
163
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, $1, $1_dim0); %}
164
%typemap(out) CTYPE[]
165
%{$result = SWIG_JavaArrayOut##JFUNCNAME(jenv, $1, FillMeInAsSizeCannotBeDeterminedAutomatically); %}
166
%typemap(freearg) CTYPE[ANY], CTYPE[]
173
%typemap(javain) CTYPE[ANY], CTYPE[] "$javainput"
174
%typemap(javaout) CTYPE[ANY], CTYPE[] {
180
JAVA_ARRAYS_TYPEMAPS(bool, boolean, jboolean, Bool, "[Z") /* bool[ANY] */
181
JAVA_ARRAYS_TYPEMAPS(signed char, byte, jbyte, Schar, "[B") /* signed char[ANY] */
182
JAVA_ARRAYS_TYPEMAPS(unsigned char, short, jshort, Uchar, "[S") /* unsigned char[ANY] */
183
JAVA_ARRAYS_TYPEMAPS(short, short, jshort, Short, "[S") /* short[ANY] */
184
JAVA_ARRAYS_TYPEMAPS(unsigned short, int, jint, Ushort, "[I") /* unsigned short[ANY] */
185
JAVA_ARRAYS_TYPEMAPS(int, int, jint, Int, "[I") /* int[ANY] */
186
JAVA_ARRAYS_TYPEMAPS(unsigned int, long, jlong, Uint, "[J") /* unsigned int[ANY] */
187
JAVA_ARRAYS_TYPEMAPS(long, int, jint, Long, "[I") /* long[ANY] */
188
JAVA_ARRAYS_TYPEMAPS(unsigned long, long, jlong, Ulong, "[J") /* unsigned long[ANY] */
189
JAVA_ARRAYS_TYPEMAPS(long long, long, jlong, Longlong, "[J") /* long long[ANY] */
190
JAVA_ARRAYS_TYPEMAPS(float, float, jfloat, Float, "[F") /* float[ANY] */
191
JAVA_ARRAYS_TYPEMAPS(double, double, jdouble, Double, "[D") /* double[ANY] */
194
%typecheck(SWIG_TYPECHECK_BOOL_ARRAY) /* Java boolean[] */
198
%typecheck(SWIG_TYPECHECK_INT8_ARRAY) /* Java byte[] */
199
signed char[ANY], signed char[]
202
%typecheck(SWIG_TYPECHECK_INT16_ARRAY) /* Java short[] */
203
unsigned char[ANY], unsigned char[],
207
%typecheck(SWIG_TYPECHECK_INT32_ARRAY) /* Java int[] */
208
unsigned short[ANY], unsigned short[],
213
%typecheck(SWIG_TYPECHECK_INT64_ARRAY) /* Java long[] */
214
unsigned int[ANY], unsigned int[],
215
unsigned long[ANY], unsigned long[],
216
long long[ANY], long long[]
219
%typecheck(SWIG_TYPECHECK_INT128_ARRAY) /* Java BigInteger[] */
220
unsigned long long[ANY], unsigned long long[]
223
%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) /* Java float[] */
227
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) /* Java double[] */
228
double[ANY], double[]
232
/* Arrays of proxy classes. The typemaps in this macro make it possible to treat an array of
233
* class/struct/unions as an array of Java classes.
234
* Use the following macro to use these typemaps for an array of class/struct/unions called name:
235
* JAVA_ARRAYSOFCLASSES(name) */
236
%define JAVA_ARRAYSOFCLASSES(ARRAYSOFCLASSES)
238
%typemap(jni) ARRAYSOFCLASSES[ANY], ARRAYSOFCLASSES[] "jlongArray"
239
%typemap(jtype) ARRAYSOFCLASSES[ANY], ARRAYSOFCLASSES[] "long[]"
240
%typemap(jstype) ARRAYSOFCLASSES[ANY], ARRAYSOFCLASSES[] "$javaclassname[]"
242
%typemap(javain) ARRAYSOFCLASSES[ANY], ARRAYSOFCLASSES[] "$javaclassname.cArrayUnwrap($javainput)"
243
%typemap(javaout) ARRAYSOFCLASSES[ANY], ARRAYSOFCLASSES[] {
244
return $javaclassname.cArrayWrap($jnicall, $owner);
247
%typemap(in) ARRAYSOFCLASSES[] (jlong *jarr, jsize sz)
251
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
254
sz = JCALL1(GetArrayLength, jenv, $input);
255
jarr = JCALL2(GetLongArrayElements, jenv, $input, 0);
260
$1 = new $*1_ltype[sz];
262
$1 = ($1_ltype) calloc(sz, sizeof($*1_ltype));
265
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
268
for (i=0; i<sz; i++) {
269
$1[i] = **($&1_ltype)&jarr[i];
273
%typemap(in) ARRAYSOFCLASSES[ANY] (jlong *jarr, jsize sz)
277
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array");
280
sz = JCALL1(GetArrayLength, jenv, $input);
282
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
285
jarr = JCALL2(GetLongArrayElements, jenv, $input, 0);
290
$1 = new $*1_ltype[sz];
292
$1 = ($1_ltype) calloc(sz, sizeof($*1_ltype));
295
SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed");
298
for (i=0; i<sz; i++) {
299
$1[i] = **($&1_ltype)&jarr[i];
303
%typemap(argout) ARRAYSOFCLASSES[ANY], ARRAYSOFCLASSES[]
306
for (i=0; i<sz$argnum; i++) {
308
*($&1_ltype)&jarr$argnum[i] = &$1[i];
310
JCALL3(ReleaseLongArrayElements, jenv, $input, jarr$argnum, 0);
313
%typemap(out) ARRAYSOFCLASSES[ANY]
317
$result = JCALL1(NewLongArray, jenv, $1_dim0);
321
arr = JCALL2(GetLongArrayElements, jenv, $result, 0);
325
for (i=0; i<$1_dim0; i++) {
327
*($&1_ltype)&arr[i] = &$1[i];
329
JCALL3(ReleaseLongArrayElements, jenv, $result, arr, 0);
332
%typemap(freearg) ARRAYSOFCLASSES[ANY], ARRAYSOFCLASSES[]
339
/* Add some code to the proxy class of the array type for converting between type used in
340
* JNI class (long[]) and type used in proxy class ( ARRAYSOFCLASSES[] ) */
341
%typemap(javacode) ARRAYSOFCLASSES %{
342
protected static long[] cArrayUnwrap($javaclassname[] arrayWrapper) {
343
long[] cArray = new long[arrayWrapper.length];
344
for (int i=0; i<arrayWrapper.length; i++)
345
cArray[i] = $javaclassname.getCPtr(arrayWrapper[i]);
349
protected static $javaclassname[] cArrayWrap(long[] cArray, boolean cMemoryOwn) {
350
$javaclassname[] arrayWrapper = new $javaclassname[cArray.length];
351
for (int i=0; i<cArray.length; i++)
352
arrayWrapper[i] = new $javaclassname(cArray[i], cMemoryOwn);
357
%enddef /* JAVA_ARRAYSOFCLASSES */
361
* Use the following to use these typemaps for an array of enums called name:
362
* %apply ARRAYSOFENUMS[ANY] { name[ANY] }; */
363
%typemap(jni) ARRAYSOFENUMS[ANY], ARRAYSOFENUMS[] "jintArray"
364
%typemap(jtype) ARRAYSOFENUMS[ANY], ARRAYSOFENUMS[] "int[]"
365
%typemap(jstype) ARRAYSOFENUMS[ANY], ARRAYSOFENUMS[] "int[]"
367
%typemap(javain) ARRAYSOFENUMS[ANY], ARRAYSOFENUMS[] "$javainput"
368
%typemap(javaout) ARRAYSOFENUMS[ANY], ARRAYSOFENUMS[] {
372
%typemap(in) ARRAYSOFENUMS[] (jint *jarr)
373
%{ if (!SWIG_JavaArrayInInt(jenv, &jarr, (int **)&$1, $input)) return $null; %}
374
%typemap(in) ARRAYSOFENUMS[ANY] (jint *jarr) {
375
if ($input && JCALL1(GetArrayLength, jenv, $input) != $1_size) {
376
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "incorrect array size");
379
if (!SWIG_JavaArrayInInt(jenv, &jarr, (int **)&$1, $input)) return $null;
381
%typemap(argout) ARRAYSOFENUMS[ANY], ARRAYSOFENUMS[]
382
%{ SWIG_JavaArrayArgoutInt(jenv, jarr$argnum, (int *)$1, $input); %}
383
%typemap(out) ARRAYSOFENUMS[ANY]
384
%{$result = SWIG_JavaArrayOutInt(jenv, (int *)$1, $1_dim0); %}
385
%typemap(freearg) ARRAYSOFENUMS[ANY], ARRAYSOFENUMS[]