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