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