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 * Pointer handling
8 *
9 * These mappings provide support for input/output arguments and
10 * common uses for C/C++ pointers.  INOUT mappings allow for C/C++
11 * pointer variables in addition to input/output arguments.
12 * ----------------------------------------------------------------------------- */
13
14// INPUT typemaps.
15// These remap a C pointer to be an "INPUT" value which is passed by value
16// instead of reference.
17
18/*
19The following methods can be applied to turn a pointer into a simple
20"input" value.  That is, instead of passing a pointer to an object,
21you would use a real value instead.
22
23         int            *INPUT
24         short          *INPUT
25         long           *INPUT
26	 long long      *INPUT
27         unsigned int   *INPUT
28         unsigned short *INPUT
29         unsigned long  *INPUT
30         unsigned long long *INPUT
31         unsigned char  *INPUT
32         char           *INPUT
33         bool           *INPUT
34         float          *INPUT
35         double         *INPUT
36
37To use these, suppose you had a C function like this :
38
39        double fadd(double *a, double *b) {
40               return *a+*b;
41        }
42
43You could wrap it with SWIG as follows :
44
45        %include <typemaps.i>
46        double fadd(double *INPUT, double *INPUT);
47
48or you can use the %apply directive :
49
50        %include <typemaps.i>
51        %apply double *INPUT { double *a, double *b };
52        double fadd(double *a, double *b);
53
54*/
55
56// OUTPUT typemaps.   These typemaps are used for parameters that
57// are output only.   The output value is appended to the result as
58// a list element.
59
60/*
61The following methods can be applied to turn a pointer into an "output"
62value.  When calling a function, no input value would be given for
63a parameter, but an output value would be returned.  In the case of
64multiple output values, they are returned in the form of a Scheme list.
65
66         int            *OUTPUT
67         short          *OUTPUT
68         long           *OUTPUT
69         long long      *OUTPUT
70         unsigned int   *OUTPUT
71         unsigned short *OUTPUT
72         unsigned long  *OUTPUT
73         unsigned long long *OUTPUT
74         unsigned char  *OUTPUT
75         char           *OUTPUT
76         bool           *OUTPUT
77         float          *OUTPUT
78         double         *OUTPUT
79
80For example, suppose you were trying to wrap the modf() function in the
81C math library which splits x into integral and fractional parts (and
82returns the integer part in one of its parameters).K:
83
84        double modf(double x, double *ip);
85
86You could wrap it with SWIG as follows :
87
88        %include <typemaps.i>
89        double modf(double x, double *OUTPUT);
90
91or you can use the %apply directive :
92
93        %include <typemaps.i>
94        %apply double *OUTPUT { double *ip };
95        double modf(double x, double *ip);
96
97*/
98
99// These typemaps contributed by Robin Dunn
100//----------------------------------------------------------------------
101//
102// T_OUTPUT typemap (and helper function) to return multiple argouts as
103// a tuple instead of a list.
104//
105//----------------------------------------------------------------------
106
107// Simple types
108
109%define INOUT_TYPEMAP(type_, from_scheme, to_scheme, checker, convtype, storage_)
110
111%typemap(in) type_ *INPUT($*1_ltype temp), type_ &INPUT($*1_ltype temp)
112%{  if (!checker ($input)) {
113    swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'");
114  }
115  temp = ($*1_ltype) from_scheme ($input);
116  $1 = &temp; %}
117
118%typemap(typecheck) type_ *INPUT = type_;
119%typemap(typecheck) type_ &INPUT = type_;
120
121%typemap(in, numinputs=0) type_ *OUTPUT($*1_ltype temp), type_ &OUTPUT($*1_ltype temp)
122"  $1 = &temp;"
123
124#if "storage_" == "0"
125
126%typemap(argout) type_ *OUTPUT, type_ &OUTPUT
127%{
128  if ($1 == NULL) {
129    swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Argument #$argnum must be non-null");
130  }
131  SWIG_APPEND_VALUE(to_scheme (convtype (*$1)));
132%}
133
134#else
135
136%typemap(argout) type_ *OUTPUT, type_ &OUTPUT
137%{
138  {
139    C_word *known_space = C_alloc(storage_);
140    if ($1 == NULL) {
141      swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Variable '$1' must be non-null");
142    }
143    SWIG_APPEND_VALUE(to_scheme (&known_space, convtype (*$1)));
144  }
145%}
146
147#endif
148
149%enddef
150
151INOUT_TYPEMAP(int, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
152INOUT_TYPEMAP(enum SWIGTYPE, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
153INOUT_TYPEMAP(short, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
154INOUT_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
155INOUT_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
156INOUT_TYPEMAP(unsigned int, C_num_to_unsigned_int, C_unsigned_int_to_num, C_swig_is_number, (int), C_SIZEOF_FLONUM);
157INOUT_TYPEMAP(unsigned short, C_num_to_unsigned_int, C_fix, C_swig_is_number, (unsigned int), 0);
158INOUT_TYPEMAP(unsigned long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
159INOUT_TYPEMAP(unsigned long long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
160INOUT_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0);
161INOUT_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0);
162INOUT_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
163INOUT_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0);
164INOUT_TYPEMAP(float, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
165INOUT_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
166
167// INOUT
168// Mappings for an argument that is both an input and output
169// parameter
170
171/*
172The following methods can be applied to make a function parameter both
173an input and output value.  This combines the behavior of both the
174"INPUT" and "OUTPUT" methods described earlier.  Output values are
175returned in the form of a CHICKEN tuple.
176
177         int            *INOUT
178         short          *INOUT
179         long           *INOUT
180         long long      *INOUT
181         unsigned int   *INOUT
182         unsigned short *INOUT
183         unsigned long  *INOUT
184         unsigned long long *INOUT
185         unsigned char  *INOUT
186         char           *INOUT
187         bool           *INOUT
188         float          *INOUT
189         double         *INOUT
190
191For example, suppose you were trying to wrap the following function :
192
193        void neg(double *x) {
194             *x = -(*x);
195        }
196
197You could wrap it with SWIG as follows :
198
199        %include <typemaps.i>
200        void neg(double *INOUT);
201
202or you can use the %apply directive :
203
204        %include <typemaps.i>
205        %apply double *INOUT { double *x };
206        void neg(double *x);
207
208As well, you can wrap variables with :
209
210        %include <typemaps.i>
211        %apply double *INOUT { double *y };
212        extern double *y;
213
214Unlike C, this mapping does not directly modify the input value (since
215this makes no sense in CHICKEN).  Rather, the modified input value shows
216up as the return value of the function.  Thus, to apply this function
217to a CHICKEN variable you might do this :
218
219       x = neg(x)
220
221Note : previous versions of SWIG used the symbol 'BOTH' to mark
222input/output arguments.   This is still supported, but will be slowly
223phased out in future releases.
224
225*/
226
227%typemap(in) int *INOUT = int *INPUT;
228%typemap(in) enum SWIGTYPE *INOUT = enum SWIGTYPE *INPUT;
229%typemap(in) short *INOUT = short *INPUT;
230%typemap(in) long *INOUT = long *INPUT;
231%typemap(in) long long *INOUT = long long *INPUT;
232%typemap(in) unsigned *INOUT = unsigned *INPUT;
233%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
234%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
235%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
236%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
237%typemap(in) char *INOUT = char *INPUT;
238%typemap(in) bool *INOUT = bool *INPUT;
239%typemap(in) float *INOUT = float *INPUT;
240%typemap(in) double *INOUT = double *INPUT;
241
242%typemap(in) int &INOUT = int &INPUT;
243%typemap(in) enum SWIGTYPE &INOUT = enum SWIGTYPE &INPUT;
244%typemap(in) short &INOUT = short &INPUT;
245%typemap(in) long &INOUT = long &INPUT;
246%typemap(in) long long &INOUT = long long &INPUT;
247%typemap(in) unsigned &INOUT = unsigned &INPUT;
248%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
249%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
250%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
251%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
252%typemap(in) char &INOUT = char &INPUT;
253%typemap(in) bool &INOUT = bool &INPUT;
254%typemap(in) float &INOUT = float &INPUT;
255%typemap(in) double &INOUT = double &INPUT;
256
257%typemap(argout) int *INOUT = int *OUTPUT;
258%typemap(argout) enum SWIGTYPE *INOUT = enum SWIGTYPE *OUTPUT;
259%typemap(argout) short *INOUT = short *OUTPUT;
260%typemap(argout) long *INOUT = long *OUTPUT;
261%typemap(argout) long long *INOUT = long long *OUTPUT;
262%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
263%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
264%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
265%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
266%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
267%typemap(argout) bool *INOUT = bool *OUTPUT;
268%typemap(argout) float *INOUT = float *OUTPUT;
269%typemap(argout) double *INOUT = double *OUTPUT;
270
271%typemap(argout) int &INOUT = int &OUTPUT;
272%typemap(argout) enum SWIGTYPE &INOUT = enum SWIGTYPE &OUTPUT;
273%typemap(argout) short &INOUT = short &OUTPUT;
274%typemap(argout) long &INOUT = long &OUTPUT;
275%typemap(argout) long long &INOUT = long long &OUTPUT;
276%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
277%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
278%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
279%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
280%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
281%typemap(argout) char &INOUT = char &OUTPUT;
282%typemap(argout) bool &INOUT = bool &OUTPUT;
283%typemap(argout) float &INOUT = float &OUTPUT;
284%typemap(argout) double &INOUT = double &OUTPUT;
285
286/* Overloading information */
287
288%typemap(typecheck) double *INOUT = double;
289%typemap(typecheck) bool *INOUT = bool;
290%typemap(typecheck) char *INOUT = char;
291%typemap(typecheck) signed char *INOUT = signed char;
292%typemap(typecheck) unsigned char *INOUT = unsigned char;
293%typemap(typecheck) unsigned long *INOUT = unsigned long;
294%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
295%typemap(typecheck) unsigned short *INOUT = unsigned short;
296%typemap(typecheck) unsigned int *INOUT = unsigned int;
297%typemap(typecheck) long *INOUT = long;
298%typemap(typecheck) long long *INOUT = long long;
299%typemap(typecheck) short *INOUT = short;
300%typemap(typecheck) int *INOUT = int;
301%typemap(typecheck) enum SWIGTYPE *INOUT = enum SWIGTYPE;
302%typemap(typecheck) float *INOUT = float;
303
304%typemap(typecheck) double &INOUT = double;
305%typemap(typecheck) bool &INOUT = bool;
306%typemap(typecheck) char &INOUT = char;
307%typemap(typecheck) signed char &INOUT = signed char;
308%typemap(typecheck) unsigned char &INOUT = unsigned char;
309%typemap(typecheck) unsigned long &INOUT = unsigned long;
310%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
311%typemap(typecheck) unsigned short &INOUT = unsigned short;
312%typemap(typecheck) unsigned int &INOUT = unsigned int;
313%typemap(typecheck) long &INOUT = long;
314%typemap(typecheck) long long &INOUT = long long;
315%typemap(typecheck) short &INOUT = short;
316%typemap(typecheck) int &INOUT = int;
317%typemap(typecheck) enum SWIGTYPE &INOUT = enum SWIGTYPE;
318%typemap(typecheck) float &INOUT = float;
319