import source from 1.3.40
[external/swig.git] / Lib / csharp / typemaps.i
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 and reference handling typemap library
8  *
9  * These mappings provide support for input/output arguments and common
10  * uses for C/C++ pointers and C++ references.
11  * ----------------------------------------------------------------------------- */
12
13 /*
14 INPUT typemaps
15 --------------
16
17 These typemaps are used for pointer/reference parameters that are input only
18 and are mapped to a C# input parameter.
19
20 The following typemaps can be applied to turn a pointer or reference into a simple
21 input value.  That is, instead of passing a pointer or reference to an object,
22 you would use a real value instead.
23
24         bool               *INPUT, bool               &INPUT
25         signed char        *INPUT, signed char        &INPUT
26         unsigned char      *INPUT, unsigned char      &INPUT
27         short              *INPUT, short              &INPUT
28         unsigned short     *INPUT, unsigned short     &INPUT
29         int                *INPUT, int                &INPUT
30         unsigned int       *INPUT, unsigned int       &INPUT
31         long               *INPUT, long               &INPUT
32         unsigned long      *INPUT, unsigned long      &INPUT
33         long long          *INPUT, long long          &INPUT
34         unsigned long long *INPUT, unsigned long long &INPUT
35         float              *INPUT, float              &INPUT
36         double             *INPUT, double             &INPUT
37          
38 To use these, suppose you had a C function like this :
39
40         double fadd(double *a, double *b) {
41                return *a+*b;
42         }
43
44 You could wrap it with SWIG as follows :
45         
46         %include <typemaps.i>
47         double fadd(double *INPUT, double *INPUT);
48
49 or 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 In C# you could then use it like this:
56         double answer = modulename.fadd(10.0, 20.0);
57
58 */
59
60 %define INPUT_TYPEMAP(TYPE, CTYPE, CSTYPE)
61 %typemap(ctype) TYPE *INPUT, TYPE &INPUT "CTYPE"
62 %typemap(imtype) TYPE *INPUT, TYPE &INPUT "CSTYPE"
63 %typemap(cstype) TYPE *INPUT, TYPE &INPUT "CSTYPE"
64 %typemap(csin) TYPE *INPUT, TYPE &INPUT "$csinput"
65 %typemap(csdirectorin) TYPE *INPUT, TYPE &INPUT "$iminput"
66 %typemap(csdirectorout) TYPE *INPUT, TYPE &INPUT "$cscall"
67
68 %typemap(in) TYPE *INPUT, TYPE &INPUT
69 %{ $1 = ($1_ltype)&$input; %}
70
71 %typemap(directorout) TYPE *INPUT, TYPE &INPUT
72 %{ $result = ($1_ltype)&$input; %}
73
74 %typemap(directorin) TYPE &INPUT
75 %{ $input = (CTYPE *)$1; %}
76
77 %typemap(directorin) TYPE *INPUT
78 %{ $input = (CTYPE *)$1; %}
79
80 %typemap(typecheck) TYPE *INPUT = TYPE;
81 %typemap(typecheck) TYPE &INPUT = TYPE;
82 %enddef
83
84 INPUT_TYPEMAP(bool,               unsigned int,         bool)
85 //INPUT_TYPEMAP(char,               char,                 char)
86 INPUT_TYPEMAP(signed char,        signed char,          sbyte)
87 INPUT_TYPEMAP(unsigned char,      unsigned char,        byte)
88 INPUT_TYPEMAP(short,              short,                short)
89 INPUT_TYPEMAP(unsigned short,     unsigned short,       ushort)
90 INPUT_TYPEMAP(int,                int,                  int)
91 INPUT_TYPEMAP(unsigned int,       unsigned int,         uint)
92 INPUT_TYPEMAP(long,               long,                 int)
93 INPUT_TYPEMAP(unsigned long,      unsigned long,        uint)
94 INPUT_TYPEMAP(long long,          long long,            long)
95 INPUT_TYPEMAP(unsigned long long, unsigned long long,   ulong)
96 INPUT_TYPEMAP(float,              float,                float)
97 INPUT_TYPEMAP(double,             double,               double)
98
99 #undef INPUT_TYPEMAP
100
101 /*
102 OUTPUT typemaps
103 ---------------
104
105 These typemaps are used for pointer/reference parameters that are output only and
106 are mapped to a C# output parameter.
107
108 The following typemaps can be applied to turn a pointer or reference into an "output"
109 value.  When calling a function, no input value would be given for
110 a parameter, but an output value would be returned. In C#, the 'out' keyword is
111 used when passing the parameter to a function that takes an output parameter.
112
113         bool               *OUTPUT, bool               &OUTPUT
114         signed char        *OUTPUT, signed char        &OUTPUT
115         unsigned char      *OUTPUT, unsigned char      &OUTPUT
116         short              *OUTPUT, short              &OUTPUT
117         unsigned short     *OUTPUT, unsigned short     &OUTPUT
118         int                *OUTPUT, int                &OUTPUT
119         unsigned int       *OUTPUT, unsigned int       &OUTPUT
120         long               *OUTPUT, long               &OUTPUT
121         unsigned long      *OUTPUT, unsigned long      &OUTPUT
122         long long          *OUTPUT, long long          &OUTPUT
123         unsigned long long *OUTPUT, unsigned long long &OUTPUT
124         float              *OUTPUT, float              &OUTPUT
125         double             *OUTPUT, double             &OUTPUT
126          
127 For example, suppose you were trying to wrap the modf() function in the
128 C math library which splits x into integral and fractional parts (and
129 returns the integer part in one of its parameters):
130
131         double modf(double x, double *ip);
132
133 You could wrap it with SWIG as follows :
134
135         %include <typemaps.i>
136         double modf(double x, double *OUTPUT);
137
138 or you can use the %apply directive :
139
140         %include <typemaps.i>
141         %apply double *OUTPUT { double *ip };
142         double modf(double x, double *ip);
143
144 The C# output of the function would be the function return value and the 
145 value returned in the second output parameter. In C# you would use it like this:
146
147     double dptr;
148     double fraction = modulename.modf(5, out dptr);
149
150 */
151
152 %define OUTPUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE)
153 %typemap(ctype) TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *"
154 %typemap(imtype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
155 %typemap(cstype) TYPE *OUTPUT, TYPE &OUTPUT "out CSTYPE"
156 %typemap(csin) TYPE *OUTPUT, TYPE &OUTPUT "out $csinput"
157 %typemap(csdirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$iminput"
158 %typemap(csdirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$cscall"
159
160
161 %typemap(in) TYPE *OUTPUT, TYPE &OUTPUT
162 %{ $1 = ($1_ltype)$input; %}
163
164 %typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT {
165 }
166
167 %typemap(directorin) TYPE &OUTPUT
168 %{ $input = &$1; %}
169
170 %typemap(directorin,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
171 {
172 }
173
174
175 %typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *OUTPUT, TYPE &OUTPUT ""
176 %enddef
177
178 OUTPUT_TYPEMAP(bool,               unsigned int,         bool,     BOOL_PTR)
179 //OUTPUT_TYPEMAP(char,               char,                 char,     CHAR_PTR)
180 OUTPUT_TYPEMAP(signed char,        signed char,          sbyte,    INT8_PTR)
181 OUTPUT_TYPEMAP(unsigned char,      unsigned char,        byte,     UINT8_PTR)
182 OUTPUT_TYPEMAP(short,              short,                short,    INT16_PTR)
183 OUTPUT_TYPEMAP(unsigned short,     unsigned short,       ushort,   UINT16_PTR)
184 OUTPUT_TYPEMAP(int,                int,                  int,      INT32_PTR)
185 OUTPUT_TYPEMAP(unsigned int,       unsigned int,         uint,     UINT32_PTR)
186 OUTPUT_TYPEMAP(long,               long,                 int,      INT32_PTR)
187 OUTPUT_TYPEMAP(unsigned long,      unsigned long,        uint,     UINT32_PTR)
188 OUTPUT_TYPEMAP(long long,          long long,            long,     INT64_PTR)
189 OUTPUT_TYPEMAP(unsigned long long, unsigned long long,   ulong,    UINT64_PTR)
190 OUTPUT_TYPEMAP(float,              float,                float,    FLOAT_PTR)
191 OUTPUT_TYPEMAP(double,             double,               double,   DOUBLE_PTR)
192
193 #undef OUTPUT_TYPEMAP
194
195 %typemap(in) bool *OUTPUT, bool &OUTPUT
196 %{ *$input = 0; 
197    $1 = ($1_ltype)$input; %}
198
199
200 /*
201 INOUT typemaps
202 --------------
203
204 These typemaps are for pointer/reference parameters that are both input and
205 output and are mapped to a C# reference parameter.
206
207 The following typemaps can be applied to turn a pointer or reference into a
208 reference parameters, that is the parameter is both an input and an output.
209 In C#, the 'ref' keyword is used for reference parameters.
210
211         bool               *INOUT, bool               &INOUT
212         signed char        *INOUT, signed char        &INOUT
213         unsigned char      *INOUT, unsigned char      &INOUT
214         short              *INOUT, short              &INOUT
215         unsigned short     *INOUT, unsigned short     &INOUT
216         int                *INOUT, int                &INOUT
217         unsigned int       *INOUT, unsigned int       &INOUT
218         long               *INOUT, long               &INOUT
219         unsigned long      *INOUT, unsigned long      &INOUT
220         long long          *INOUT, long long          &INOUT
221         unsigned long long *INOUT, unsigned long long &INOUT
222         float              *INOUT, float              &INOUT
223         double             *INOUT, double             &INOUT
224          
225 For example, suppose you were trying to wrap the following function :
226
227         void neg(double *x) {
228              *x = -(*x);
229         }
230
231 You could wrap it with SWIG as follows :
232
233         %include <typemaps.i>
234         void neg(double *INOUT);
235
236 or you can use the %apply directive :
237
238         %include <typemaps.i>
239         %apply double *INOUT { double *x };
240         void neg(double *x);
241
242 The C# output of the function would be the new value returned by the 
243 reference parameter. In C# you would use it like this:
244
245
246        double x = 5.0;
247        neg(ref x);
248
249 The implementation of the OUTPUT and INOUT typemaps is different to the scripting
250 languages in that the scripting languages will return the output value as part 
251 of the function return value.
252
253 */
254
255 %define INOUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE)
256 %typemap(ctype) TYPE *INOUT, TYPE &INOUT "CTYPE *"
257 %typemap(imtype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
258 %typemap(cstype) TYPE *INOUT, TYPE &INOUT "ref CSTYPE"
259 %typemap(csin) TYPE *INOUT, TYPE &INOUT "ref $csinput"
260 %typemap(csdirectorin) TYPE *INOUT, TYPE &INOUT "$iminput"
261 %typemap(csdirectorout) TYPE *INOUT, TYPE &INOUT "$cscall"
262
263 %typemap(in) TYPE *INOUT, TYPE &INOUT
264 %{ $1 = ($1_ltype)$input; %}
265
266 %typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT {
267 }
268
269 %typemap(directorin) TYPE &INOUT
270 %{ $input = &$1; %}
271
272 %typemap(directorin,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT
273 {
274 }
275
276 %typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *INOUT, TYPE &INOUT ""
277 %enddef
278
279 INOUT_TYPEMAP(bool,               unsigned int,         bool,     BOOL_PTR)
280 //INOUT_TYPEMAP(char,               char,                 char,     CHAR_PTR)
281 INOUT_TYPEMAP(signed char,        signed char,          sbyte,    INT8_PTR)
282 INOUT_TYPEMAP(unsigned char,      unsigned char,        byte,     UINT8_PTR)
283 INOUT_TYPEMAP(short,              short,                short,    INT16_PTR)
284 INOUT_TYPEMAP(unsigned short,     unsigned short,       ushort,   UINT16_PTR)
285 INOUT_TYPEMAP(int,                int,                  int,      INT32_PTR)
286 INOUT_TYPEMAP(unsigned int,       unsigned int,         uint,     UINT32_PTR)
287 INOUT_TYPEMAP(long,               long,                 int,      INT32_PTR)
288 INOUT_TYPEMAP(unsigned long,      unsigned long,        uint,     UINT32_PTR)
289 INOUT_TYPEMAP(long long,          long long,            long,     INT64_PTR)
290 INOUT_TYPEMAP(unsigned long long, unsigned long long,   ulong,    UINT64_PTR)
291 INOUT_TYPEMAP(float,              float,                float,    FLOAT_PTR)
292 INOUT_TYPEMAP(double,             double,               double,   DOUBLE_PTR)
293
294 #undef INOUT_TYPEMAP
295