PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Lib/tcl/typemaps.i

#
Swig | 467 lines | 290 code | 40 blank | 137 comment | 0 complexity | 09d5630e762daa4b85c8113d4e02d6a3 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * typemaps.i
  6. *
  7. * Swig typemap library for Tcl8. This file contains various sorts
  8. * of typemaps for modifying Swig's code generation.
  9. * ----------------------------------------------------------------------------- */
  10. #if !defined(SWIG_USE_OLD_TYPEMAPS)
  11. %include <typemaps/typemaps.swg>
  12. #else
  13. /*
  14. The SWIG typemap library provides a language independent mechanism for
  15. supporting output arguments, input values, and other C function
  16. calling mechanisms. The primary use of the library is to provide a
  17. better interface to certain C function--especially those involving
  18. pointers.
  19. */
  20. // INPUT typemaps.
  21. // These remap a C pointer to be an "INPUT" value which is passed by value
  22. // instead of reference.
  23. /*
  24. The following methods can be applied to turn a pointer into a simple
  25. "input" value. That is, instead of passing a pointer to an object,
  26. you would use a real value instead.
  27. int *INPUT
  28. short *INPUT
  29. long *INPUT
  30. long long *INPUT
  31. unsigned int *INPUT
  32. unsigned short *INPUT
  33. unsigned long *INPUT
  34. unsigned long long *INPUT
  35. unsigned char *INPUT
  36. bool *INPUT
  37. float *INPUT
  38. double *INPUT
  39. To use these, suppose you had a C function like this :
  40. double fadd(double *a, double *b) {
  41. return *a+*b;
  42. }
  43. You could wrap it with SWIG as follows :
  44. %include typemaps.i
  45. double fadd(double *INPUT, double *INPUT);
  46. or you can use the %apply directive :
  47. %include typemaps.i
  48. %apply double *INPUT { double *a, double *b };
  49. double fadd(double *a, double *b);
  50. */
  51. %typemap(in) double *INPUT(double temp), double &INPUT(double temp)
  52. {
  53. if (Tcl_GetDoubleFromObj(interp,$input,&temp) == TCL_ERROR) {
  54. SWIG_fail;
  55. }
  56. $1 = &temp;
  57. }
  58. %typemap(in) float *INPUT(double dvalue, float temp), float &INPUT(double dvalue, float temp)
  59. {
  60. if (Tcl_GetDoubleFromObj(interp,$input,&dvalue) == TCL_ERROR) {
  61. SWIG_fail;
  62. }
  63. temp = (float) dvalue;
  64. $1 = &temp;
  65. }
  66. %typemap(in) int *INPUT(int temp), int &INPUT(int temp)
  67. {
  68. if (Tcl_GetIntFromObj(interp,$input,&temp) == TCL_ERROR) {
  69. SWIG_fail;
  70. }
  71. $1 = &temp;
  72. }
  73. %typemap(in) short *INPUT(int ivalue, short temp), short &INPUT(int ivalue, short temp)
  74. {
  75. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  76. SWIG_fail;
  77. }
  78. temp = (short) ivalue;
  79. $1 = &temp;
  80. }
  81. %typemap(in) long *INPUT(int ivalue, long temp), long &INPUT(int ivalue, long temp)
  82. {
  83. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  84. SWIG_fail;
  85. }
  86. temp = (long) ivalue;
  87. $1 = &temp;
  88. }
  89. %typemap(in) unsigned int *INPUT(int ivalue, unsigned int temp),
  90. unsigned int &INPUT(int ivalue, unsigned int temp)
  91. {
  92. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  93. SWIG_fail;
  94. }
  95. temp = (unsigned int) ivalue;
  96. $1 = &temp;
  97. }
  98. %typemap(in) unsigned short *INPUT(int ivalue, unsigned short temp),
  99. unsigned short &INPUT(int ivalue, unsigned short temp)
  100. {
  101. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  102. SWIG_fail;
  103. }
  104. temp = (unsigned short) ivalue;
  105. $1 = &temp;
  106. }
  107. %typemap(in) unsigned long *INPUT(int ivalue, unsigned long temp),
  108. unsigned long &INPUT(int ivalue, unsigned long temp)
  109. {
  110. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  111. SWIG_fail;
  112. }
  113. temp = (unsigned long) ivalue;
  114. $1 = &temp;
  115. }
  116. %typemap(in) unsigned char *INPUT(int ivalue, unsigned char temp),
  117. unsigned char &INPUT(int ivalue, unsigned char temp)
  118. {
  119. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  120. SWIG_fail;
  121. }
  122. temp = (unsigned char) ivalue;
  123. $1 = &temp;
  124. }
  125. %typemap(in) signed char *INPUT(int ivalue, signed char temp),
  126. signed char &INPUT(int ivalue, signed char temp)
  127. {
  128. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  129. SWIG_fail;
  130. }
  131. temp = (signed char) ivalue;
  132. $1 = &temp;
  133. }
  134. %typemap(in) bool *INPUT(int ivalue, bool temp),
  135. bool &INPUT(int ivalue, bool temp)
  136. {
  137. if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
  138. SWIG_fail;
  139. }
  140. temp = ivalue ? true : false;
  141. $1 = &temp;
  142. }
  143. %typemap(in) long long *INPUT($*1_ltype temp),
  144. long long &INPUT($*1_ltype temp)
  145. {
  146. temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);
  147. $1 = &temp;
  148. }
  149. %typemap(in) unsigned long long *INPUT($*1_ltype temp),
  150. unsigned long long &INPUT($*1_ltype temp)
  151. {
  152. temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0);
  153. $1 = &temp;
  154. }
  155. // OUTPUT typemaps. These typemaps are used for parameters that
  156. // are output only. The output value is appended to the result as
  157. // a list element.
  158. /*
  159. The following methods can be applied to turn a pointer into an "output"
  160. value. When calling a function, no input value would be given for
  161. a parameter, but an output value would be returned. In the case of
  162. multiple output values, they are returned in the form of a Tcl list.
  163. int *OUTPUT
  164. short *OUTPUT
  165. long *OUTPUT
  166. long long *OUTPUT
  167. unsigned int *OUTPUT
  168. unsigned short *OUTPUT
  169. unsigned long *OUTPUT
  170. unsigned long long *OUTPUT
  171. unsigned char *OUTPUT
  172. bool *OUTPUT
  173. float *OUTPUT
  174. double *OUTPUT
  175. For example, suppose you were trying to wrap the modf() function in the
  176. C math library which splits x into integral and fractional parts (and
  177. returns the integer part in one of its parameters).K:
  178. double modf(double x, double *ip);
  179. You could wrap it with SWIG as follows :
  180. %include typemaps.i
  181. double modf(double x, double *OUTPUT);
  182. or you can use the %apply directive :
  183. %include typemaps.i
  184. %apply double *OUTPUT { double *ip };
  185. double modf(double x, double *ip);
  186. The Tcl output of the function would be a list containing both
  187. output values.
  188. */
  189. %typemap(in,numinputs=0) int *OUTPUT(int temp),
  190. short *OUTPUT(short temp),
  191. long *OUTPUT(long temp),
  192. unsigned int *OUTPUT(unsigned int temp),
  193. unsigned short *OUTPUT(unsigned short temp),
  194. unsigned long *OUTPUT(unsigned long temp),
  195. unsigned char *OUTPUT(unsigned char temp),
  196. signed char *OUTPUT(signed char temp),
  197. bool *OUTPUT(bool temp),
  198. float *OUTPUT(float temp),
  199. double *OUTPUT(double temp),
  200. long long *OUTPUT($*1_ltype temp),
  201. unsigned long long *OUTPUT($*1_ltype temp),
  202. int &OUTPUT(int temp),
  203. short &OUTPUT(short temp),
  204. long &OUTPUT(long temp),
  205. unsigned int &OUTPUT(unsigned int temp),
  206. unsigned short &OUTPUT(unsigned short temp),
  207. unsigned long &OUTPUT(unsigned long temp),
  208. signed char &OUTPUT(signed char temp),
  209. bool &OUTPUT(bool temp),
  210. unsigned char &OUTPUT(unsigned char temp),
  211. float &OUTPUT(float temp),
  212. double &OUTPUT(double temp),
  213. long long &OUTPUT($*1_ltype temp),
  214. unsigned long long &OUTPUT($*1_ltype temp)
  215. "$1 = &temp;";
  216. %typemap(argout) int *OUTPUT, int &OUTPUT,
  217. short *OUTPUT, short &OUTPUT,
  218. long *OUTPUT, long &OUTPUT,
  219. unsigned int *OUTPUT, unsigned int &OUTPUT,
  220. unsigned short *OUTPUT, unsigned short &OUTPUT,
  221. unsigned long *OUTPUT, unsigned long &OUTPUT,
  222. unsigned char *OUTPUT, unsigned char &OUTPUT,
  223. signed char *OUTPUT, signed char &OUTPUT,
  224. bool *OUTPUT, bool &OUTPUT
  225. {
  226. Tcl_Obj *o;
  227. o = Tcl_NewIntObj((int) *($1));
  228. Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
  229. }
  230. %typemap(argout) float *OUTPUT, float &OUTPUT,
  231. double *OUTPUT, double &OUTPUT
  232. {
  233. Tcl_Obj *o;
  234. o = Tcl_NewDoubleObj((double) *($1));
  235. Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
  236. }
  237. %typemap(argout) long long *OUTPUT, long long &OUTPUT
  238. {
  239. char temp[256];
  240. Tcl_Obj *o;
  241. sprintf(temp,"%lld",(long long)*($1));
  242. o = Tcl_NewStringObj(temp,-1);
  243. Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
  244. }
  245. %typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT
  246. {
  247. char temp[256];
  248. Tcl_Obj *o;
  249. sprintf(temp,"%llu",(unsigned long long)*($1));
  250. o = Tcl_NewStringObj(temp,-1);
  251. Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
  252. }
  253. // INOUT
  254. // Mappings for an argument that is both an input and output
  255. // parameter
  256. /*
  257. The following methods can be applied to make a function parameter both
  258. an input and output value. This combines the behavior of both the
  259. "INPUT" and "OUTPUT" methods described earlier. Output values are
  260. returned in the form of a Tcl list.
  261. int *INOUT
  262. short *INOUT
  263. long *INOUT
  264. long long *INOUT
  265. unsigned int *INOUT
  266. unsigned short *INOUT
  267. unsigned long *INOUT
  268. unsigned long long *INOUT
  269. unsigned char *INOUT
  270. bool *INOUT
  271. float *INOUT
  272. double *INOUT
  273. For example, suppose you were trying to wrap the following function :
  274. void neg(double *x) {
  275. *x = -(*x);
  276. }
  277. You could wrap it with SWIG as follows :
  278. %include typemaps.i
  279. void neg(double *INOUT);
  280. or you can use the %apply directive :
  281. %include typemaps.i
  282. %apply double *INOUT { double *x };
  283. void neg(double *x);
  284. Unlike C, this mapping does not directly modify the input value (since
  285. this makes no sense in Tcl). Rather, the modified input value shows
  286. up as the return value of the function. Thus, to apply this function
  287. to a Tcl variable you might do this :
  288. set x [neg $x]
  289. */
  290. %typemap(in) int *INOUT = int *INPUT;
  291. %typemap(in) short *INOUT = short *INPUT;
  292. %typemap(in) long *INOUT = long *INPUT;
  293. %typemap(in) unsigned int *INOUT = unsigned int *INPUT;
  294. %typemap(in) unsigned short *INOUT = unsigned short *INPUT;
  295. %typemap(in) unsigned long *INOUT = unsigned long *INPUT;
  296. %typemap(in) unsigned char *INOUT = unsigned char *INPUT;
  297. %typemap(in) signed char *INOUT = signed char *INPUT;
  298. %typemap(in) bool *INOUT = bool *INPUT;
  299. %typemap(in) float *INOUT = float *INPUT;
  300. %typemap(in) double *INOUT = double *INPUT;
  301. %typemap(in) long long *INOUT = long long *INPUT;
  302. %typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
  303. %typemap(in) int &INOUT = int &INPUT;
  304. %typemap(in) short &INOUT = short &INPUT;
  305. %typemap(in) long &INOUT = long &INPUT;
  306. %typemap(in) unsigned int &INOUT = unsigned int &INPUT;
  307. %typemap(in) unsigned short &INOUT = unsigned short &INPUT;
  308. %typemap(in) unsigned long &INOUT = unsigned long &INPUT;
  309. %typemap(in) unsigned char &INOUT = unsigned char &INPUT;
  310. %typemap(in) signed char &INOUT = signed char &INPUT;
  311. %typemap(in) bool &INOUT = bool &INPUT;
  312. %typemap(in) float &INOUT = float &INPUT;
  313. %typemap(in) double &INOUT = double &INPUT;
  314. %typemap(in) long long &INOUT = long long &INPUT;
  315. %typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
  316. %typemap(argout) int *INOUT = int *OUTPUT;
  317. %typemap(argout) short *INOUT = short *OUTPUT;
  318. %typemap(argout) long *INOUT = long *OUTPUT;
  319. %typemap(argout) unsigned int *INOUT = unsigned int *OUTPUT;
  320. %typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
  321. %typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
  322. %typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
  323. %typemap(argout) signed char *INOUT = signed char *OUTPUT;
  324. %typemap(argout) bool *INOUT = bool *OUTPUT;
  325. %typemap(argout) float *INOUT = float *OUTPUT;
  326. %typemap(argout) double *INOUT = double *OUTPUT;
  327. %typemap(argout) long long *INOUT = long long *OUTPUT;
  328. %typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
  329. %typemap(argout) int &INOUT = int &OUTPUT;
  330. %typemap(argout) short &INOUT = short &OUTPUT;
  331. %typemap(argout) long &INOUT = long &OUTPUT;
  332. %typemap(argout) unsigned int &INOUT = unsigned int &OUTPUT;
  333. %typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
  334. %typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
  335. %typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
  336. %typemap(argout) signed char &INOUT = signed char &OUTPUT;
  337. %typemap(argout) bool &INOUT = bool &OUTPUT;
  338. %typemap(argout) float &INOUT = float &OUTPUT;
  339. %typemap(argout) double &INOUT = double &OUTPUT;
  340. %typemap(argout) long long &INOUT = long long &OUTPUT;
  341. %typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
  342. /* Overloading information */
  343. %typemap(typecheck) double *INPUT = double;
  344. %typemap(typecheck) bool *INPUT = bool;
  345. %typemap(typecheck) signed char *INPUT = signed char;
  346. %typemap(typecheck) unsigned char *INPUT = unsigned char;
  347. %typemap(typecheck) unsigned long *INPUT = unsigned long;
  348. %typemap(typecheck) unsigned short *INPUT = unsigned short;
  349. %typemap(typecheck) unsigned int *INPUT = unsigned int;
  350. %typemap(typecheck) long *INPUT = long;
  351. %typemap(typecheck) short *INPUT = short;
  352. %typemap(typecheck) int *INPUT = int;
  353. %typemap(typecheck) float *INPUT = float;
  354. %typemap(typecheck) long long *INPUT = long long;
  355. %typemap(typecheck) unsigned long long *INPUT = unsigned long long;
  356. %typemap(typecheck) double &INPUT = double;
  357. %typemap(typecheck) bool &INPUT = bool;
  358. %typemap(typecheck) signed char &INPUT = signed char;
  359. %typemap(typecheck) unsigned char &INPUT = unsigned char;
  360. %typemap(typecheck) unsigned long &INPUT = unsigned long;
  361. %typemap(typecheck) unsigned short &INPUT = unsigned short;
  362. %typemap(typecheck) unsigned int &INPUT = unsigned int;
  363. %typemap(typecheck) long &INPUT = long;
  364. %typemap(typecheck) short &INPUT = short;
  365. %typemap(typecheck) int &INPUT = int;
  366. %typemap(typecheck) float &INPUT = float;
  367. %typemap(typecheck) long long &INPUT = long long;
  368. %typemap(typecheck) unsigned long long &INPUT = unsigned long long;
  369. %typemap(typecheck) double *INOUT = double;
  370. %typemap(typecheck) bool *INOUT = bool;
  371. %typemap(typecheck) signed char *INOUT = signed char;
  372. %typemap(typecheck) unsigned char *INOUT = unsigned char;
  373. %typemap(typecheck) unsigned long *INOUT = unsigned long;
  374. %typemap(typecheck) unsigned short *INOUT = unsigned short;
  375. %typemap(typecheck) unsigned int *INOUT = unsigned int;
  376. %typemap(typecheck) long *INOUT = long;
  377. %typemap(typecheck) short *INOUT = short;
  378. %typemap(typecheck) int *INOUT = int;
  379. %typemap(typecheck) float *INOUT = float;
  380. %typemap(typecheck) long long *INOUT = long long;
  381. %typemap(typecheck) unsigned long long *INOUT = unsigned long long;
  382. %typemap(typecheck) double &INOUT = double;
  383. %typemap(typecheck) bool &INOUT = bool;
  384. %typemap(typecheck) signed char &INOUT = signed char;
  385. %typemap(typecheck) unsigned char &INOUT = unsigned char;
  386. %typemap(typecheck) unsigned long &INOUT = unsigned long;
  387. %typemap(typecheck) unsigned short &INOUT = unsigned short;
  388. %typemap(typecheck) unsigned int &INOUT = unsigned int;
  389. %typemap(typecheck) long &INOUT = long;
  390. %typemap(typecheck) short &INOUT = short;
  391. %typemap(typecheck) int &INOUT = int;
  392. %typemap(typecheck) float &INOUT = float;
  393. %typemap(typecheck) long long &INOUT = long long;
  394. %typemap(typecheck) unsigned long long &INOUT = unsigned long long;
  395. #endif
  396. // --------------------------------------------------------------------
  397. // Special types
  398. // --------------------------------------------------------------------
  399. %include <tclinterp.i>
  400. %include <tclresult.i>