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