import source from 1.3.40
[external/swig.git] / Lib / csharp / csharp.swg
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  * csharp.swg
6  *
7  * C# typemaps
8  * ----------------------------------------------------------------------------- */
9
10 %include <csharphead.swg>
11
12 /* The ctype, imtype and cstype typemaps work together and so there should be one of each. 
13  * The ctype typemap contains the PInvoke type used in the PInvoke (C/C++) code. 
14  * The imtype typemap contains the C# type used in the intermediary class. 
15  * The cstype typemap contains the C# type used in the C# proxy classes, type wrapper classes and module class. */
16
17
18 /* Fragments */
19 %fragment("SWIG_PackData", "header") {
20 /* Pack binary data into a string */
21 SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
22   static const char hex[17] = "0123456789abcdef";
23   register const unsigned char *u = (unsigned char *) ptr;
24   register const unsigned char *eu =  u + sz;
25   for (; u != eu; ++u) {
26     register unsigned char uu = *u;
27     *(c++) = hex[(uu & 0xf0) >> 4];
28     *(c++) = hex[uu & 0xf];
29   }
30   return c;
31 }
32 }
33
34 %fragment("SWIG_UnPackData", "header") {
35 /* Unpack binary data from a string */
36 SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
37   register unsigned char *u = (unsigned char *) ptr;
38   register const unsigned char *eu = u + sz;
39   for (; u != eu; ++u) {
40     register char d = *(c++);
41     register unsigned char uu;
42     if ((d >= '0') && (d <= '9'))
43       uu = ((d - '0') << 4);
44     else if ((d >= 'a') && (d <= 'f'))
45       uu = ((d - ('a'-10)) << 4);
46     else 
47       return (char *) 0;
48     d = *(c++);
49     if ((d >= '0') && (d <= '9'))
50       uu |= (d - '0');
51     else if ((d >= 'a') && (d <= 'f'))
52       uu |= (d - ('a'-10));
53     else 
54       return (char *) 0;
55     *u = uu;
56   }
57   return c;
58 }
59 }
60
61 /* Primitive types */
62 %typemap(ctype) bool,               const bool &               "unsigned int"
63 %typemap(ctype) char,               const char &               "char"
64 %typemap(ctype) signed char,        const signed char &        "signed char"
65 %typemap(ctype) unsigned char,      const unsigned char &      "unsigned char"
66 %typemap(ctype) short,              const short &              "short"
67 %typemap(ctype) unsigned short,     const unsigned short &     "unsigned short"
68 %typemap(ctype) int,                const int &                "int"
69 %typemap(ctype) unsigned int,       const unsigned int &       "unsigned int"
70 %typemap(ctype) long,               const long &               "long"
71 %typemap(ctype) unsigned long,      const unsigned long &      "unsigned long"
72 %typemap(ctype) long long,          const long long &          "long long"
73 %typemap(ctype) unsigned long long, const unsigned long long & "unsigned long long"
74 %typemap(ctype) float,              const float &              "float"
75 %typemap(ctype) double,             const double &             "double"
76 %typemap(ctype) void                                           "void"
77
78 %typemap(imtype) bool,               const bool &               "bool"
79 %typemap(imtype) char,               const char &               "char"
80 %typemap(imtype) signed char,        const signed char &        "sbyte"
81 %typemap(imtype) unsigned char,      const unsigned char &      "byte"
82 %typemap(imtype) short,              const short &              "short"
83 %typemap(imtype) unsigned short,     const unsigned short &     "ushort"
84 %typemap(imtype) int,                const int &                "int"
85 %typemap(imtype) unsigned int,       const unsigned int &       "uint"
86 %typemap(imtype) long,               const long &               "int"
87 %typemap(imtype) unsigned long,      const unsigned long &      "uint"
88 %typemap(imtype) long long,          const long long &          "long"
89 %typemap(imtype) unsigned long long, const unsigned long long & "ulong"
90 %typemap(imtype) float,              const float &              "float"
91 %typemap(imtype) double,             const double &             "double"
92 %typemap(imtype) void                                           "void"
93
94 %typemap(cstype) bool,               const bool &               "bool"
95 %typemap(cstype) char,               const char &               "char"
96 %typemap(cstype) signed char,        const signed char &        "sbyte"
97 %typemap(cstype) unsigned char,      const unsigned char &      "byte"
98 %typemap(cstype) short,              const short &              "short"
99 %typemap(cstype) unsigned short,     const unsigned short &     "ushort"
100 %typemap(cstype) int,                const int &                "int"
101 %typemap(cstype) unsigned int,       const unsigned int &       "uint"
102 %typemap(cstype) long,               const long &               "int"
103 %typemap(cstype) unsigned long,      const unsigned long &      "uint"
104 %typemap(cstype) long long,          const long long &          "long"
105 %typemap(cstype) unsigned long long, const unsigned long long & "ulong"
106 %typemap(cstype) float,              const float &              "float"
107 %typemap(cstype) double,             const double &             "double"
108 %typemap(cstype) void                                           "void"
109
110 %typemap(ctype) char *, char *&, char[ANY], char[]   "char *"
111 %typemap(imtype) char *, char *&, char[ANY], char[]   "string"
112 %typemap(cstype) char *, char *&, char[ANY], char[]   "string"
113
114 /* Non primitive types */
115 %typemap(ctype) SWIGTYPE "void *"
116 %typemap(imtype, out="IntPtr") SWIGTYPE "HandleRef"
117 %typemap(cstype) SWIGTYPE "$&csclassname"
118
119 %typemap(ctype) SWIGTYPE [] "void *"
120 %typemap(imtype, out="IntPtr") SWIGTYPE [] "HandleRef"
121 %typemap(cstype) SWIGTYPE [] "$csclassname"
122
123 %typemap(ctype) SWIGTYPE * "void *"
124 %typemap(imtype, out="IntPtr") SWIGTYPE * "HandleRef"
125 %typemap(cstype) SWIGTYPE * "$csclassname"
126
127 %typemap(ctype) SWIGTYPE & "void *"
128 %typemap(imtype, out="IntPtr") SWIGTYPE & "HandleRef"
129 %typemap(cstype) SWIGTYPE & "$csclassname"
130
131 /* pointer to a class member */
132 %typemap(ctype) SWIGTYPE (CLASS::*) "char *"
133 %typemap(imtype) SWIGTYPE (CLASS::*) "string"
134 %typemap(cstype) SWIGTYPE (CLASS::*) "$csclassname"
135
136 /* The following are the in and out typemaps. These are the PInvoke code generating typemaps for converting from C# to C and visa versa. */
137
138 /* primitive types */
139 %typemap(in) bool
140 %{ $1 = $input ? true : false; %}
141
142 %typemap(directorout) bool
143 %{ $result = $input ? true : false; %}
144
145 %typemap(csdirectorin) bool "$iminput"
146 %typemap(csdirectorout) bool "$cscall"
147
148 %typemap(in) char, 
149              signed char, 
150              unsigned char, 
151              short, 
152              unsigned short, 
153              int, 
154              unsigned int, 
155              long, 
156              unsigned long, 
157              long long, 
158              unsigned long long, 
159              float, 
160              double
161 %{ $1 = ($1_ltype)$input; %}
162
163 %typemap(directorout) char, 
164              signed char, 
165              unsigned char, 
166              short, 
167              unsigned short, 
168              int, 
169              unsigned int, 
170              long, 
171              unsigned long, 
172              long long, 
173              unsigned long long, 
174              float, 
175              double
176 %{ $result = ($1_ltype)$input; %}
177
178 %typemap(directorin) bool               "$input = $1;"
179 %typemap(directorin) char               "$input = $1;"
180 %typemap(directorin) signed char        "$input = $1;"
181 %typemap(directorin) unsigned char      "$input = $1;"
182 %typemap(directorin) short              "$input = $1;"
183 %typemap(directorin) unsigned short     "$input = $1;"
184 %typemap(directorin) int                "$input = $1;"
185 %typemap(directorin) unsigned int       "$input = $1;"
186 %typemap(directorin) long               "$input = $1;"
187 %typemap(directorin) unsigned long      "$input = $1;"
188 %typemap(directorin) long long          "$input = $1;"
189 %typemap(directorin) unsigned long long "$input = $1;"
190 %typemap(directorin) float              "$input = $1;"
191 %typemap(directorin) double             "$input = $1;"
192
193 %typemap(csdirectorin) char, 
194                        signed char, 
195                        unsigned char, 
196                        short, 
197                        unsigned short, 
198                        int, 
199                        unsigned int, 
200                        long, 
201                        unsigned long, 
202                        long long, 
203                        unsigned long long, 
204                        float, 
205                        double
206   "$iminput"
207
208 %typemap(csdirectorout) char, 
209                         signed char, 
210                         unsigned char, 
211                         short, 
212                         unsigned short, 
213                         int, 
214                         unsigned int, 
215                         long, 
216                         unsigned long, 
217                         long long, 
218                         unsigned long long, 
219                         float, 
220                         double
221   "$cscall"
222
223 %typemap(out) bool               %{ $result = $1; %}
224 %typemap(out) char               %{ $result = $1; %}
225 %typemap(out) signed char        %{ $result = $1; %}
226 %typemap(out) unsigned char      %{ $result = $1; %}
227 %typemap(out) short              %{ $result = $1; %}
228 %typemap(out) unsigned short     %{ $result = $1; %}
229 %typemap(out) int                %{ $result = $1; %}
230 %typemap(out) unsigned int       %{ $result = $1; %}
231 %typemap(out) long               %{ $result = $1; %}
232 %typemap(out) unsigned long      %{ $result = (unsigned long)$1; %}
233 %typemap(out) long long          %{ $result = $1; %}
234 %typemap(out) unsigned long long %{ $result = $1; %}
235 %typemap(out) float              %{ $result = $1; %}
236 %typemap(out) double             %{ $result = $1; %}
237
238 /* char * - treat as String */
239 %typemap(in) char * %{ $1 = ($1_ltype)$input; %}
240 %typemap(out) char * %{ $result = SWIG_csharp_string_callback((const char *)$1); %}
241 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
242 %typemap(directorin) char * %{ $input = SWIG_csharp_string_callback((const char *)$1); %}
243 %typemap(csdirectorin) char * "$iminput"
244 %typemap(csdirectorout) char * "$cscall"
245
246 /* char *& - treat as String */
247 %typemap(in) char *& ($*1_ltype temp = 0) %{ 
248   temp = ($*1_ltype)$input;
249   $1 = &temp;
250 %}
251 %typemap(out) char *& %{ if ($1) $result = SWIG_csharp_string_callback((const char *)*$1); %}
252
253 %typemap(out, null="") void ""
254 %typemap(csdirectorin) void "$iminput"
255 %typemap(csdirectorout) void "$cscall"
256 %typemap(directorin) void ""
257
258 /* primitive types by const reference */
259 %typemap(in) const bool & ($*1_ltype temp)
260 %{ temp = $input ? true : false; 
261    $1 = &temp; %}
262
263 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
264 %{ static $*1_ltype temp;
265    temp = $input ? true : false; 
266    $result = &temp; %}
267
268 %typemap(csdirectorin) const bool & "$iminput"
269 %typemap(csdirectorout) const bool & "$cscall"
270
271 %typemap(in) const char & ($*1_ltype temp), 
272              const signed char & ($*1_ltype temp), 
273              const unsigned char & ($*1_ltype temp), 
274              const short & ($*1_ltype temp), 
275              const unsigned short & ($*1_ltype temp), 
276              const int & ($*1_ltype temp), 
277              const unsigned int & ($*1_ltype temp), 
278              const long & ($*1_ltype temp), 
279              const unsigned long & ($*1_ltype temp), 
280              const long long & ($*1_ltype temp), 
281              const unsigned long long & ($*1_ltype temp), 
282              const float & ($*1_ltype temp), 
283              const double & ($*1_ltype temp)
284 %{ temp = ($*1_ltype)$input; 
285    $1 = &temp; %}
286
287 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const char &,
288              const signed char &,
289              const unsigned char &,
290              const short &,
291              const unsigned short &,
292              const int &,
293              const unsigned int &,
294              const long &,
295              const unsigned long &,
296              const long long &,
297              const float &,
298              const double &
299 %{ static $*1_ltype temp;
300    temp = ($*1_ltype)$input; 
301    $result = &temp; %}
302
303 %typemap(directorin) const bool &           "$input = $1_name;"
304 %typemap(directorin) const char &           "$input = $1_name;"
305 %typemap(directorin) const signed char &    "$input = $1_name;"
306 %typemap(directorin) const unsigned char &  "$input = $1_name;"
307 %typemap(directorin) const short &          "$input = $1_name;"
308 %typemap(directorin) const unsigned short & "$input = $1_name;"
309 %typemap(directorin) const int &            "$input = $1_name;"
310 %typemap(directorin) const unsigned int &   "$input = $1_name;"
311 %typemap(directorin) const long &           "$input = $1_name;"
312 %typemap(directorin) const unsigned long &  "$input = $1_name;"
313 %typemap(directorin) const long long &      "$input = $1_name;"
314 %typemap(directorin) const float &          "$input = $1_name;"
315 %typemap(directorin) const double &         "$input = $1_name;"
316
317 %typemap(csdirectorin) const char & ($*1_ltype temp), 
318                        const signed char & ($*1_ltype temp), 
319                        const unsigned char & ($*1_ltype temp), 
320                        const short & ($*1_ltype temp), 
321                        const unsigned short & ($*1_ltype temp), 
322                        const int & ($*1_ltype temp), 
323                        const unsigned int & ($*1_ltype temp), 
324                        const long & ($*1_ltype temp), 
325                        const unsigned long & ($*1_ltype temp), 
326                        const long long & ($*1_ltype temp), 
327                        const float & ($*1_ltype temp), 
328                        const double & ($*1_ltype temp)
329   "$iminput"
330
331 %typemap(csdirectorout) const char & ($*1_ltype temp), 
332                         const signed char & ($*1_ltype temp), 
333                         const unsigned char & ($*1_ltype temp), 
334                         const short & ($*1_ltype temp), 
335                         const unsigned short & ($*1_ltype temp), 
336                         const int & ($*1_ltype temp), 
337                         const unsigned int & ($*1_ltype temp), 
338                         const long & ($*1_ltype temp), 
339                         const unsigned long & ($*1_ltype temp), 
340                         const long long & ($*1_ltype temp), 
341                         const float & ($*1_ltype temp), 
342                         const double & ($*1_ltype temp)
343   "$cscall"
344
345
346 %typemap(out) const bool &               %{ $result = *$1; %}
347 %typemap(out) const char &               %{ $result = *$1; %}
348 %typemap(out) const signed char &        %{ $result = *$1; %}
349 %typemap(out) const unsigned char &      %{ $result = *$1; %}
350 %typemap(out) const short &              %{ $result = *$1; %}
351 %typemap(out) const unsigned short &     %{ $result = *$1; %}
352 %typemap(out) const int &                %{ $result = *$1; %}
353 %typemap(out) const unsigned int &       %{ $result = *$1; %}
354 %typemap(out) const long &               %{ $result = *$1; %}
355 %typemap(out) const unsigned long &      %{ $result = (unsigned long)*$1; %}
356 %typemap(out) const long long &          %{ $result = *$1; %}
357 %typemap(out) const unsigned long long & %{ $result = *$1; %}
358 %typemap(out) const float &              %{ $result = *$1; %}
359 %typemap(out) const double &             %{ $result = *$1; %}
360
361 /* Default handling. Object passed by value. Convert to a pointer */
362 %typemap(in, canthrow=1) SWIGTYPE ($&1_type argp)
363 %{ argp = ($&1_ltype)$input; 
364    if (!argp) {
365      SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0);
366      return $null;
367    }
368    $1 = *argp; %}
369
370 %typemap(directorout) SWIGTYPE
371 %{ if (!$input) {
372      SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
373      return $null;
374    }
375    $result = *($&1_ltype)$input; %}
376
377 %typemap(out) SWIGTYPE 
378 #ifdef __cplusplus
379 %{ $result = new $1_ltype((const $1_ltype &)$1); %}
380 #else
381 {
382   $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
383   memmove($1ptr, &$1, sizeof($1_type));
384   $result = $1ptr;
385 }
386 #endif
387
388 %typemap(directorin) SWIGTYPE 
389 %{ $input = (void *)&$1; %}
390 %typemap(csdirectorin) SWIGTYPE "new $&csclassname($iminput, false)"
391 %typemap(csdirectorout) SWIGTYPE "$&csclassname.getCPtr($cscall).Handle"
392
393 /* Generic pointers and references */
394 %typemap(in) SWIGTYPE * %{ $1 = ($1_ltype)$input; %}
395 %typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) %{ 
396   SWIG_UnpackData($input, (void *)&$1, sizeof($1));
397 %}
398 %typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
399   if (!$1) {
400     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
401     return $null;
402   } %}
403 %typemap(out) SWIGTYPE * %{ $result = (void *)$1; %} 
404 %typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
405   char buf[128];
406   char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
407   *data = '\0';
408   $result = SWIG_csharp_string_callback(buf);
409 %}
410 %typemap(out) SWIGTYPE & %{ $result = (void *)$1; %} 
411
412 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
413 %{ $result = ($1_ltype)$input; %}
414 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
415 %{ $result = ($1_ltype)$input; %}
416
417 %typemap(directorin) SWIGTYPE *
418 %{ $input = (void *) $1; %}
419 %typemap(directorin) SWIGTYPE (CLASS::*)
420 %{ $input = (void *) $1; %}
421
422 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &
423 %{ if (!$input) {
424      SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
425      return $null;
426    }
427    $result = ($1_ltype)$input; %}
428 %typemap(directorin) SWIGTYPE &
429 %{ $input = ($1_ltype) &$1; %}
430
431 %typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($iminput == IntPtr.Zero) ? null : new $csclassname($iminput, false)"
432 %typemap(csdirectorin) SWIGTYPE & "new $csclassname($iminput, false)"
433 %typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle"
434
435 /* Default array handling */
436 %typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}
437 %typemap(out) SWIGTYPE [] %{ $result = $1; %} 
438
439 /* char arrays - treat as String */
440 %typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
441 %typemap(out) char[ANY], char[] %{ $result = SWIG_csharp_string_callback((const char *)$1); %}
442
443 %typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
444 %typemap(directorin) char[ANY], char[] %{ $input = SWIG_csharp_string_callback((const char *)$1); %}
445
446 %typemap(csdirectorin) char[ANY], char[] "$iminput"
447 %typemap(csdirectorout) char[ANY], char[] "$cscall"
448
449
450 /* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions 
451  * that cannot be overloaded in C# as more than one C++ type maps to a single C# type */
452
453 %typecheck(SWIG_TYPECHECK_BOOL)
454     bool,
455     const bool &
456     ""
457
458 %typecheck(SWIG_TYPECHECK_CHAR)
459     char, 
460     const char &
461     ""
462
463 %typecheck(SWIG_TYPECHECK_INT8)
464     signed char,
465     const signed char &
466     ""
467
468 %typecheck(SWIG_TYPECHECK_UINT8)
469     unsigned char, 
470     const unsigned char & 
471     ""
472
473 %typecheck(SWIG_TYPECHECK_INT16)
474     short, 
475     const short &
476     ""
477
478 %typecheck(SWIG_TYPECHECK_UINT16)
479     unsigned short, 
480     const unsigned short &
481     ""
482
483 %typecheck(SWIG_TYPECHECK_INT32)
484     int, 
485     long, 
486     const int &, 
487     const long &
488     ""
489
490 %typecheck(SWIG_TYPECHECK_UINT32)
491     unsigned int, 
492     unsigned long, 
493     const unsigned int &, 
494     const unsigned long &
495     ""
496
497 %typecheck(SWIG_TYPECHECK_INT64)
498     long long, 
499     const long long &
500     ""
501
502 %typecheck(SWIG_TYPECHECK_UINT64)
503     unsigned long long,
504     const unsigned long long &
505     ""
506
507 %typecheck(SWIG_TYPECHECK_FLOAT)
508     float,
509     const float &
510     ""
511
512 %typecheck(SWIG_TYPECHECK_DOUBLE)
513     double,
514     const double &
515     ""
516
517 %typecheck(SWIG_TYPECHECK_STRING)
518     char *,
519     char *&,
520     char[ANY],
521     char[]
522     ""
523
524 %typecheck(SWIG_TYPECHECK_POINTER)
525     SWIGTYPE, 
526     SWIGTYPE *, 
527     SWIGTYPE &, 
528     SWIGTYPE [],
529     SWIGTYPE (CLASS::*)
530     ""
531
532 /* Exception handling */
533
534 %typemap(throws, canthrow=1) int, 
535                  long, 
536                  short, 
537                  unsigned int, 
538                  unsigned long, 
539                  unsigned short
540 %{ char error_msg[256];
541    sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
542    SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, error_msg);
543    return $null; %}
544
545 %typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY]
546 %{ (void)$1;
547    SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
548    return $null; %}
549
550 %typemap(throws, canthrow=1) char *
551 %{ SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1);
552    return $null; %}
553
554
555 /* Typemaps for code generation in proxy classes and C# type wrapper classes */
556
557 /* The csin typemap is used for converting function parameter types from the type 
558  * used in the proxy, module or type wrapper class to the type used in the PInvoke class. */
559 %typemap(csin)   bool,               const bool &,
560                  char,               const char &,
561                  signed char,        const signed char &,
562                  unsigned char,      const unsigned char &,
563                  short,              const short &,
564                  unsigned short,     const unsigned short &,
565                  int,                const int &,
566                  unsigned int,       const unsigned int &,
567                  long,               const long &,
568                  unsigned long,      const unsigned long &,
569                  long long,          const long long &,
570                  unsigned long long, const unsigned long long &,
571                  float,              const float &,
572                  double,             const double &
573     "$csinput"
574 %typemap(csin) char *, char *&, char[ANY], char[] "$csinput"
575 %typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)"
576 %typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
577 %typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
578
579 /* The csout typemap is used for converting function return types from the return type
580  * used in the PInvoke class to the type returned by the proxy, module or type wrapper class.
581  * The $excode special variable is replaced by the excode typemap attribute code if the
582  * method can throw any exceptions from unmanaged code, otherwise replaced by nothing. */
583
584 // Macro used by the $excode special variable
585 %define SWIGEXCODE "\n    if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef
586 %define SWIGEXCODE2 "\n      if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef
587
588 %typemap(csout, excode=SWIGEXCODE) bool,               const bool &               {
589     bool ret = $imcall;$excode
590     return ret;
591   }
592 %typemap(csout, excode=SWIGEXCODE) char,               const char &               {
593     char ret = $imcall;$excode
594     return ret;
595   }
596 %typemap(csout, excode=SWIGEXCODE) signed char,        const signed char &        {
597     sbyte ret = $imcall;$excode
598     return ret;
599   }
600 %typemap(csout, excode=SWIGEXCODE) unsigned char,      const unsigned char &      {
601     byte ret = $imcall;$excode
602     return ret;
603   }
604 %typemap(csout, excode=SWIGEXCODE) short,              const short &              {
605     short ret = $imcall;$excode
606     return ret;
607   }
608 %typemap(csout, excode=SWIGEXCODE) unsigned short,     const unsigned short &     {
609     ushort ret = $imcall;$excode
610     return ret;
611   }
612 %typemap(csout, excode=SWIGEXCODE) int,                const int &                {
613     int ret = $imcall;$excode
614     return ret;
615   }
616 %typemap(csout, excode=SWIGEXCODE) unsigned int,       const unsigned int &       {
617     uint ret = $imcall;$excode
618     return ret;
619   }
620 %typemap(csout, excode=SWIGEXCODE) long,               const long &               {
621     int ret = $imcall;$excode
622     return ret;
623   }
624 %typemap(csout, excode=SWIGEXCODE) unsigned long,      const unsigned long &      {
625     uint ret = $imcall;$excode
626     return ret;
627   }
628 %typemap(csout, excode=SWIGEXCODE) long long,          const long long &          {
629     long ret = $imcall;$excode
630     return ret;
631   }
632 %typemap(csout, excode=SWIGEXCODE) unsigned long long, const unsigned long long & {
633     ulong ret = $imcall;$excode
634     return ret;
635   }
636 %typemap(csout, excode=SWIGEXCODE) float,              const float &              {
637     float ret = $imcall;$excode
638     return ret;
639   }
640 %typemap(csout, excode=SWIGEXCODE) double,             const double &             {
641     double ret = $imcall;$excode
642     return ret;
643   }
644 %typemap(csout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
645     string ret = $imcall;$excode
646     return ret;
647   }
648 %typemap(csout, excode=SWIGEXCODE) void {
649     $imcall;$excode
650   }
651 %typemap(csout, excode=SWIGEXCODE) SWIGTYPE {
652     $&csclassname ret = new $&csclassname($imcall, true);$excode
653     return ret;
654   }
655 %typemap(csout, excode=SWIGEXCODE) SWIGTYPE & {
656     $csclassname ret = new $csclassname($imcall, $owner);$excode
657     return ret;
658   }
659 %typemap(csout, excode=SWIGEXCODE) SWIGTYPE *, SWIGTYPE [] {
660     IntPtr cPtr = $imcall;
661     $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode
662     return ret;
663   }
664 %typemap(csout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) {
665     string cMemberPtr = $imcall;
666     $csclassname ret = (cMemberPtr == null) ? null : new $csclassname(cMemberPtr, $owner);$excode
667     return ret;
668   }
669
670
671 /* Properties */
672 %typemap(csvarin, excode=SWIGEXCODE2) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
673     set {
674       $imcall;$excode
675     } %}
676
677 %typemap(csvarin, excode=SWIGEXCODE2) char *, char *&, char[ANY], char[] %{
678     set {
679       $imcall;$excode
680     } %}
681
682 %typemap(csvarout, excode=SWIGEXCODE2) bool,               const bool &               %{
683     get {
684       bool ret = $imcall;$excode
685       return ret;
686     } %}
687 %typemap(csvarout, excode=SWIGEXCODE2) char,               const char &               %{
688     get {
689       char ret = $imcall;$excode
690       return ret;
691     } %}
692 %typemap(csvarout, excode=SWIGEXCODE2) signed char,        const signed char &        %{
693     get {
694       sbyte ret = $imcall;$excode
695       return ret;
696     } %}
697 %typemap(csvarout, excode=SWIGEXCODE2) unsigned char,      const unsigned char &      %{
698     get {
699       byte ret = $imcall;$excode
700       return ret;
701     } %}
702 %typemap(csvarout, excode=SWIGEXCODE2) short,              const short &              %{
703     get {
704       short ret = $imcall;$excode
705       return ret;
706     } %}
707 %typemap(csvarout, excode=SWIGEXCODE2) unsigned short,     const unsigned short &     %{
708     get {
709       ushort ret = $imcall;$excode
710       return ret;
711     } %}
712 %typemap(csvarout, excode=SWIGEXCODE2) int,                const int &                %{
713     get {
714       int ret = $imcall;$excode
715       return ret;
716     } %}
717 %typemap(csvarout, excode=SWIGEXCODE2) unsigned int,       const unsigned int &       %{
718     get {
719       uint ret = $imcall;$excode
720       return ret;
721     } %}
722 %typemap(csvarout, excode=SWIGEXCODE2) long,               const long &               %{
723     get {
724       int ret = $imcall;$excode
725       return ret;
726     } %}
727 %typemap(csvarout, excode=SWIGEXCODE2) unsigned long,      const unsigned long &      %{
728     get {
729       uint ret = $imcall;$excode
730       return ret;
731     } %}
732 %typemap(csvarout, excode=SWIGEXCODE2) long long,          const long long &          %{
733     get {
734       long ret = $imcall;$excode
735       return ret;
736     } %}
737 %typemap(csvarout, excode=SWIGEXCODE2) unsigned long long, const unsigned long long & %{
738     get {
739       ulong ret = $imcall;$excode
740       return ret;
741     } %}
742 %typemap(csvarout, excode=SWIGEXCODE2) float,              const float &              %{
743     get {
744       float ret = $imcall;$excode
745       return ret;
746     } %}
747 %typemap(csvarout, excode=SWIGEXCODE2) double,             const double &             %{
748     get {
749       double ret = $imcall;$excode
750       return ret;
751     } %}
752
753
754 %typemap(csvarout, excode=SWIGEXCODE2) char *, char *&, char[ANY], char[] %{
755     get {
756       string ret = $imcall;$excode
757       return ret;
758     } %}
759 %typemap(csvarout, excode=SWIGEXCODE2) void %{
760     get {
761       $imcall;$excode
762     } %}
763 %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE %{
764     get {
765       $&csclassname ret = new $&csclassname($imcall, true);$excode
766       return ret;
767     } %}
768 %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE & %{
769     get {
770       $csclassname ret = new $csclassname($imcall, $owner);$excode
771       return ret;
772     } %}
773 %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, SWIGTYPE [] %{
774     get {
775       IntPtr cPtr = $imcall;
776       $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode
777       return ret;
778     } %}
779
780 %typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE (CLASS::*) %{
781     get {
782       string cMemberPtr = $imcall;
783       $csclassname ret = (cMemberPtr == null) ? null : new $csclassname(cMemberPtr, $owner);$excode
784       return ret;
785     } %}
786
787 /* Pointer reference typemaps */
788 %typemap(ctype) SWIGTYPE *& "void *"
789 %typemap(imtype, out="IntPtr") SWIGTYPE *& "HandleRef"
790 %typemap(cstype) SWIGTYPE *& "$*csclassname"
791 %typemap(csin) SWIGTYPE *& "$*csclassname.getCPtr($csinput)"
792 %typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& {
793     IntPtr cPtr = $imcall;
794     $*csclassname ret = (cPtr == IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
795     return ret;
796   }
797 %typemap(in) SWIGTYPE *& ($*1_ltype temp = 0)
798 %{ temp = ($*1_ltype)$input;
799    $1 = &temp; %}
800 %typemap(out) SWIGTYPE *&
801 %{ $result = (void *)*$1; %} 
802
803 /* Array reference typemaps */
804 %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
805
806 /* Marshal C/C++ pointer to IntPtr */
807 %typemap(ctype) void *VOID_INT_PTR "void *"
808 %typemap(imtype) void *VOID_INT_PTR "IntPtr"
809 %typemap(cstype) void *VOID_INT_PTR "IntPtr"
810 %typemap(in) void *VOID_INT_PTR %{ $1 = ($1_ltype)$input; %}
811 %typemap(out) void *VOID_INT_PTR %{ $result = (void *)$1; %} 
812 %typemap(csin) void *VOID_INT_PTR "$csinput"
813 %typemap(csout, excode=SWIGEXCODE) void *VOID_INT_PTR {
814     IntPtr ret = $imcall;$excode
815     return ret;
816   }
817
818
819 /* Typemaps used for the generation of proxy and type wrapper class code */
820 %typemap(csbase)                      SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
821 %typemap(csclassmodifiers)            SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class"
822 %typemap(cscode)                      SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
823 %typemap(csimports)                   SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\nusing System.Runtime.InteropServices;\n"
824 %typemap(csinterfaces)                SWIGTYPE "IDisposable"
825 %typemap(csinterfaces)                          SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
826 %typemap(csinterfaces_derived)        SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
827
828 // Proxy classes (base classes, ie, not derived classes)
829 %typemap(csbody) SWIGTYPE %{
830   private HandleRef swigCPtr;
831   protected bool swigCMemOwn;
832
833   internal $csclassname(IntPtr cPtr, bool cMemoryOwn) {
834     swigCMemOwn = cMemoryOwn;
835     swigCPtr = new HandleRef(this, cPtr);
836   }
837
838   internal static HandleRef getCPtr($csclassname obj) {
839     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
840   }
841 %}
842
843 // Derived proxy classes
844 %typemap(csbody_derived) SWIGTYPE %{
845   private HandleRef swigCPtr;
846
847   internal $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclassnameUpcast(cPtr), cMemoryOwn) {
848     swigCPtr = new HandleRef(this, cPtr);
849   }
850
851   internal static HandleRef getCPtr($csclassname obj) {
852     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
853   }
854 %}
855
856 // Typewrapper classes
857 %typemap(csbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
858   private HandleRef swigCPtr;
859
860   internal $csclassname(IntPtr cPtr, bool futureUse) {
861     swigCPtr = new HandleRef(this, cPtr);
862   }
863
864   protected $csclassname() {
865     swigCPtr = new HandleRef(null, IntPtr.Zero);
866   }
867
868   internal static HandleRef getCPtr($csclassname obj) {
869     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
870   }
871 %}
872
873 %typemap(csbody) SWIGTYPE (CLASS::*) %{
874   private string swigCMemberPtr;
875
876   internal $csclassname(string cMemberPtr, bool futureUse) {
877     swigCMemberPtr = cMemberPtr;
878   }
879
880   protected $csclassname() {
881     swigCMemberPtr = null;
882   }
883
884   internal static string getCMemberPtr($csclassname obj) {
885     return obj.swigCMemberPtr;
886   }
887 %}
888
889 %typemap(csfinalize) SWIGTYPE %{
890   ~$csclassname() {
891     Dispose();
892   }
893 %}
894
895 %typemap(csconstruct, excode=SWIGEXCODE,directorconnect="\n    SwigDirectorConnect();") SWIGTYPE %{: this($imcall, true) {$excode$directorconnect
896   }
897 %}
898
899 %typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
900     lock(this) {
901       if (swigCPtr.Handle != IntPtr.Zero) {
902         if (swigCMemOwn) {
903           swigCMemOwn = false;
904           $imcall;
905         }
906         swigCPtr = new HandleRef(null, IntPtr.Zero);
907       }
908       GC.SuppressFinalize(this);
909     }
910   }
911
912 %typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
913     lock(this) {
914       if (swigCPtr.Handle != IntPtr.Zero) {
915         if (swigCMemOwn) {
916           swigCMemOwn = false;
917           $imcall;
918         }
919         swigCPtr = new HandleRef(null, IntPtr.Zero);
920       }
921       GC.SuppressFinalize(this);
922       base.Dispose();
923     }
924   }
925
926 %typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{
927   protected void $methodname() {
928     swigCMemOwn = false;
929     $imcall;
930   }
931 %}
932
933 /* C# specific directives */
934 #define %csconst(flag)              %feature("cs:const","flag")
935 #define %csconstvalue(value)        %feature("cs:constvalue",value)
936 #define %csenum(wrapapproach)       %feature("cs:enum","wrapapproach")
937 #define %csmethodmodifiers          %feature("cs:methodmodifiers")
938 #define %csnothrowexception         %feature("except")
939 #define %csattributes               %feature("cs:attributes")
940
941 %pragma(csharp) imclassclassmodifiers="class"
942 %pragma(csharp) moduleclassmodifiers="public class"
943
944 %pragma(csharp) moduleimports=%{
945 using System;
946 using System.Runtime.InteropServices;
947 %}
948
949 %pragma(csharp) imclassimports=%{
950 using System;
951 using System.Runtime.InteropServices;
952 %}
953
954 /* Some ANSI C typemaps */
955
956 %apply unsigned long { size_t };
957 %apply const unsigned long & { const size_t & };
958
959 /* csharp keywords */
960 %include <csharpkw.swg>
961
962 // Default enum handling
963 %include <enums.swg>
964
965 /*
966 // Alternative char * typemaps.
967 %pragma(csharp) imclasscode=%{
968   public class SWIGStringMarshal : IDisposable {
969     public readonly HandleRef swigCPtr;
970     public SWIGStringMarshal(string str) {
971       swigCPtr = new HandleRef(this, System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str));
972     }
973     public virtual void Dispose() {
974       System.Runtime.InteropServices.Marshal.FreeHGlobal(swigCPtr.Handle);
975       GC.SuppressFinalize(this);
976     }
977   }
978 %}
979
980 %typemap(imtype, out="IntPtr") char *, char[ANY], char[]   "HandleRef"
981 %typemap(out) char *, char[ANY], char[] %{ $result = $1; %}
982 %typemap(csin) char *, char[ANY], char[] "new $imclassname.SWIGStringMarshal($csinput).swigCPtr"
983 %typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] {
984     string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
985     return ret;
986   }
987 %typemap(csvarin, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
988     set {
989       $imcall;$excode
990     } %}
991 %typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
992     get {
993       string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
994       return ret;
995     } %}
996 */
997