PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Lib/tcl/typemaps.i

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