PageRenderTime 52ms CodeModel.GetById 20ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Lib/csharp/csharp.swg

#
Unknown | 1013 lines | 890 code | 123 blank | 0 comment | 0 complexity | 76b2c50125d1739afa7faacd173595a5 MD5 | raw file
   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 */
  18SWIGINTERN 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 */
  33SWIGINTERN 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 float &,
 295             const double &
 296%{ static $*1_ltype temp;
 297   temp = ($*1_ltype)$input; 
 298   $result = &temp; %}
 299
 300%typemap(directorin) const bool &           "$input = $1;"
 301%typemap(directorin) const char &           "$input = $1;"
 302%typemap(directorin) const signed char &    "$input = $1;"
 303%typemap(directorin) const unsigned char &  "$input = $1;"
 304%typemap(directorin) const short &          "$input = $1;"
 305%typemap(directorin) const unsigned short & "$input = $1;"
 306%typemap(directorin) const int &            "$input = $1;"
 307%typemap(directorin) const unsigned int &   "$input = $1;"
 308%typemap(directorin) const long &           "$input = $1;"
 309%typemap(directorin) const unsigned long &  "$input = $1;"
 310%typemap(directorin) const long long &      "$input = $1;"
 311%typemap(directorin) const float &          "$input = $1;"
 312%typemap(directorin) const double &         "$input = $1;"
 313
 314%typemap(csdirectorin) const char & ($*1_ltype temp), 
 315                       const signed char & ($*1_ltype temp), 
 316                       const unsigned char & ($*1_ltype temp), 
 317                       const short & ($*1_ltype temp), 
 318                       const unsigned short & ($*1_ltype temp), 
 319                       const int & ($*1_ltype temp), 
 320                       const unsigned int & ($*1_ltype temp), 
 321                       const long & ($*1_ltype temp), 
 322                       const unsigned long & ($*1_ltype temp), 
 323                       const long long & ($*1_ltype temp), 
 324                       const float & ($*1_ltype temp), 
 325                       const double & ($*1_ltype temp)
 326  "$iminput"
 327
 328%typemap(csdirectorout) const char & ($*1_ltype temp), 
 329                        const signed char & ($*1_ltype temp), 
 330                        const unsigned char & ($*1_ltype temp), 
 331                        const short & ($*1_ltype temp), 
 332                        const unsigned short & ($*1_ltype temp), 
 333                        const int & ($*1_ltype temp), 
 334                        const unsigned int & ($*1_ltype temp), 
 335                        const long & ($*1_ltype temp), 
 336                        const unsigned long & ($*1_ltype temp), 
 337                        const long long & ($*1_ltype temp), 
 338                        const float & ($*1_ltype temp), 
 339                        const double & ($*1_ltype temp)
 340  "$cscall"
 341
 342
 343%typemap(out) const bool &               %{ $result = *$1; %}
 344%typemap(out) const char &               %{ $result = *$1; %}
 345%typemap(out) const signed char &        %{ $result = *$1; %}
 346%typemap(out) const unsigned char &      %{ $result = *$1; %}
 347%typemap(out) const short &              %{ $result = *$1; %}
 348%typemap(out) const unsigned short &     %{ $result = *$1; %}
 349%typemap(out) const int &                %{ $result = *$1; %}
 350%typemap(out) const unsigned int &       %{ $result = *$1; %}
 351%typemap(out) const long &               %{ $result = *$1; %}
 352%typemap(out) const unsigned long &      %{ $result = (unsigned long)*$1; %}
 353%typemap(out) const long long &          %{ $result = *$1; %}
 354%typemap(out) const unsigned long long & %{ $result = *$1; %}
 355%typemap(out) const float &              %{ $result = *$1; %}
 356%typemap(out) const double &             %{ $result = *$1; %}
 357
 358/* Default handling. Object passed by value. Convert to a pointer */
 359%typemap(in, canthrow=1) SWIGTYPE ($&1_type argp)
 360%{ argp = ($&1_ltype)$input; 
 361   if (!argp) {
 362     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0);
 363     return $null;
 364   }
 365   $1 = *argp; %}
 366
 367%typemap(directorout) SWIGTYPE
 368%{ if (!$input) {
 369     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
 370     return $null;
 371   }
 372   $result = *($&1_ltype)$input; %}
 373
 374%typemap(out) SWIGTYPE 
 375#ifdef __cplusplus
 376%{ $result = new $1_ltype((const $1_ltype &)$1); %}
 377#else
 378{
 379  $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
 380  memmove($1ptr, &$1, sizeof($1_type));
 381  $result = $1ptr;
 382}
 383#endif
 384
 385%typemap(directorin) SWIGTYPE 
 386%{ $input = (void *)&$1; %}
 387%typemap(csdirectorin) SWIGTYPE "new $&csclassname($iminput, false)"
 388%typemap(csdirectorout) SWIGTYPE "$&csclassname.getCPtr($cscall).Handle"
 389
 390/* Generic pointers and references */
 391%typemap(in) SWIGTYPE * %{ $1 = ($1_ltype)$input; %}
 392%typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) %{ 
 393  SWIG_UnpackData($input, (void *)&$1, sizeof($1));
 394%}
 395%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
 396  if (!$1) {
 397    SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
 398    return $null;
 399  } %}
 400%typemap(out) SWIGTYPE * %{ $result = (void *)$1; %} 
 401%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
 402  char buf[128];
 403  char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
 404  *data = '\0';
 405  $result = SWIG_csharp_string_callback(buf);
 406%}
 407%typemap(out) SWIGTYPE & %{ $result = (void *)$1; %} 
 408
 409%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
 410%{ $result = ($1_ltype)$input; %}
 411%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
 412%{ $result = ($1_ltype)$input; %}
 413
 414%typemap(directorin) SWIGTYPE *
 415%{ $input = (void *) $1; %}
 416%typemap(directorin) SWIGTYPE (CLASS::*)
 417%{ $input = (void *) $1; %}
 418
 419%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &
 420%{ if (!$input) {
 421     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Unexpected null return for type $1_type", 0);
 422     return $null;
 423   }
 424   $result = ($1_ltype)$input; %}
 425%typemap(directorin) SWIGTYPE &
 426%{ $input = ($1_ltype) &$1; %}
 427
 428%typemap(csdirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($iminput == IntPtr.Zero) ? null : new $csclassname($iminput, false)"
 429%typemap(csdirectorin) SWIGTYPE & "new $csclassname($iminput, false)"
 430%typemap(csdirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$csclassname.getCPtr($cscall).Handle"
 431
 432/* Default array handling */
 433%typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}
 434%typemap(out) SWIGTYPE [] %{ $result = $1; %} 
 435
 436/* char arrays - treat as String */
 437%typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
 438%typemap(out) char[ANY], char[] %{ $result = SWIG_csharp_string_callback((const char *)$1); %}
 439
 440%typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
 441%typemap(directorin) char[ANY], char[] %{ $input = SWIG_csharp_string_callback((const char *)$1); %}
 442
 443%typemap(csdirectorin) char[ANY], char[] "$iminput"
 444%typemap(csdirectorout) char[ANY], char[] "$cscall"
 445
 446
 447/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions 
 448 * that cannot be overloaded in C# as more than one C++ type maps to a single C# type */
 449
 450%typecheck(SWIG_TYPECHECK_BOOL)
 451    bool,
 452    const bool &
 453    ""
 454
 455%typecheck(SWIG_TYPECHECK_CHAR)
 456    char, 
 457    const char &
 458    ""
 459
 460%typecheck(SWIG_TYPECHECK_INT8)
 461    signed char,
 462    const signed char &
 463    ""
 464
 465%typecheck(SWIG_TYPECHECK_UINT8)
 466    unsigned char, 
 467    const unsigned char & 
 468    ""
 469
 470%typecheck(SWIG_TYPECHECK_INT16)
 471    short, 
 472    const short &
 473    ""
 474
 475%typecheck(SWIG_TYPECHECK_UINT16)
 476    unsigned short, 
 477    const unsigned short &
 478    ""
 479
 480%typecheck(SWIG_TYPECHECK_INT32)
 481    int, 
 482    long, 
 483    const int &, 
 484    const long &
 485    ""
 486
 487%typecheck(SWIG_TYPECHECK_UINT32)
 488    unsigned int, 
 489    unsigned long, 
 490    const unsigned int &, 
 491    const unsigned long &
 492    ""
 493
 494%typecheck(SWIG_TYPECHECK_INT64)
 495    long long, 
 496    const long long &
 497    ""
 498
 499%typecheck(SWIG_TYPECHECK_UINT64)
 500    unsigned long long,
 501    const unsigned long long &
 502    ""
 503
 504%typecheck(SWIG_TYPECHECK_FLOAT)
 505    float,
 506    const float &
 507    ""
 508
 509%typecheck(SWIG_TYPECHECK_DOUBLE)
 510    double,
 511    const double &
 512    ""
 513
 514%typecheck(SWIG_TYPECHECK_STRING)
 515    char *,
 516    char *&,
 517    char[ANY],
 518    char[]
 519    ""
 520
 521%typecheck(SWIG_TYPECHECK_POINTER)
 522    SWIGTYPE, 
 523    SWIGTYPE *, 
 524    SWIGTYPE &, 
 525    SWIGTYPE *const&, 
 526    SWIGTYPE [],
 527    SWIGTYPE (CLASS::*)
 528    ""
 529
 530/* Exception handling */
 531
 532%typemap(throws, canthrow=1) int, 
 533                 long, 
 534                 short, 
 535                 unsigned int, 
 536                 unsigned long, 
 537                 unsigned short
 538%{ char error_msg[256];
 539   sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
 540   SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, error_msg);
 541   return $null; %}
 542
 543%typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY]
 544%{ (void)$1;
 545   SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
 546   return $null; %}
 547
 548%typemap(throws, canthrow=1) char *
 549%{ SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1);
 550   return $null; %}
 551
 552
 553/* Typemaps for code generation in proxy classes and C# type wrapper classes */
 554
 555/* The csin typemap is used for converting function parameter types from the type 
 556 * used in the proxy, module or type wrapper class to the type used in the PInvoke class. */
 557%typemap(csin)   bool,               const bool &,
 558                 char,               const char &,
 559                 signed char,        const signed char &,
 560                 unsigned char,      const unsigned char &,
 561                 short,              const short &,
 562                 unsigned short,     const unsigned short &,
 563                 int,                const int &,
 564                 unsigned int,       const unsigned int &,
 565                 long,               const long &,
 566                 unsigned long,      const unsigned long &,
 567                 long long,          const long long &,
 568                 unsigned long long, const unsigned long long &,
 569                 float,              const float &,
 570                 double,             const double &
 571    "$csinput"
 572%typemap(csin) char *, char *&, char[ANY], char[] "$csinput"
 573%typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)"
 574%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
 575%typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
 576
 577/* The csout typemap is used for converting function return types from the return type
 578 * used in the PInvoke class to the type returned by the proxy, module or type wrapper class.
 579 * The $excode special variable is replaced by the excode typemap attribute code if the
 580 * method can throw any exceptions from unmanaged code, otherwise replaced by nothing. */
 581
 582// Macro used by the $excode special variable
 583%define SWIGEXCODE "\n    if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef
 584%define SWIGEXCODE2 "\n      if ($imclassname.SWIGPendingException.Pending) throw $imclassname.SWIGPendingException.Retrieve();" %enddef
 585
 586%typemap(csout, excode=SWIGEXCODE) bool,               const bool &               {
 587    bool ret = $imcall;$excode
 588    return ret;
 589  }
 590%typemap(csout, excode=SWIGEXCODE) char,               const char &               {
 591    char ret = $imcall;$excode
 592    return ret;
 593  }
 594%typemap(csout, excode=SWIGEXCODE) signed char,        const signed char &        {
 595    sbyte ret = $imcall;$excode
 596    return ret;
 597  }
 598%typemap(csout, excode=SWIGEXCODE) unsigned char,      const unsigned char &      {
 599    byte ret = $imcall;$excode
 600    return ret;
 601  }
 602%typemap(csout, excode=SWIGEXCODE) short,              const short &              {
 603    short ret = $imcall;$excode
 604    return ret;
 605  }
 606%typemap(csout, excode=SWIGEXCODE) unsigned short,     const unsigned short &     {
 607    ushort ret = $imcall;$excode
 608    return ret;
 609  }
 610%typemap(csout, excode=SWIGEXCODE) int,                const int &                {
 611    int ret = $imcall;$excode
 612    return ret;
 613  }
 614%typemap(csout, excode=SWIGEXCODE) unsigned int,       const unsigned int &       {
 615    uint ret = $imcall;$excode
 616    return ret;
 617  }
 618%typemap(csout, excode=SWIGEXCODE) long,               const long &               {
 619    int ret = $imcall;$excode
 620    return ret;
 621  }
 622%typemap(csout, excode=SWIGEXCODE) unsigned long,      const unsigned long &      {
 623    uint ret = $imcall;$excode
 624    return ret;
 625  }
 626%typemap(csout, excode=SWIGEXCODE) long long,          const long long &          {
 627    long ret = $imcall;$excode
 628    return ret;
 629  }
 630%typemap(csout, excode=SWIGEXCODE) unsigned long long, const unsigned long long & {
 631    ulong ret = $imcall;$excode
 632    return ret;
 633  }
 634%typemap(csout, excode=SWIGEXCODE) float,              const float &              {
 635    float ret = $imcall;$excode
 636    return ret;
 637  }
 638%typemap(csout, excode=SWIGEXCODE) double,             const double &             {
 639    double ret = $imcall;$excode
 640    return ret;
 641  }
 642%typemap(csout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
 643    string ret = $imcall;$excode
 644    return ret;
 645  }
 646%typemap(csout, excode=SWIGEXCODE) void {
 647    $imcall;$excode
 648  }
 649%typemap(csout, excode=SWIGEXCODE) SWIGTYPE {
 650    $&csclassname ret = new $&csclassname($imcall, true);$excode
 651    return ret;
 652  }
 653%typemap(csout, excode=SWIGEXCODE) SWIGTYPE & {
 654    $csclassname ret = new $csclassname($imcall, $owner);$excode
 655    return ret;
 656  }
 657%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *, SWIGTYPE [] {
 658    IntPtr cPtr = $imcall;
 659    $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode
 660    return ret;
 661  }
 662%typemap(csout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) {
 663    string cMemberPtr = $imcall;
 664    $csclassname ret = (cMemberPtr == null) ? null : new $csclassname(cMemberPtr, $owner);$excode
 665    return ret;
 666  }
 667
 668
 669/* Properties */
 670%typemap(csvarin, excode=SWIGEXCODE2) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{
 671    set {
 672      $imcall;$excode
 673    } %}
 674
 675%typemap(csvarin, excode=SWIGEXCODE2) char *, char *&, char[ANY], char[] %{
 676    set {
 677      $imcall;$excode
 678    } %}
 679
 680%typemap(csvarout, excode=SWIGEXCODE2) bool,               const bool &               %{
 681    get {
 682      bool ret = $imcall;$excode
 683      return ret;
 684    } %}
 685%typemap(csvarout, excode=SWIGEXCODE2) char,               const char &               %{
 686    get {
 687      char ret = $imcall;$excode
 688      return ret;
 689    } %}
 690%typemap(csvarout, excode=SWIGEXCODE2) signed char,        const signed char &        %{
 691    get {
 692      sbyte ret = $imcall;$excode
 693      return ret;
 694    } %}
 695%typemap(csvarout, excode=SWIGEXCODE2) unsigned char,      const unsigned char &      %{
 696    get {
 697      byte ret = $imcall;$excode
 698      return ret;
 699    } %}
 700%typemap(csvarout, excode=SWIGEXCODE2) short,              const short &              %{
 701    get {
 702      short ret = $imcall;$excode
 703      return ret;
 704    } %}
 705%typemap(csvarout, excode=SWIGEXCODE2) unsigned short,     const unsigned short &     %{
 706    get {
 707      ushort ret = $imcall;$excode
 708      return ret;
 709    } %}
 710%typemap(csvarout, excode=SWIGEXCODE2) int,                const int &                %{
 711    get {
 712      int ret = $imcall;$excode
 713      return ret;
 714    } %}
 715%typemap(csvarout, excode=SWIGEXCODE2) unsigned int,       const unsigned int &       %{
 716    get {
 717      uint ret = $imcall;$excode
 718      return ret;
 719    } %}
 720%typemap(csvarout, excode=SWIGEXCODE2) long,               const long &               %{
 721    get {
 722      int ret = $imcall;$excode
 723      return ret;
 724    } %}
 725%typemap(csvarout, excode=SWIGEXCODE2) unsigned long,      const unsigned long &      %{
 726    get {
 727      uint ret = $imcall;$excode
 728      return ret;
 729    } %}
 730%typemap(csvarout, excode=SWIGEXCODE2) long long,          const long long &          %{
 731    get {
 732      long ret = $imcall;$excode
 733      return ret;
 734    } %}
 735%typemap(csvarout, excode=SWIGEXCODE2) unsigned long long, const unsigned long long & %{
 736    get {
 737      ulong ret = $imcall;$excode
 738      return ret;
 739    } %}
 740%typemap(csvarout, excode=SWIGEXCODE2) float,              const float &              %{
 741    get {
 742      float ret = $imcall;$excode
 743      return ret;
 744    } %}
 745%typemap(csvarout, excode=SWIGEXCODE2) double,             const double &             %{
 746    get {
 747      double ret = $imcall;$excode
 748      return ret;
 749    } %}
 750
 751
 752%typemap(csvarout, excode=SWIGEXCODE2) char *, char *&, char[ANY], char[] %{
 753    get {
 754      string ret = $imcall;$excode
 755      return ret;
 756    } %}
 757%typemap(csvarout, excode=SWIGEXCODE2) void %{
 758    get {
 759      $imcall;$excode
 760    } %}
 761%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE %{
 762    get {
 763      $&csclassname ret = new $&csclassname($imcall, true);$excode
 764      return ret;
 765    } %}
 766%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE & %{
 767    get {
 768      $csclassname ret = new $csclassname($imcall, $owner);$excode
 769      return ret;
 770    } %}
 771%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE *, SWIGTYPE [] %{
 772    get {
 773      IntPtr cPtr = $imcall;
 774      $csclassname ret = (cPtr == IntPtr.Zero) ? null : new $csclassname(cPtr, $owner);$excode
 775      return ret;
 776    } %}
 777
 778%typemap(csvarout, excode=SWIGEXCODE2) SWIGTYPE (CLASS::*) %{
 779    get {
 780      string cMemberPtr = $imcall;
 781      $csclassname ret = (cMemberPtr == null) ? null : new $csclassname(cMemberPtr, $owner);$excode
 782      return ret;
 783    } %}
 784
 785/* Pointer reference typemaps */
 786%typemap(ctype) SWIGTYPE *const& "void *"
 787%typemap(imtype, out="IntPtr") SWIGTYPE *const& "HandleRef"
 788%typemap(cstype) SWIGTYPE *const& "$*csclassname"
 789%typemap(csin) SWIGTYPE *const& "$*csclassname.getCPtr($csinput)"
 790%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *const& {
 791    IntPtr cPtr = $imcall;
 792    $*csclassname ret = (cPtr == IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
 793    return ret;
 794  }
 795%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
 796%{ temp = ($*1_ltype)$input;
 797   $1 = ($1_ltype)&temp; %}
 798%typemap(out) SWIGTYPE *const&
 799%{ $result = (void *)*$1; %} 
 800
 801/* Marshal C/C++ pointer to IntPtr */
 802%typemap(ctype) void *VOID_INT_PTR "void *"
 803%typemap(imtype) void *VOID_INT_PTR "IntPtr"
 804%typemap(cstype) void *VOID_INT_PTR "IntPtr"
 805%typemap(in) void *VOID_INT_PTR %{ $1 = ($1_ltype)$input; %}
 806%typemap(out) void *VOID_INT_PTR %{ $result = (void *)$1; %} 
 807%typemap(csin) void *VOID_INT_PTR "$csinput"
 808%typemap(csout, excode=SWIGEXCODE) void *VOID_INT_PTR {
 809    IntPtr ret = $imcall;$excode
 810    return ret;
 811  }
 812
 813
 814/* Typemaps used for the generation of proxy and type wrapper class code */
 815%typemap(csbase)                      SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
 816%typemap(csclassmodifiers)            SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class"
 817%typemap(cscode)                      SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
 818%typemap(csimports)                   SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "\nusing System;\nusing System.Runtime.InteropServices;\n"
 819%typemap(csinterfaces)                SWIGTYPE "IDisposable"
 820%typemap(csinterfaces)                          SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
 821%typemap(csinterfaces_derived)        SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
 822
 823
 824// csbody typemaps... these are in macros so that the visibility of the methods can be easily changed by users.
 825
 826%define SWIG_CSBODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
 827// Proxy classes (base classes, ie, not derived classes)
 828%typemap(csbody) TYPE %{
 829  private HandleRef swigCPtr;
 830  protected bool swigCMemOwn;
 831
 832  PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) {
 833    swigCMemOwn = cMemoryOwn;
 834    swigCPtr = new HandleRef(this, cPtr);
 835  }
 836
 837  CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
 838    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 839  }
 840%}
 841
 842// Derived proxy classes
 843%typemap(csbody_derived) TYPE %{
 844  private HandleRef swigCPtr;
 845
 846  PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool cMemoryOwn) : base($imclassname.$csclazznameSWIGUpcast(cPtr), cMemoryOwn) {
 847    swigCPtr = new HandleRef(this, cPtr);
 848  }
 849
 850  CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
 851    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 852  }
 853%}
 854%enddef
 855
 856%define SWIG_CSBODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
 857// Typewrapper classes
 858%typemap(csbody) TYPE *, TYPE &, TYPE [] %{
 859  private HandleRef swigCPtr;
 860
 861  PTRCTOR_VISIBILITY $csclassname(IntPtr cPtr, bool futureUse) {
 862    swigCPtr = new HandleRef(this, cPtr);
 863  }
 864
 865  DEFAULTCTOR_VISIBILITY $csclassname() {
 866    swigCPtr = new HandleRef(null, IntPtr.Zero);
 867  }
 868
 869  CPTR_VISIBILITY static HandleRef getCPtr($csclassname obj) {
 870    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 871  }
 872%}
 873
 874%typemap(csbody) TYPE (CLASS::*) %{
 875  private string swigCMemberPtr;
 876
 877  PTRCTOR_VISIBILITY $csclassname(string cMemberPtr, bool futureUse) {
 878    swigCMemberPtr = cMemberPtr;
 879  }
 880
 881  DEFAULTCTOR_VISIBILITY $csclassname() {
 882    swigCMemberPtr = null;
 883  }
 884
 885  CPTR_VISIBILITY static string getCMemberPtr($csclassname obj) {
 886    return obj.swigCMemberPtr;
 887  }
 888%}
 889%enddef
 890
 891/* Set the default csbody typemaps to use internal visibility.
 892   Use the macros to change to public if using multiple modules. */
 893SWIG_CSBODY_PROXY(internal, internal, SWIGTYPE)
 894SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
 895
 896%typemap(csfinalize) SWIGTYPE %{
 897  ~$csclassname() {
 898    Dispose();
 899  }
 900%}
 901
 902%typemap(csconstruct, excode=SWIGEXCODE,directorconnect="\n    SwigDirectorConnect();") SWIGTYPE %{: this($imcall, true) {$excode$directorconnect
 903  }
 904%}
 905
 906%typemap(csdestruct, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
 907    lock(this) {
 908      if (swigCPtr.Handle != IntPtr.Zero) {
 909        if (swigCMemOwn) {
 910          swigCMemOwn = false;
 911          $imcall;
 912        }
 913        swigCPtr = new HandleRef(null, IntPtr.Zero);
 914      }
 915      GC.SuppressFinalize(this);
 916    }
 917  }
 918
 919%typemap(csdestruct_derived, methodname="Dispose", methodmodifiers="public") SWIGTYPE {
 920    lock(this) {
 921      if (swigCPtr.Handle != IntPtr.Zero) {
 922        if (swigCMemOwn) {
 923          swigCMemOwn = false;
 924          $imcall;
 925        }
 926        swigCPtr = new HandleRef(null, IntPtr.Zero);
 927      }
 928      GC.SuppressFinalize(this);
 929      base.Dispose();
 930    }
 931  }
 932
 933%typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{
 934  protected void $methodname() {
 935    swigCMemOwn = false;
 936    $imcall;
 937  }
 938%}
 939
 940/* C# specific directives */
 941#define %csconst(flag)              %feature("cs:const","flag")
 942#define %csconstvalue(value)        %feature("cs:constvalue",value)
 943#define %csenum(wrapapproach)       %feature("cs:enum","wrapapproach")
 944#define %csmethodmodifiers          %feature("cs:methodmodifiers")
 945#define %csnothrowexception         %feature("except")
 946#define %csattributes               %feature("cs:attributes")
 947
 948%pragma(csharp) imclassclassmodifiers="class"
 949%pragma(csharp) moduleclassmodifiers="public class"
 950
 951%pragma(csharp) moduleimports=%{
 952using System;
 953using System.Runtime.InteropServices;
 954%}
 955
 956%pragma(csharp) imclassimports=%{
 957using System;
 958using System.Runtime.InteropServices;
 959%}
 960
 961/* Some ANSI C typemaps */
 962
 963%apply unsigned long { size_t };
 964%apply const unsigned long & { const size_t & };
 965
 966/* Array reference typemaps */
 967%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
 968
 969/* const pointers */
 970%apply SWIGTYPE * { SWIGTYPE *const }
 971
 972/* csharp keywords */
 973%include <csharpkw.swg>
 974
 975// Default enum handling
 976%include <enums.swg>
 977
 978// For vararg handling in macros, from swigmacros.swg
 979#define %arg(X...) X
 980
 981/*
 982// Alternative char * typemaps.
 983%pragma(csharp) imclasscode=%{
 984  public class SWIGStringMarshal : IDisposable {
 985    public readonly HandleRef swigCPtr;
 986    public SWIGStringMarshal(string str) {
 987      swigCPtr = new HandleRef(this, System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(str));
 988    }
 989    public virtual void Dispose() {
 990      System.Runtime.InteropServices.Marshal.FreeHGlobal(swigCPtr.Handle);
 991      GC.SuppressFinalize(this);
 992    }
 993  }
 994%}
 995
 996%typemap(imtype, out="IntPtr") char *, char[ANY], char[]   "HandleRef"
 997%typemap(out) char *, char[ANY], char[] %{ $result = $1; %}
 998%typemap(csin) char *, char[ANY], char[] "new $imclassname.SWIGStringMarshal($csinput).swigCPtr"
 999%typemap(csout, excode=SWIGEXCODE) char *, char[ANY], char[] {
1000    string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
1001    return ret;
1002  }
1003%typemap(csvarin, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
1004    set {
1005      $imcall;$excode
1006    } %}
1007%typemap(csvarout, excode=SWIGEXCODE2) char *, char[ANY], char[] %{
1008    get {
1009      string ret = System.Runtime.InteropServices.Marshal.PtrToStringAnsi($imcall);$excode
1010      return ret;
1011    } %}
1012*/
1013