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.
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 * ----------------------------------------------------------------------------- */
15 // These remap a C pointer to be an "INPUT" value which is passed by value
16 // instead of reference.
19 The 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,
21 you would use a real value instead.
30 unsigned long long *INPUT
37 To use these, suppose you had a C function like this :
39 double fadd(double *a, double *b) {
43 You could wrap it with SWIG as follows :
46 double fadd(double *INPUT, double *INPUT);
48 or you can use the %apply directive :
51 %apply double *INPUT { double *a, double *b };
52 double fadd(double *a, double *b);
56 // OUTPUT typemaps. These typemaps are used for parameters that
57 // are output only. The output value is appended to the result as
61 The following methods can be applied to turn a pointer into an "output"
62 value. When calling a function, no input value would be given for
63 a parameter, but an output value would be returned. In the case of
64 multiple output values, they are returned in the form of a Scheme list.
71 unsigned short *OUTPUT
73 unsigned long long *OUTPUT
80 For example, suppose you were trying to wrap the modf() function in the
81 C math library which splits x into integral and fractional parts (and
82 returns the integer part in one of its parameters).K:
84 double modf(double x, double *ip);
86 You could wrap it with SWIG as follows :
89 double modf(double x, double *OUTPUT);
91 or you can use the %apply directive :
94 %apply double *OUTPUT { double *ip };
95 double modf(double x, double *ip);
99 // These typemaps contributed by Robin Dunn
100 //----------------------------------------------------------------------
102 // T_OUTPUT typemap (and helper function) to return multiple argouts as
103 // a tuple instead of a list.
105 //----------------------------------------------------------------------
109 %define INOUT_TYPEMAP(type_, from_scheme, to_scheme, checker, convtype, storage_)
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_'");
115 temp = ($*1_ltype) from_scheme ($input);
118 %typemap(typecheck) type_ *INPUT = type_;
119 %typemap(typecheck) type_ &INPUT = type_;
121 %typemap(in, numinputs=0) type_ *OUTPUT($*1_ltype temp), type_ &OUTPUT($*1_ltype temp)
124 #if "storage_" == "0"
126 %typemap(argout) type_ *OUTPUT, type_ &OUTPUT
129 swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Argument #$argnum must be non-null");
131 SWIG_APPEND_VALUE(to_scheme (convtype (*$1)));
136 %typemap(argout) type_ *OUTPUT, type_ &OUTPUT
139 C_word *known_space = C_alloc(storage_);
141 swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Variable '$1' must be non-null");
143 SWIG_APPEND_VALUE(to_scheme (&known_space, convtype (*$1)));
151 INOUT_TYPEMAP(int, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
152 INOUT_TYPEMAP(enum SWIGTYPE, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
153 INOUT_TYPEMAP(short, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
154 INOUT_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
155 INOUT_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
156 INOUT_TYPEMAP(unsigned int, C_num_to_unsigned_int, C_unsigned_int_to_num, C_swig_is_number, (int), C_SIZEOF_FLONUM);
157 INOUT_TYPEMAP(unsigned short, C_num_to_unsigned_int, C_fix, C_swig_is_number, (unsigned int), 0);
158 INOUT_TYPEMAP(unsigned long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
159 INOUT_TYPEMAP(unsigned long long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
160 INOUT_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0);
161 INOUT_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0);
162 INOUT_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
163 INOUT_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0);
164 INOUT_TYPEMAP(float, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
165 INOUT_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
168 // Mappings for an argument that is both an input and output
172 The following methods can be applied to make a function parameter both
173 an input and output value. This combines the behavior of both the
174 "INPUT" and "OUTPUT" methods described earlier. Output values are
175 returned in the form of a CHICKEN tuple.
182 unsigned short *INOUT
184 unsigned long long *INOUT
191 For example, suppose you were trying to wrap the following function :
193 void neg(double *x) {
197 You could wrap it with SWIG as follows :
199 %include <typemaps.i>
200 void neg(double *INOUT);
202 or you can use the %apply directive :
204 %include <typemaps.i>
205 %apply double *INOUT { double *x };
208 As well, you can wrap variables with :
210 %include <typemaps.i>
211 %apply double *INOUT { double *y };
214 Unlike C, this mapping does not directly modify the input value (since
215 this makes no sense in CHICKEN). Rather, the modified input value shows
216 up as the return value of the function. Thus, to apply this function
217 to a CHICKEN variable you might do this :
221 Note : previous versions of SWIG used the symbol 'BOTH' to mark
222 input/output arguments. This is still supported, but will be slowly
223 phased out in future releases.
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;
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;
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;
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;
286 /* Overloading information */
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;
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;