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 * The SWIG typemap library provides a language independent mechanism for
8 * supporting output arguments, input values, and other C function
9 * calling mechanisms.  The primary use of the library is to provide a
10 * better interface to certain C function--especially those involving
11 * pointers.
12 * ----------------------------------------------------------------------------- */
13
14#if !defined(SWIG_USE_OLD_TYPEMAPS)
15%include <typemaps/typemaps.swg>
16#else
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
24/*
25The following methods can be applied to turn a pointer into a simple
26"input" value.  That is, instead of passing a pointer to an object,
27you would use a real value instead.
28
29         int            *INPUT
30         short          *INPUT
31         long           *INPUT
32         long long      *INPUT
33         unsigned int   *INPUT
34         unsigned short *INPUT
35         unsigned long  *INPUT
36         unsigned long long *INPUT
37         unsigned char  *INPUT
38         bool           *INPUT
39         float          *INPUT
40         double         *INPUT
41
42To use these, suppose you had a C function like this :
43
44        double fadd(double *a, double *b) {
45               return *a+*b;
46        }
47
48You could wrap it with SWIG as follows :
49
50        %include typemaps.i
51        double fadd(double *INPUT, double *INPUT);
52
53or you can use the %apply directive :
54
55        %include typemaps.i
56        %apply double *INPUT { double *a, double *b };
57        double fadd(double *a, double *b);
58
59*/
60
61%define INPUT_TYPEMAP(type, converter)
62%typemap(in) type *INPUT(type temp), type &INPUT(type temp) {
63  temp = (type) converter($input);
64  $1 = &temp;
65}
66%typemap(typecheck) type *INPUT = type;
67%typemap(typecheck) type &INPUT = type;
68%enddef
69
70INPUT_TYPEMAP(float, SvNV);
71INPUT_TYPEMAP(double, SvNV);
72INPUT_TYPEMAP(int, SvIV);
73INPUT_TYPEMAP(long, SvIV);
74INPUT_TYPEMAP(short, SvIV);
75INPUT_TYPEMAP(signed char, SvIV);
76INPUT_TYPEMAP(unsigned int, SvUV);
77INPUT_TYPEMAP(unsigned long, SvUV);
78INPUT_TYPEMAP(unsigned short, SvUV);
79INPUT_TYPEMAP(unsigned char, SvUV);
80
81%typemap(in) bool *INPUT(bool temp), bool &INPUT(bool temp) {
82  temp = SvIV($input) ? true : false;
83  $1 = &temp;
84}
85%typemap(typecheck) bool *INPUT = bool;
86%typemap(typecheck) bool &INPUT = bool;
87
88%typemap(in) long long *INPUT($*1_ltype temp), long long &INPUT($*1_ltype temp) {
89  temp = strtoll(SvPV_nolen($input), 0, 0);
90  $1 = &temp;
91}
92%typemap(typecheck) long long *INPUT = long long;
93%typemap(typecheck) long long &INPUT = long long;
94
95%typemap(in) unsigned long long *INPUT($*1_ltype temp), unsigned long long &INPUT($*1_ltype temp) {
96  temp = strtoull(SvPV_nolen($input), 0, 0);
97  $1 = &temp;
98}
99%typemap(typecheck) unsigned long long *INPUT = unsigned long long;
100%typemap(typecheck) unsigned long long &INPUT = unsigned long long;
101
102
103#undef INPUT_TYPEMAP
104
105// OUTPUT typemaps.   These typemaps are used for parameters that
106// are output only.   The output value is appended to the result as
107// a list element.
108
109/*
110The following methods can be applied to turn a pointer into an "output"
111value.  When calling a function, no input value would be given for
112a parameter, but an output value would be returned.  In the case of
113multiple output values, functions will return a Perl array.
114
115         int            *OUTPUT
116         short          *OUTPUT
117         long           *OUTPUT
118         long long      *OUTPUT
119         unsigned int   *OUTPUT
120         unsigned short *OUTPUT
121         unsigned long  *OUTPUT
122         unsigned long long *OUTPUT
123         unsigned char  *OUTPUT
124         bool           *OUTPUT
125         float          *OUTPUT
126         double         *OUTPUT
127
128For example, suppose you were trying to wrap the modf() function in the
129C math library which splits x into integral and fractional parts (and
130returns the integer part in one of its parameters).:
131
132        double modf(double x, double *ip);
133
134You could wrap it with SWIG as follows :
135
136        %include typemaps.i
137        double modf(double x, double *OUTPUT);
138
139or you can use the %apply directive :
140
141        %include typemaps.i
142        %apply double *OUTPUT { double *ip };
143        double modf(double x, double *ip);
144
145The Perl output of the function would be an array containing both
146output values.
147
148*/
149
150// Force the argument to be ignored.
151
152%typemap(in,numinputs=0) int            *OUTPUT(int temp),  int &OUTPUT(int temp),
153                 short          *OUTPUT(short temp), short &OUTPUT(short temp),
154                 long           *OUTPUT(long temp), long &OUTPUT(long temp),
155                 unsigned int   *OUTPUT(unsigned int temp), unsigned int &OUTPUT(unsigned int temp),
156                 unsigned short *OUTPUT(unsigned short temp), unsigned short &OUTPUT(unsigned short temp),
157                 unsigned long  *OUTPUT(unsigned long temp), unsigned long &OUTPUT(unsigned long temp),
158                 unsigned char  *OUTPUT(unsigned char temp), unsigned char &OUTPUT(unsigned char temp),
159                 signed char    *OUTPUT(signed char temp), signed char &OUTPUT(signed char temp),
160                 bool           *OUTPUT(bool temp), bool &OUTPUT(bool temp),
161                 float          *OUTPUT(float temp), float &OUTPUT(float temp),
162                 double         *OUTPUT(double temp), double &OUTPUT(double temp),
163                 long long      *OUTPUT($*1_ltype temp), long long &OUTPUT($*1_ltype temp),
164                 unsigned long long *OUTPUT($*1_ltype temp), unsigned long long &OUTPUT($*1_ltype temp)
165"$1 = &temp;";
166
167%typemap(argout)  int            *OUTPUT, int &OUTPUT,
168                  short          *OUTPUT, short &OUTPUT,
169                  long           *OUTPUT, long &OUTPUT,
170                  signed char    *OUTPUT, signed char &OUTPUT,
171                  bool           *OUTPUT, bool &OUTPUT
172{
173  if (argvi >= items) {
174    EXTEND(sp,1);
175  }
176  $result = sv_newmortal();
177  sv_setiv($result,(IV) *($1));
178  argvi++;
179}
180
181%typemap(argout)  unsigned int   *OUTPUT, unsigned int &OUTPUT,
182                  unsigned short *OUTPUT, unsigned short &OUTPUT,
183                  unsigned long  *OUTPUT, unsigned long &OUTPUT,
184                  unsigned char  *OUTPUT, unsigned char &OUTPUT
185{
186  if (argvi >= items) {
187    EXTEND(sp,1);
188  }
189  $result = sv_newmortal();
190  sv_setuv($result,(UV) *($1));
191  argvi++;
192}
193
194
195
196%typemap(argout) float    *OUTPUT, float &OUTPUT,
197                 double   *OUTPUT, double &OUTPUT
198{
199  if (argvi >= items) {
200    EXTEND(sp,1);
201  }
202  $result = sv_newmortal();
203  sv_setnv($result,(double) *($1));
204  argvi++;
205}
206
207%typemap(argout) long long *OUTPUT, long long &OUTPUT {
208    char temp[256];
209    if (argvi >= items) {
210	EXTEND(sp,1);
211    }
212    sprintf(temp,"%lld", (long long)*($1));
213    $result = sv_newmortal();
214    sv_setpv($result,temp);
215    argvi++;
216}
217
218%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT {
219    char temp[256];
220    if (argvi >= items) {
221	EXTEND(sp,1);
222    }
223    sprintf(temp,"%llu", (unsigned long long)*($1));
224    $result = sv_newmortal();
225    sv_setpv($result,temp);
226    argvi++;
227}
228
229// INOUT
230// Mappings for an argument that is both an input and output
231// parameter
232
233/*
234The following methods can be applied to make a function parameter both
235an input and output value.  This combines the behavior of both the
236"INPUT" and "OUTPUT" methods described earlier.  Output values are
237returned in the form of a Perl array.
238
239         int            *INOUT
240         short          *INOUT
241         long           *INOUT
242         long long      *INOUT
243         unsigned int   *INOUT
244         unsigned short *INOUT
245         unsigned long  *INOUT
246         unsigned long long *INOUT
247         unsigned char  *INOUT
248         bool           *INOUT
249         float          *INOUT
250         double         *INOUT
251
252For example, suppose you were trying to wrap the following function :
253
254        void neg(double *x) {
255             *x = -(*x);
256        }
257
258You could wrap it with SWIG as follows :
259
260        %include typemaps.i
261        void neg(double *INOUT);
262
263or you can use the %apply directive :
264
265        %include typemaps.i
266        %apply double *INOUT { double *x };
267        void neg(double *x);
268
269Unlike C, this mapping does not directly modify the input value.
270Rather, the modified input value shows up as the return value of the
271function.  Thus, to apply this function to a Perl variable you might
272do this :
273
274       $x = neg($x);
275
276*/
277
278%typemap(in) int *INOUT = int *INPUT;
279%typemap(in) short *INOUT = short *INPUT;
280%typemap(in) long *INOUT = long *INPUT;
281%typemap(in) unsigned *INOUT = unsigned *INPUT;
282%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
283%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
284%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
285%typemap(in) signed char *INOUT = signed char *INPUT;
286%typemap(in) bool *INOUT = bool *INPUT;
287%typemap(in) float *INOUT = float *INPUT;
288%typemap(in) double *INOUT = double *INPUT;
289%typemap(in) long long *INOUT = long long *INPUT;
290%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
291
292%typemap(in) int &INOUT = int &INPUT;
293%typemap(in) short &INOUT = short &INPUT;
294%typemap(in) long &INOUT = long &INPUT;
295%typemap(in) unsigned &INOUT = unsigned &INPUT;
296%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
297%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
298%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
299%typemap(in) signed char &INOUT = signed char &INPUT;
300%typemap(in) bool &INOUT = bool &INPUT;
301%typemap(in) float &INOUT = float &INPUT;
302%typemap(in) double &INOUT = double &INPUT;
303%typemap(in) long long &INOUT = long long &INPUT;
304%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
305
306
307%typemap(argout) int *INOUT = int *OUTPUT;
308%typemap(argout) short *INOUT = short *OUTPUT;
309%typemap(argout) long *INOUT = long *OUTPUT;
310%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
311%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
312%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
313%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
314%typemap(argout) signed char *INOUT = signed char *OUTPUT;
315%typemap(argout) bool *INOUT = bool *OUTPUT;
316%typemap(argout) float *INOUT = float *OUTPUT;
317%typemap(argout) double *INOUT = double *OUTPUT;
318%typemap(argout) long long *INOUT = long long *OUTPUT;
319%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
320
321
322%typemap(argout) int &INOUT = int &OUTPUT;
323%typemap(argout) short &INOUT = short &OUTPUT;
324%typemap(argout) long &INOUT = long &OUTPUT;
325%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
326%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
327%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
328%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
329%typemap(argout) signed char &INOUT = signed char &OUTPUT;
330%typemap(argout) bool &INOUT = bool &OUTPUT;
331%typemap(argout) float &INOUT = float &OUTPUT;
332%typemap(argout) double &INOUT = double &OUTPUT;
333%typemap(argout) long long &INOUT = long long &OUTPUT;
334%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
335
336
337/* Overloading information */
338
339%typemap(typecheck) double *INOUT = double;
340%typemap(typecheck) bool *INOUT = bool;
341%typemap(typecheck) signed char *INOUT = signed char;
342%typemap(typecheck) unsigned char *INOUT = unsigned char;
343%typemap(typecheck) unsigned long *INOUT = unsigned long;
344%typemap(typecheck) unsigned short *INOUT = unsigned short;
345%typemap(typecheck) unsigned int *INOUT = unsigned int;
346%typemap(typecheck) long *INOUT = long;
347%typemap(typecheck) short *INOUT = short;
348%typemap(typecheck) int *INOUT = int;
349%typemap(typecheck) float *INOUT = float;
350%typemap(typecheck) long long *INOUT = long long;
351%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
352
353%typemap(typecheck) double &INOUT = double;
354%typemap(typecheck) bool &INOUT = bool;
355%typemap(typecheck) signed char &INOUT = signed char;
356%typemap(typecheck) unsigned char &INOUT = unsigned char;
357%typemap(typecheck) unsigned long &INOUT = unsigned long;
358%typemap(typecheck) unsigned short &INOUT = unsigned short;
359%typemap(typecheck) unsigned int &INOUT = unsigned int;
360%typemap(typecheck) long &INOUT = long;
361%typemap(typecheck) short &INOUT = short;
362%typemap(typecheck) int &INOUT = int;
363%typemap(typecheck) float &INOUT = float;
364%typemap(typecheck) long long &INOUT = long long;
365%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
366
367#endif
368
369// --------------------------------------------------------------------
370// Special types
371// --------------------------------------------------------------------
372
373
374%include <reference.i>
375