java.swg 47 KB

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