1 /* ----------------------------------------------------------------------------- 2 * java.swg 3 * 4 * Java typemaps 5 * ----------------------------------------------------------------------------- */ 6 7 %include <javahead.swg> 8 9 /* The jni, jtype and jstype typemaps work together and so there should be one of each. 10 * The jni typemap contains the JNI type used in the JNI (C/C++) code. 11 * The jtype typemap contains the Java type used in the JNI intermediary class. 12 * The jstype typemap contains the Java type used in the Java proxy classes, type wrapper classes and module class. */ 13 14 /* Fragments */ 15 %fragment("SWIG_PackData", "header") { 16 /* Pack binary data into a string */ 17 SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) { 18 static const char hex[17] = "0123456789abcdef"; 19 register const unsigned char *u = (unsigned char *) ptr; 20 register const unsigned char *eu = u + sz; 21 for (; u != eu; ++u) { 22 register unsigned char uu = *u; 23 *(c++) = hex[(uu & 0xf0) >> 4]; 24 *(c++) = hex[uu & 0xf]; 25 } 26 return c; 27 } 28 } 29 30 %fragment("SWIG_UnPackData", "header") { 31 /* Unpack binary data from a string */ 32 SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { 33 register unsigned char *u = (unsigned char *) ptr; 34 register const unsigned char *eu = u + sz; 35 for (; u != eu; ++u) { 36 register char d = *(c++); 37 register unsigned char uu; 38 if ((d >= '0') && (d <= '9')) 39 uu = ((d - '0') << 4); 40 else if ((d >= 'a') && (d <= 'f')) 41 uu = ((d - ('a'-10)) << 4); 42 else 43 return (char *) 0; 44 d = *(c++); 45 if ((d >= '0') && (d <= '9')) 46 uu |= (d - '0'); 47 else if ((d >= 'a') && (d <= 'f')) 48 uu |= (d - ('a'-10)); 49 else 50 return (char *) 0; 51 *u = uu; 52 } 53 return c; 54 } 55 } 56 57 /* Primitive types */ 58 %typemap(jni) bool, const bool & "jboolean" 59 %typemap(jni) char, const char & "jchar" 60 %typemap(jni) signed char, const signed char & "jbyte" 61 %typemap(jni) unsigned char, const unsigned char & "jshort" 62 %typemap(jni) short, const short & "jshort" 63 %typemap(jni) unsigned short, const unsigned short & "jint" 64 %typemap(jni) int, const int & "jint" 65 %typemap(jni) unsigned int, const unsigned int & "jlong" 66 %typemap(jni) long, const long & "jint" 67 %typemap(jni) unsigned long, const unsigned long & "jlong" 68 %typemap(jni) long long, const long long & "jlong" 69 %typemap(jni) unsigned long long, const unsigned long long & "jobject" 70 %typemap(jni) float, const float & "jfloat" 71 %typemap(jni) double, const double & "jdouble" 72 %typemap(jni) void "void" 73 74 %typemap(jtype) bool, const bool & "boolean" 75 %typemap(jtype) char, const char & "char" 76 %typemap(jtype) signed char, const signed char & "byte" 77 %typemap(jtype) unsigned char, const unsigned char & "short" 78 %typemap(jtype) short, const short & "short" 79 %typemap(jtype) unsigned short, const unsigned short & "int" 80 %typemap(jtype) int, const int & "int" 81 %typemap(jtype) unsigned int, const unsigned int & "long" 82 %typemap(jtype) long, const long & "int" 83 %typemap(jtype) unsigned long, const unsigned long & "long" 84 %typemap(jtype) long long, const long long & "long" 85 %typemap(jtype) unsigned long long, const unsigned long long & "java.math.BigInteger" 86 %typemap(jtype) float, const float & "float" 87 %typemap(jtype) double, const double & "double" 88 %typemap(jtype) void "void" 89 90 %typemap(jstype) bool, const bool & "boolean" 91 %typemap(jstype) char, const char & "char" 92 %typemap(jstype) signed char, const signed char & "byte" 93 %typemap(jstype) unsigned char, const unsigned char & "short" 94 %typemap(jstype) short, const short & "short" 95 %typemap(jstype) unsigned short, const unsigned short & "int" 96 %typemap(jstype) int, const int & "int" 97 %typemap(jstype) unsigned int, const unsigned int & "long" 98 %typemap(jstype) long, const long & "int" 99 %typemap(jstype) unsigned long, const unsigned long & "long" 100 %typemap(jstype) long long, const long long & "long" 101 %typemap(jstype) unsigned long long, const unsigned long long & "java.math.BigInteger" 102 %typemap(jstype) float, const float & "float" 103 %typemap(jstype) double, const double & "double" 104 %typemap(jstype) void "void" 105 106 %typemap(jni) char *, char *&, char[ANY], char[] "jstring" 107 %typemap(jtype) char *, char *&, char[ANY], char[] "String" 108 %typemap(jstype) char *, char *&, char[ANY], char[] "String" 109 110 /* JNI types */ 111 %typemap(jni) jboolean "jboolean" 112 %typemap(jni) jchar "jchar" 113 %typemap(jni) jbyte "jbyte" 114 %typemap(jni) jshort "jshort" 115 %typemap(jni) jint "jint" 116 %typemap(jni) jlong "jlong" 117 %typemap(jni) jfloat "jfloat" 118 %typemap(jni) jdouble "jdouble" 119 %typemap(jni) jstring "jstring" 120 %typemap(jni) jobject "jobject" 121 %typemap(jni) jbooleanArray "jbooleanArray" 122 %typemap(jni) jcharArray "jcharArray" 123 %typemap(jni) jbyteArray "jbyteArray" 124 %typemap(jni) jshortArray "jshortArray" 125 %typemap(jni) jintArray "jintArray" 126 %typemap(jni) jlongArray "jlongArray" 127 %typemap(jni) jfloatArray "jfloatArray" 128 %typemap(jni) jdoubleArray "jdoubleArray" 129 %typemap(jni) jobjectArray "jobjectArray" 130 131 %typemap(jtype) jboolean "boolean" 132 %typemap(jtype) jchar "char" 133 %typemap(jtype) jbyte "byte" 134 %typemap(jtype) jshort "short" 135 %typemap(jtype) jint "int" 136 %typemap(jtype) jlong "long" 137 %typemap(jtype) jfloat "float" 138 %typemap(jtype) jdouble "double" 139 %typemap(jtype) jstring "String" 140 %typemap(jtype) jobject "Object" 141 %typemap(jtype) jbooleanArray "boolean[]" 142 %typemap(jtype) jcharArray "char[]" 143 %typemap(jtype) jbyteArray "byte[]" 144 %typemap(jtype) jshortArray "short[]" 145 %typemap(jtype) jintArray "int[]" 146 %typemap(jtype) jlongArray "long[]" 147 %typemap(jtype) jfloatArray "float[]" 148 %typemap(jtype) jdoubleArray "double[]" 149 %typemap(jtype) jobjectArray "Object[]" 150 151 %typemap(jstype) jboolean "boolean" 152 %typemap(jstype) jchar "char" 153 %typemap(jstype) jbyte "byte" 154 %typemap(jstype) jshort "short" 155 %typemap(jstype) jint "int" 156 %typemap(jstype) jlong "long" 157 %typemap(jstype) jfloat "float" 158 %typemap(jstype) jdouble "double" 159 %typemap(jstype) jstring "String" 160 %typemap(jstype) jobject "Object" 161 %typemap(jstype) jbooleanArray "boolean[]" 162 %typemap(jstype) jcharArray "char[]" 163 %typemap(jstype) jbyteArray "byte[]" 164 %typemap(jstype) jshortArray "short[]" 165 %typemap(jstype) jintArray "int[]" 166 %typemap(jstype) jlongArray "long[]" 167 %typemap(jstype) jfloatArray "float[]" 168 %typemap(jstype) jdoubleArray "double[]" 169 %typemap(jstype) jobjectArray "Object[]" 170 171 /* Non primitive types */ 172 %typemap(jni) SWIGTYPE "jlong" 173 %typemap(jtype) SWIGTYPE "long" 174 %typemap(jstype) SWIGTYPE "$&javaclassname" 175 176 %typemap(jni) SWIGTYPE [] "jlong" 177 %typemap(jtype) SWIGTYPE [] "long" 178 %typemap(jstype) SWIGTYPE [] "$javaclassname" 179 180 %typemap(jni) SWIGTYPE * "jlong" 181 %typemap(jtype) SWIGTYPE * "long" 182 %typemap(jstype) SWIGTYPE * "$javaclassname" 183 184 %typemap(jni) SWIGTYPE & "jlong" 185 %typemap(jtype) SWIGTYPE & "long" 186 %typemap(jstype) SWIGTYPE & "$javaclassname" 187 188 /* pointer to a class member */ 189 %typemap(jni) SWIGTYPE (CLASS::*) "jstring" 190 %typemap(jtype) SWIGTYPE (CLASS::*) "String" 191 %typemap(jstype) SWIGTYPE (CLASS::*) "$javaclassname" 192 193 /* 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. */ 194 195 /* primitive types */ 196 %typemap(in) bool 197 %{ $1 = $input ? true : false; %} 198 199 %typemap(directorout) bool 200 %{ $result = $input ? true : false; %} 201 202 %typemap(javadirectorin) bool "$jniinput" 203 %typemap(javadirectorout) bool "$javacall" 204 205 %typemap(in) char, 206 signed char, 207 unsigned char, 208 short, 209 unsigned short, 210 int, 211 unsigned int, 212 long, 213 unsigned long, 214 long long, 215 float, 216 double 217 %{ $1 = ($1_ltype)$input; %} 218 219 %typemap(directorout) char, 220 signed char, 221 unsigned char, 222 short, 223 unsigned short, 224 int, 225 unsigned int, 226 long, 227 unsigned long, 228 long long, 229 float, 230 double 231 %{ $result = ($1_ltype)$input; %} 232 233 %typemap(directorin, descriptor="Z") bool "$input = (jboolean) $1;" 234 %typemap(directorin, descriptor="C") char "$input = (jint) $1;" 235 %typemap(directorin, descriptor="B") signed char "$input = (jbyte) $1;" 236 %typemap(directorin, descriptor="S") unsigned char "$input = (jshort) $1;" 237 %typemap(directorin, descriptor="S") short "$input = (jshort) $1;" 238 %typemap(directorin, descriptor="I") unsigned short "$input = (jint) $1;" 239 %typemap(directorin, descriptor="I") int "$input = (jint) $1;" 240 %typemap(directorin, descriptor="J") unsigned int "$input = (jlong) $1;" 241 %typemap(directorin, descriptor="I") long "$input = (jint) $1;" 242 %typemap(directorin, descriptor="J") unsigned long "$input = (jlong) $1;" 243 %typemap(directorin, descriptor="J") long long "$input = (jlong) $1;" 244 %typemap(directorin, descriptor="F") float "$input = (jfloat) $1;" 245 %typemap(directorin, descriptor="D") double "$input = (jdouble) $1;" 246 247 %typemap(javadirectorin) char, 248 signed char, 249 unsigned char, 250 short, 251 unsigned short, 252 int, 253 unsigned int, 254 long, 255 unsigned long, 256 long long, 257 float, 258 double 259 "$jniinput" 260 261 %typemap(javadirectorout) char, 262 signed char, 263 unsigned char, 264 short, 265 unsigned short, 266 int, 267 unsigned int, 268 long, 269 unsigned long, 270 long long, 271 float, 272 double 273 "$javacall" 274 275 %typemap(out) bool %{ $result = (jboolean)$1; %} 276 %typemap(out) char %{ $result = (jchar)$1; %} 277 %typemap(out) signed char %{ $result = (jbyte)$1; %} 278 %typemap(out) unsigned char %{ $result = (jshort)$1; %} 279 %typemap(out) short %{ $result = (jshort)$1; %} 280 %typemap(out) unsigned short %{ $result = (jint)$1; %} 281 %typemap(out) int %{ $result = (jint)$1; %} 282 %typemap(out) unsigned int %{ $result = (jlong)$1; %} 283 %typemap(out) long %{ $result = (jint)$1; %} 284 %typemap(out) unsigned long %{ $result = (jlong)$1; %} 285 %typemap(out) long long %{ $result = (jlong)$1; %} 286 %typemap(out) float %{ $result = (jfloat)$1; %} 287 %typemap(out) double %{ $result = (jdouble)$1; %} 288 289 /* unsigned long long */ 290 /* Convert from BigInteger using the toByteArray member function */ 291 %typemap(in) unsigned long long { 292 jclass clazz; 293 jmethodID mid; 294 jbyteArray ba; 295 jbyte* bae; 296 jsize sz; 297 int i; 298 299 if (!$input) { 300 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null"); 301 return $null; 302 } 303 clazz = JCALL1(GetObjectClass, jenv, $input); 304 mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B"); 305 ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid); 306 bae = JCALL2(GetByteArrayElements, jenv, ba, 0); 307 sz = JCALL1(GetArrayLength, jenv, ba); 308 $1 = 0; 309 for(i=0; i<sz; i++) { 310 $1 = ($1 << 8) | ($1_type)(unsigned char)bae[i]; 311 } 312 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0); 313 } 314 315 %typemap(directorout) unsigned long long { 316 jclass clazz; 317 jmethodID mid; 318 jbyteArray ba; 319 jbyte* bae; 320 jsize sz; 321 int i; 322 323 if (!$input) { 324 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null"); 325 return $null; 326 } 327 clazz = JCALL1(GetObjectClass, jenv, $input); 328 mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B"); 329 ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid); 330 bae = JCALL2(GetByteArrayElements, jenv, ba, 0); 331 sz = JCALL1(GetArrayLength, jenv, ba); 332 $result = 0; 333 for(i=0; i<sz; i++) { 334 $result = ($result << 8) | ($1_type)(unsigned char)bae[i]; 335 } 336 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0); 337 } 338 339 340 /* Convert to BigInteger - byte array holds number in 2's complement big endian format */ 341 %typemap(out) unsigned long long { 342 jbyteArray ba = JCALL1(NewByteArray, jenv, 9); 343 jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0); 344 jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger"); 345 jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V"); 346 jobject bigint; 347 int i; 348 349 bae[0] = 0; 350 for(i=1; i<9; i++ ) { 351 bae[i] = (jbyte)($1>>8*(8-i)); 352 } 353 354 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0); 355 bigint = JCALL3(NewObject, jenv, clazz, mid, ba); 356 $result = bigint; 357 } 358 359 /* Convert to BigInteger (see out typemap) */ 360 %typemap(directorin, descriptor="Ljava/math/BigInteger;") unsigned long long, const unsigned long long & { 361 jbyteArray ba = JCALL1(NewByteArray, jenv, 9); 362 jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0); 363 jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger"); 364 jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V"); 365 jobject bigint; 366 int swig_i; 367 368 bae[0] = 0; 369 for(swig_i=1; swig_i<9; swig_i++ ) { 370 bae[swig_i] = (jbyte)($1>>8*(8-swig_i)); 371 } 372 373 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0); 374 bigint = JCALL3(NewObject, jenv, clazz, mid, ba); 375 $input = bigint; 376 } 377 378 %typemap(javadirectorin) unsigned long long "$jniinput" 379 %typemap(javadirectorout) unsigned long long "$javacall" 380 381 /* char * - treat as String */ 382 %typemap(in, noblock=1) char * { 383 $1 = 0; 384 if ($input) { 385 $1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0); 386 if (!$1) return $null; 387 } 388 } 389 390 %typemap(directorout, noblock=1, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * { 391 $1 = 0; 392 if ($input) { 393 $result = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0); 394 if (!$result) return $null; 395 } 396 } 397 398 %typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char * { 399 $input = 0; 400 if ($1) { 401 $input = JCALL1(NewStringUTF, jenv, (const char *)$1); 402 if (!$input) return $null; 403 } 404 } 405 406 %typemap(freearg, noblock=1) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)$1); } 407 %typemap(out, noblock=1) char * { if ($1) $result = JCALL1(NewStringUTF, jenv, (const char *)$1); } 408 %typemap(javadirectorin) char * "$jniinput" 409 %typemap(javadirectorout) char * "$javacall" 410 411 /* char *& - treat as String */ 412 %typemap(in, noblock=1) char *& ($*1_ltype temp = 0) { 413 $1 = 0; 414 if ($input) { 415 temp = ($*1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0); 416 if (!temp) return $null; 417 } 418 $1 = &temp; 419 } 420 %typemap(freearg, noblock=1) char *& { if ($1 && *$1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)*$1); } 421 %typemap(out, noblock=1) char *& { if (*$1) $result = JCALL1(NewStringUTF, jenv, (const char *)*$1); } 422 423 %typemap(out) void "" 424 %typemap(javadirectorin) void "$jniinput" 425 %typemap(javadirectorout) void "$javacall" 426 %typemap(directorin, descriptor="V") void "" 427 428 /* primitive types by reference */ 429 %typemap(in) const bool & ($*1_ltype temp) 430 %{ temp = $input ? true : false; 431 $1 = &temp; %} 432 433 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool & 434 %{ static $*1_ltype temp; 435 temp = $input ? true : false; 436 $result = &temp; %} 437 438 %typemap(javadirectorin) const bool & "$jniinput" 439 %typemap(javadirectorout) const bool & "$javacall" 440 441 %typemap(in) const char & ($*1_ltype temp), 442 const signed char & ($*1_ltype temp), 443 const unsigned char & ($*1_ltype temp), 444 const short & ($*1_ltype temp), 445 const unsigned short & ($*1_ltype temp), 446 const int & ($*1_ltype temp), 447 const unsigned int & ($*1_ltype temp), 448 const long & ($*1_ltype temp), 449 const unsigned long & ($*1_ltype temp), 450 const long long & ($*1_ltype temp), 451 const float & ($*1_ltype temp), 452 const double & ($*1_ltype temp) 453 %{ temp = ($*1_ltype)$input; 454 $1 = &temp; %} 455 456 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const char &, 457 const signed char &, 458 const unsigned char &, 459 const short &, 460 const unsigned short &, 461 const int &, 462 const unsigned int &, 463 const long &, 464 const unsigned long &, 465 const long long &, 466 const float &, 467 const double & 468 %{ static $*1_ltype temp; 469 temp = ($*1_ltype)$input; 470 $result = &temp; %} 471 472 %typemap(directorin, descriptor="Z") const bool & "$input = (jboolean)$1;" 473 %typemap(directorin, descriptor="C") const char & "$input = (jchar)$1;" 474 %typemap(directorin, descriptor="B") const signed char & "$input = (jbyte)$1;" 475 %typemap(directorin, descriptor="S") const unsigned char & "$input = (jshort)$1;" 476 %typemap(directorin, descriptor="S") const short & "$input = (jshort)$1;" 477 %typemap(directorin, descriptor="I") const unsigned short & "$input = (jint)$1;" 478 %typemap(directorin, descriptor="I") const int & "$input = (jint)$1;" 479 %typemap(directorin, descriptor="J") const unsigned int & "$input = (jlong)$1;" 480 %typemap(directorin, descriptor="I") const long & "$input = (jint)$1;" 481 %typemap(directorin, descriptor="J") const unsigned long & "$input = (jlong)$1;" 482 %typemap(directorin, descriptor="J") const long long & "$input = (jlong)$1;" 483 %typemap(directorin, descriptor="F") const float & "$input = (jfloat)$1;" 484 %typemap(directorin, descriptor="D") const double & "$input = (jdouble)$1;" 485 486 %typemap(javadirectorin) const char & ($*1_ltype temp), 487 const signed char & ($*1_ltype temp), 488 const unsigned char & ($*1_ltype temp), 489 const short & ($*1_ltype temp), 490 const unsigned short & ($*1_ltype temp), 491 const int & ($*1_ltype temp), 492 const unsigned int & ($*1_ltype temp), 493 const long & ($*1_ltype temp), 494 const unsigned long & ($*1_ltype temp), 495 const long long & ($*1_ltype temp), 496 const float & ($*1_ltype temp), 497 const double & ($*1_ltype temp) 498 "$jniinput" 499 500 %typemap(javadirectorout) const char & ($*1_ltype temp), 501 const signed char & ($*1_ltype temp), 502 const unsigned char & ($*1_ltype temp), 503 const short & ($*1_ltype temp), 504 const unsigned short & ($*1_ltype temp), 505 const int & ($*1_ltype temp), 506 const unsigned int & ($*1_ltype temp), 507 const long & ($*1_ltype temp), 508 const unsigned long & ($*1_ltype temp), 509 const long long & ($*1_ltype temp), 510 const float & ($*1_ltype temp), 511 const double & ($*1_ltype temp) 512 "$javacall" 513 514 515 %typemap(out) const bool & %{ $result = (jboolean)*$1; %} 516 %typemap(out) const char & %{ $result = (jchar)*$1; %} 517 %typemap(out) const signed char & %{ $result = (jbyte)*$1; %} 518 %typemap(out) const unsigned char & %{ $result = (jshort)*$1; %} 519 %typemap(out) const short & %{ $result = (jshort)*$1; %} 520 %typemap(out) const unsigned short & %{ $result = (jint)*$1; %} 521 %typemap(out) const int & %{ $result = (jint)*$1; %} 522 %typemap(out) const unsigned int & %{ $result = (jlong)*$1; %} 523 %typemap(out) const long & %{ $result = (jint)*$1; %} 524 %typemap(out) const unsigned long & %{ $result = (jlong)*$1; %} 525 %typemap(out) const long long & %{ $result = (jlong)*$1; %} 526 %typemap(out) const float & %{ $result = (jfloat)*$1; %} 527 %typemap(out) const double & %{ $result = (jdouble)*$1; %} 528 529 /* const unsigned long long & */ 530 /* Similar to unsigned long long */ 531 %typemap(in) const unsigned long long & ($*1_ltype temp) { 532 jclass clazz; 533 jmethodID mid; 534 jbyteArray ba; 535 jbyte* bae; 536 jsize sz; 537 int i; 538 539 if (!$input) { 540 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null"); 541 return $null; 542 } 543 clazz = JCALL1(GetObjectClass, jenv, $input); 544 mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B"); 545 ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid); 546 bae = JCALL2(GetByteArrayElements, jenv, ba, 0); 547 sz = JCALL1(GetArrayLength, jenv, ba); 548 $1 = &temp; 549 temp = 0; 550 for(i=0; i<sz; i++) { 551 temp = (temp << 8) | ($*1_ltype)(unsigned char)bae[i]; 552 } 553 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0); 554 } 555 556 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const unsigned long long & { 557 static $*1_ltype temp; 558 jclass clazz; 559 jmethodID mid; 560 jbyteArray ba; 561 jbyte* bae; 562 jsize sz; 563 int i; 564 565 if (!$input) { 566 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null"); 567 return $null; 568 } 569 clazz = JCALL1(GetObjectClass, jenv, $input); 570 mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B"); 571 ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid); 572 bae = JCALL2(GetByteArrayElements, jenv, ba, 0); 573 sz = JCALL1(GetArrayLength, jenv, ba); 574 $result = &temp; 575 temp = 0; 576 for(i=0; i<sz; i++) { 577 temp = (temp << 8) | ($*1_ltype)(unsigned char)bae[i]; 578 } 579 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0); 580 } 581 582 %typemap(out) const unsigned long long & { 583 jbyteArray ba = JCALL1(NewByteArray, jenv, 9); 584 jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0); 585 jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger"); 586 jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V"); 587 jobject bigint; 588 int i; 589 590 bae[0] = 0; 591 for(i=1; i<9; i++ ) { 592 bae[i] = (jbyte)(*$1>>8*(8-i)); 593 } 594 595 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0); 596 bigint = JCALL3(NewObject, jenv, clazz, mid, ba); 597 $result = bigint; 598 } 599 600 %typemap(javadirectorin) const unsigned long long & "$jniinput" 601 %typemap(javadirectorout) const unsigned long long & "$javacall" 602 603 /* Default handling. Object passed by value. Convert to a pointer */ 604 %typemap(in) SWIGTYPE ($&1_type argp) 605 %{ argp = *($&1_ltype*)&$input; 606 if (!argp) { 607 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); 608 return $null; 609 } 610 $1 = *argp; %} 611 612 %typemap(directorout) SWIGTYPE ($&1_type argp) 613 %{ argp = *($&1_ltype*)&$input; 614 if (!argp) { 615 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Unexpected null return for type $1_type"); 616 return $null; 617 } 618 $result = *argp; %} 619 620 %typemap(out) SWIGTYPE 621 #ifdef __cplusplus 622 %{ *($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1); %} 623 #else 624 { 625 $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); 626 memmove($1ptr, &$1, sizeof($1_type)); 627 *($&1_ltype*)&$result = $1ptr; 628 } 629 #endif 630 631 %typemap(directorin,descriptor="L$packagepath/$&javaclassname;") SWIGTYPE 632 %{ $input = 0; 633 *(($&1_ltype*)&$input) = &$1; %} 634 %typemap(javadirectorin) SWIGTYPE "new $&javaclassname($jniinput, false)" 635 %typemap(javadirectorout) SWIGTYPE "$&javaclassname.getCPtr($javacall)" 636 637 /* Generic pointers and references */ 638 %typemap(in) SWIGTYPE * %{ $1 = *($&1_ltype)&$input; %} 639 %typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) { 640 const char *temp = 0; 641 if ($input) { 642 temp = JCALL2(GetStringUTFChars, jenv, $input, 0); 643 if (!temp) return $null; 644 } 645 SWIG_UnpackData(temp, (void *)&$1, sizeof($1)); 646 } 647 %typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input; 648 if (!$1) { 649 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); 650 return $null; 651 } %} 652 %typemap(out) SWIGTYPE * 653 %{ *($&1_ltype)&$result = $1; %} 654 %typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) { 655 char buf[128]; 656 char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1)); 657 *data = '\0'; 658 $result = JCALL1(NewStringUTF, jenv, buf); 659 } 660 %typemap(out) SWIGTYPE & 661 %{ *($&1_ltype)&$result = $1; %} 662 663 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE * 664 %{ $result = *($&1_ltype)&$input; %} 665 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*) 666 %{ $result = *($&1_ltype)&$input; %} 667 668 %typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE * 669 %{ *(($&1_ltype)&$input) = ($1_ltype) $1; %} 670 %typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE (CLASS::*) 671 %{ *(($&1_ltype)&$input) = ($1_ltype) $1; %} 672 673 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE & 674 %{ if (!$input) { 675 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Unexpected null return for type $1_type"); 676 return $null; 677 } 678 $result = *($&1_ltype)&$input; %} 679 %typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE & 680 %{ *($&1_ltype)&$input = ($1_ltype) &$1; %} 681 682 %typemap(javadirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($jniinput == 0) ? null : new $javaclassname($jniinput, false)" 683 %typemap(javadirectorin) SWIGTYPE & "new $javaclassname($jniinput, false)" 684 %typemap(javadirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$javaclassname.getCPtr($javacall)" 685 686 /* Default array handling */ 687 %typemap(in) SWIGTYPE [] %{ $1 = *($&1_ltype)&$input; %} 688 %typemap(out) SWIGTYPE [] %{ *($&1_ltype)&$result = $1; %} 689 %typemap(freearg) SWIGTYPE [ANY], SWIGTYPE [] "" 690 691 /* char arrays - treat as String */ 692 %typemap(in, noblock=1) char[ANY], char[] { 693 $1 = 0; 694 if ($input) { 695 $1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0); 696 if (!$1) return $null; 697 } 698 } 699 700 %typemap(directorout, noblock=1) char[ANY], char[] { 701 $1 = 0; 702 if ($input) { 703 $result = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0); 704 if (!$result) return $null; 705 } 706 } 707 708 %typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char[ANY], char[] { 709 $input = 0; 710 if ($1) { 711 $input = JCALL1(NewStringUTF, jenv, (const char *)$1); 712 if (!$input) return $null; 713 } 714 } 715 716 %typemap(argout) char[ANY], char[] "" 717 %typemap(freearg, noblock=1) char[ANY], char[] { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)$1); } 718 %typemap(out, noblock=1) char[ANY], char[] { if ($1) $result = JCALL1(NewStringUTF, jenv, (const char *)$1); } 719 %typemap(javadirectorin) char[ANY], char[] "$jniinput" 720 %typemap(javadirectorout) char[ANY], char[] "$javacall" 721 722 /* JNI types */ 723 %typemap(in) jboolean, 724 jchar, 725 jbyte, 726 jshort, 727 jint, 728 jlong, 729 jfloat, 730 jdouble, 731 jstring, 732 jobject, 733 jbooleanArray, 734 jcharArray, 735 jbyteArray, 736 jshortArray, 737 jintArray, 738 jlongArray, 739 jfloatArray, 740 jdoubleArray, 741 jobjectArray 742 %{ $1 = $input; %} 743 744 %typemap(directorout) jboolean, 745 jchar, 746 jbyte, 747 jshort, 748 jint, 749 jlong, 750 jfloat, 751 jdouble, 752 jstring, 753 jobject, 754 jbooleanArray, 755 jcharArray, 756 jbyteArray, 757 jshortArray, 758 jintArray, 759 jlongArray, 760 jfloatArray, 761 jdoubleArray, 762 jobjectArray 763 %{ $result = $input; %} 764 765 %typemap(out) jboolean, 766 jchar, 767 jbyte, 768 jshort, 769 jint, 770 jlong, 771 jfloat, 772 jdouble, 773 jstring, 774 jobject, 775 jbooleanArray, 776 jcharArray, 777 jbyteArray, 778 jshortArray, 779 jintArray, 780 jlongArray, 781 jfloatArray, 782 jdoubleArray, 783 jobjectArray 784 %{ $result = $1; %} 785 786 %typemap(directorin,descriptor="Z") jboolean "$input = $1;" 787 %typemap(directorin,descriptor="C") jchar "$input = $1;" 788 %typemap(directorin,descriptor="B") jbyte "$input = $1;" 789 %typemap(directorin,descriptor="S") jshort "$input = $1;" 790 %typemap(directorin,descriptor="I") jint "$input = $1;" 791 %typemap(directorin,descriptor="J") jlong "$input = $1;" 792 %typemap(directorin,descriptor="F") jfloat "$input = $1;" 793 %typemap(directorin,descriptor="D") jdouble "$input = $1;" 794 %typemap(directorin,descriptor="Ljava/lang/String;") jstring "$input = $1;" 795 %typemap(directorin,descriptor="Ljava/lang/Object;",nouse="1") jobject "$input = $1;" 796 %typemap(directorin,descriptor="[Z") jbooleanArray "$input = $1;" 797 %typemap(directorin,descriptor="[C") jcharArray "$input = $1;" 798 %typemap(directorin,descriptor="[B") jbyteArray "$input = $1;" 799 %typemap(directorin,descriptor="[S") jshortArray "$input = $1;" 800 %typemap(directorin,descriptor="[I") jintArray "$input = $1;" 801 %typemap(directorin,descriptor="[J") jlongArray "$input = $1;" 802 %typemap(directorin,descriptor="[F") jfloatArray "$input = $1;" 803 %typemap(directorin,descriptor="[D") jdoubleArray "$input = $1;" 804 %typemap(directorin,descriptor="[Ljava/lang/Object;",nouse="1") jobjectArray "$input = $1;" 805 806 %typemap(javadirectorin) jboolean, 807 jchar, 808 jbyte, 809 jshort, 810 jint, 811 jlong, 812 jfloat, 813 jdouble, 814 jstring, 815 jobject, 816 jbooleanArray, 817 jcharArray, 818 jbyteArray, 819 jshortArray, 820 jintArray, 821 jlongArray, 822 jfloatArray, 823 jdoubleArray, 824 jobjectArray 825 "$jniinput" 826 827 %typemap(javadirectorout) jboolean, 828 jchar, 829 jbyte, 830 jshort, 831 jint, 832 jlong, 833 jfloat, 834 jdouble, 835 jstring, 836 jobject, 837 jbooleanArray, 838 jcharArray, 839 jbyteArray, 840 jshortArray, 841 jintArray, 842 jlongArray, 843 jfloatArray, 844 jdoubleArray, 845 jobjectArray 846 "$javacall" 847 848 /* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions 849 * that cannot be overloaded in Java as more than one C++ type maps to a single Java type */ 850 851 %typecheck(SWIG_TYPECHECK_BOOL) /* Java boolean */ 852 jboolean, 853 bool, 854 const bool & 855 "" 856 857 %typecheck(SWIG_TYPECHECK_CHAR) /* Java char */ 858 jchar, 859 char, 860 const char & 861 "" 862 863 %typecheck(SWIG_TYPECHECK_INT8) /* Java byte */ 864 jbyte, 865 signed char, 866 const signed char & 867 "" 868 869 %typecheck(SWIG_TYPECHECK_INT16) /* Java short */ 870 jshort, 871 unsigned char, 872 short, 873 const unsigned char &, 874 const short & 875 "" 876 877 %typecheck(SWIG_TYPECHECK_INT32) /* Java int */ 878 jint, 879 unsigned short, 880 int, 881 long, 882 const unsigned short &, 883 const int &, 884 const long & 885 "" 886 887 %typecheck(SWIG_TYPECHECK_INT64) /* Java long */ 888 jlong, 889 unsigned int, 890 unsigned long, 891 long long, 892 const unsigned int &, 893 const unsigned long &, 894 const long long & 895 "" 896 897 %typecheck(SWIG_TYPECHECK_INT128) /* Java BigInteger */ 898 unsigned long long, 899 const unsigned long long & 900 "" 901 902 %typecheck(SWIG_TYPECHECK_FLOAT) /* Java float */ 903 jfloat, 904 float, 905 const float & 906 "" 907 908 %typecheck(SWIG_TYPECHECK_DOUBLE) /* Java double */ 909 jdouble, 910 double, 911 const double & 912 "" 913 914 %typecheck(SWIG_TYPECHECK_STRING) /* Java String */ 915 jstring, 916 char *, 917 char *&, 918 char[ANY], 919 char [] 920 "" 921 922 %typecheck(SWIG_TYPECHECK_BOOL_ARRAY) /* Java boolean[] */ 923 jbooleanArray 924 "" 925 926 %typecheck(SWIG_TYPECHECK_CHAR_ARRAY) /* Java char[] */ 927 jcharArray 928 "" 929 930 %typecheck(SWIG_TYPECHECK_INT8_ARRAY) /* Java byte[] */ 931 jbyteArray 932 "" 933 934 %typecheck(SWIG_TYPECHECK_INT16_ARRAY) /* Java short[] */ 935 jshortArray 936 "" 937 938 %typecheck(SWIG_TYPECHECK_INT32_ARRAY) /* Java int[] */ 939 jintArray 940 "" 941 942 %typecheck(SWIG_TYPECHECK_INT64_ARRAY) /* Java long[] */ 943 jlongArray 944 "" 945 946 %typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) /* Java float[] */ 947 jfloatArray 948 "" 949 950 %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) /* Java double[] */ 951 jdoubleArray 952 "" 953 954 %typecheck(SWIG_TYPECHECK_OBJECT_ARRAY) /* Java jobject[] */ 955 jobjectArray 956 "" 957 958 %typecheck(SWIG_TYPECHECK_POINTER) /* Default */ 959 SWIGTYPE, 960 SWIGTYPE *, 961 SWIGTYPE &, 962 SWIGTYPE *const&, 963 SWIGTYPE [], 964 SWIGTYPE (CLASS::*) 965 "" 966 967 968 /* Exception handling */ 969 970 %typemap(throws) int, 971 long, 972 short, 973 unsigned int, 974 unsigned long, 975 unsigned short 976 %{ char error_msg[256]; 977 sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1); 978 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, error_msg); 979 return $null; %} 980 981 %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] 982 %{ (void)$1; 983 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown"); 984 return $null; %} 985 986 %typemap(throws) char * 987 %{ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1); 988 return $null; %} 989 990 991 /* Typemaps for code generation in proxy classes and Java type wrapper classes */ 992 993 /* The javain typemap is used for converting function parameter types from the type 994 * used in the proxy, module or type wrapper class to the type used in the JNI class. */ 995 %typemap(javain) bool, const bool &, 996 char, const char &, 997 signed char, const signed char &, 998 unsigned char, const unsigned char &, 999 short, const short &, 1000 unsigned short, const unsigned short &, 1001 int, const int &, 1002 unsigned int, const unsigned int &, 1003 long, const long &, 1004 unsigned long, const unsigned long &, 1005 long long, const long long &, 1006 unsigned long long, const unsigned long long &, 1007 float, const float &, 1008 double, const double & 1009 "$javainput" 1010 %typemap(javain) char *, char *&, char[ANY], char[] "$javainput" 1011 %typemap(javain) jboolean, 1012 jchar, 1013 jbyte, 1014 jshort, 1015 jint, 1016 jlong, 1017 jfloat, 1018 jdouble, 1019 jstring, 1020 jobject, 1021 jbooleanArray, 1022 jcharArray, 1023 jbyteArray, 1024 jshortArray, 1025 jintArray, 1026 jlongArray, 1027 jfloatArray, 1028 jdoubleArray, 1029 jobjectArray 1030 "$javainput" 1031 %typemap(javain) SWIGTYPE "$&javaclassname.getCPtr($javainput)" 1032 %typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$javaclassname.getCPtr($javainput)" 1033 %typemap(javain) SWIGTYPE (CLASS::*) "$javaclassname.getCMemberPtr($javainput)" 1034 1035 /* The javaout typemap is used for converting function return types from the return type 1036 * used in the JNI class to the type returned by the proxy, module or type wrapper class. */ 1037 %typemap(javaout) bool, const bool &, 1038 char, const char &, 1039 signed char, const signed char &, 1040 unsigned char, const unsigned char &, 1041 short, const short &, 1042 unsigned short, const unsigned short &, 1043 int, const int &, 1044 unsigned int, const unsigned int &, 1045 long, const long &, 1046 unsigned long, const unsigned long &, 1047 long long, const long long &, 1048 unsigned long long, const unsigned long long &, 1049 float, const float &, 1050 double, const double & { 1051 return $jnicall; 1052 } 1053 %typemap(javaout) char *, char *&, char[ANY], char[] { 1054 return $jnicall; 1055 } 1056 %typemap(javaout) jboolean, 1057 jchar, 1058 jbyte, 1059 jshort, 1060 jint, 1061 jlong, 1062 jfloat, 1063 jdouble, 1064 jstring, 1065 jobject, 1066 jbooleanArray, 1067 jcharArray, 1068 jbyteArray, 1069 jshortArray, 1070 jintArray, 1071 jlongArray, 1072 jfloatArray, 1073 jdoubleArray, 1074 jobjectArray { 1075 return $jnicall; 1076 } 1077 %typemap(javaout) void { 1078 $jnicall; 1079 } 1080 %typemap(javaout) SWIGTYPE { 1081 return new $&javaclassname($jnicall, true); 1082 } 1083 %typemap(javaout) SWIGTYPE & { 1084 return new $javaclassname($jnicall, $owner); 1085 } 1086 %typemap(javaout) SWIGTYPE *, SWIGTYPE [] { 1087 long cPtr = $jnicall; 1088 return (cPtr == 0) ? null : new $javaclassname(cPtr, $owner); 1089 } 1090 %typemap(javaout) SWIGTYPE (CLASS::*) { 1091 String cMemberPtr = $jnicall; 1092 return (cMemberPtr == null) ? null : new $javaclassname(cMemberPtr, $owner); 1093 } 1094 1095 /* Pointer reference typemaps */ 1096 %typemap(jni) SWIGTYPE *const& "jlong" 1097 %typemap(jtype) SWIGTYPE *const& "long" 1098 %typemap(jstype) SWIGTYPE *const& "$*javaclassname" 1099 %typemap(javain) SWIGTYPE *const& "$*javaclassname.getCPtr($javainput)" 1100 %typemap(javaout) SWIGTYPE *const& { 1101 long cPtr = $jnicall; 1102 return (cPtr == 0) ? null : new $*javaclassname(cPtr, $owner); 1103 } 1104 %typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) 1105 %{ temp = *($1_ltype)&$input; 1106 $1 = ($1_ltype)&temp; %} 1107 %typemap(out) SWIGTYPE *const& 1108 %{ *($1_ltype)&$result = *$1; %} 1109 1110 /* Typemaps used for the generation of proxy and type wrapper class code */ 1111 %typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" 1112 %typemap(javaclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" 1113 %typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" 1114 %typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" 1115 %typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" 1116 1117 /* javabody typemaps */ 1118 1119 %define SWIG_JAVABODY_METHODS(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE) %enddef // legacy name 1120 1121 %define SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) 1122 // Base proxy classes 1123 %typemap(javabody) TYPE %{ 1124 private long swigCPtr; 1125 protected boolean swigCMemOwn; 1126 1127 PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { 1128 swigCMemOwn = cMemoryOwn; 1129 swigCPtr = cPtr; 1130 } 1131 1132 CPTR_VISIBILITY static long getCPtr($javaclassname obj) { 1133 return (obj == null) ? 0 : obj.swigCPtr; 1134 } 1135 %} 1136 1137 // Derived proxy classes 1138 %typemap(javabody_derived) TYPE %{ 1139 private long swigCPtr; 1140 1141 PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { 1142 super($imclassname.$javaclazznameSWIGUpcast(cPtr), cMemoryOwn); 1143 swigCPtr = cPtr; 1144 } 1145 1146 CPTR_VISIBILITY static long getCPtr($javaclassname obj) { 1147 return (obj == null) ? 0 : obj.swigCPtr; 1148 } 1149 %} 1150 %enddef 1151 1152 %define SWIG_JAVABODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) 1153 // Typewrapper classes 1154 %typemap(javabody) TYPE *, TYPE &, TYPE [] %{ 1155 private long swigCPtr; 1156 1157 PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean futureUse) { 1158 swigCPtr = cPtr; 1159 } 1160 1161 DEFAULTCTOR_VISIBILITY $javaclassname() { 1162 swigCPtr = 0; 1163 } 1164 1165 CPTR_VISIBILITY static long getCPtr($javaclassname obj) { 1166 return (obj == null) ? 0 : obj.swigCPtr; 1167 } 1168 %} 1169 1170 %typemap(javabody) TYPE (CLASS::*) %{ 1171 private String swigCMemberPtr; 1172 1173 PTRCTOR_VISIBILITY $javaclassname(String cMemberPtr, boolean futureUse) { 1174 swigCMemberPtr = cMemberPtr; 1175 } 1176 1177 DEFAULTCTOR_VISIBILITY $javaclassname() { 1178 swigCMemberPtr = null; 1179 } 1180 1181 CPTR_VISIBILITY static String getCMemberPtr($javaclassname obj) { 1182 return obj.swigCMemberPtr; 1183 } 1184 %} 1185 %enddef 1186 1187 /* Set the default javabody typemaps to use protected visibility. 1188 Use the macros to change to public if using multiple modules. */ 1189 SWIG_JAVABODY_PROXY(protected, protected, SWIGTYPE) 1190 SWIG_JAVABODY_TYPEWRAPPER(protected, protected, protected, SWIGTYPE) 1191 1192 %typemap(javafinalize) SWIGTYPE %{ 1193 protected void finalize() { 1194 delete(); 1195 } 1196 %} 1197 1198 /* 1199 * Java constructor typemaps: 1200 * 1201 * The javaconstruct typemap is inserted when a proxy class's constructor is generated. 1202 * This typemap allows control over what code is executed in the constructor as 1203 * well as specifying who owns the underlying C/C++ object. Normally, Java has 1204 * ownership and the underlying C/C++ object is deallocated when the Java object 1205 * is finalized (swigCMemOwn is true.) If swigCMemOwn is false, C/C++ is 1206 * ultimately responsible for deallocating the underlying object's memory. 1207 * 1208 * The SWIG_PROXY_CONSTRUCTOR macro defines the javaconstruct typemap for a proxy 1209 * class for a particular TYPENAME. OWNERSHIP is passed as the value of 1210 * swigCMemOwn to the pointer constructor method. WEAKREF determines which kind 1211 * of Java object reference will be used by the C++ director class (WeakGlobalRef 1212 * vs. GlobalRef.) 1213 * 1214 * The SWIG_DIRECTOR_OWNED macro sets the ownership of director-based proxy 1215 * classes and the weak reference flag to false, meaning that the underlying C++ 1216 * object will be reclaimed by C++. 1217 */ 1218 1219 %define SWIG_PROXY_CONSTRUCTOR(OWNERSHIP, WEAKREF, TYPENAME...) 1220 %typemap(javaconstruct,directorconnect="\n $imclassname.$javaclazznamedirector_connect(this, swigCPtr, swigCMemOwn, WEAKREF);") TYPENAME { 1221 this($imcall, OWNERSHIP);$directorconnect 1222 } 1223 %enddef 1224 1225 %define SWIG_DIRECTOR_OWNED(TYPENAME...) 1226 SWIG_PROXY_CONSTRUCTOR(true, false, TYPENAME) 1227 %enddef 1228 1229 // Set the default for SWIGTYPE: Java owns the C/C++ object. 1230 SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) 1231 1232 %typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE { 1233 if (swigCPtr != 0) { 1234 if (swigCMemOwn) { 1235 swigCMemOwn = false; 1236 $jnicall; 1237 } 1238 swigCPtr = 0; 1239 } 1240 } 1241 1242 %typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE { 1243 if (swigCPtr != 0) { 1244 if (swigCMemOwn) { 1245 swigCMemOwn = false; 1246 $jnicall; 1247 } 1248 swigCPtr = 0; 1249 } 1250 super.delete(); 1251 } 1252 1253 %typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{ 1254 protected void $methodname() { 1255 swigCMemOwn = false; 1256 $jnicall; 1257 } 1258 %} 1259 1260 %typemap(directorowner_release, methodname="swigReleaseOwnership") SWIGTYPE %{ 1261 public void $methodname() { 1262 swigCMemOwn = false; 1263 $jnicall; 1264 } 1265 %} 1266 1267 %typemap(directorowner_take, methodname="swigTakeOwnership") SWIGTYPE %{ 1268 public void $methodname() { 1269 swigCMemOwn = true; 1270 $jnicall; 1271 } 1272 %} 1273 1274 /* Java specific directives */ 1275 #define %javaconst(flag) %feature("java:const","flag") 1276 #define %javaconstvalue(value) %feature("java:constvalue",value) 1277 #define %javaenum(wrapapproach) %feature("java:enum","wrapapproach") 1278 #define %javamethodmodifiers %feature("java:methodmodifiers") 1279 #define %javaexception(exceptionclasses) %feature("except",throws=exceptionclasses) 1280 #define %nojavaexception %feature("except","0",throws="") 1281 #define %clearjavaexception %feature("except","",throws="") 1282 1283 %pragma(java) jniclassclassmodifiers="public class" 1284 %pragma(java) moduleclassmodifiers="public class" 1285 1286 /* Some ANSI C typemaps */ 1287 1288 %apply unsigned long { size_t }; 1289 %apply const unsigned long & { const size_t & }; 1290 1291 /* Array reference typemaps */ 1292 %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } 1293 1294 /* const pointers */ 1295 %apply SWIGTYPE * { SWIGTYPE *const } 1296 1297 /* String & length */ 1298 %typemap(jni) (char *STRING, size_t LENGTH) "jbyteArray" 1299 %typemap(jtype) (char *STRING, size_t LENGTH) "byte[]" 1300 %typemap(jstype) (char *STRING, size_t LENGTH) "byte[]" 1301 %typemap(javain) (char *STRING, size_t LENGTH) "$javainput" 1302 %typemap(freearg) (char *STRING, size_t LENGTH) "" 1303 %typemap(in) (char *STRING, size_t LENGTH) { 1304 if ($input) { 1305 $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0); 1306 $2 = (size_t) JCALL1(GetArrayLength, jenv, $input); 1307 } else { 1308 $1 = 0; 1309 $2 = 0; 1310 } 1311 } 1312 %typemap(argout) (char *STRING, size_t LENGTH) { 1313 if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); 1314 } 1315 %typemap(directorin, descriptor="[B") (char *STRING, size_t LENGTH) { 1316 jbyteArray jb = (jenv)->NewByteArray($2); 1317 (jenv)->SetByteArrayRegion(jb, 0, $2, (jbyte *)$1); 1318 $input = jb; 1319 } 1320 %typemap(directorargout) (char *STRING, size_t LENGTH) 1321 %{(jenv)->GetByteArrayRegion($input, 0, $2, (jbyte *)$1); %} 1322 %apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) } 1323 1324 /* java keywords */ 1325 %include <javakw.swg> 1326 1327 // Default enum handling 1328 %include <enumtypesafe.swg> 1329 1330