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