Home | History | Annotate | Download | only in csharp
      1 /* -----------------------------------------------------------------------------
      2  * std_wstring.i
      3  *
      4  * Typemaps for std::wstring and const std::wstring&
      5  * These are mapped to a C# String and are passed around by value.
      6  *
      7  * To use non-const std::wstring references use the following %apply.  Note
      8  * that they are passed by value.
      9  * %apply const std::wstring & {std::wstring &};
     10  * ----------------------------------------------------------------------------- */
     11 
     12 %include <wchar.i>
     13 
     14 %{
     15 #include <string>
     16 %}
     17 
     18 namespace std {
     19 
     20 %naturalvar wstring;
     21 
     22 class wstring;
     23 
     24 // wstring
     25 %typemap(ctype, out="void *") wstring "wchar_t *"
     26 %typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]") wstring "string"
     27 %typemap(cstype) wstring "string"
     28 %typemap(csdirectorin) wstring "$iminput"
     29 %typemap(csdirectorout) wstring "$cscall"
     30 
     31 %typemap(in, canthrow=1) wstring
     32 %{ if (!$input) {
     33     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
     34     return $null;
     35    }
     36    $1.assign($input); %}
     37 %typemap(out) wstring %{ $result = SWIG_csharp_wstring_callback($1.c_str()); %}
     38 
     39 %typemap(directorout, canthrow=1) wstring
     40 %{ if (!$input) {
     41     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
     42     return $null;
     43    }
     44    $result.assign($input); %}
     45 
     46 %typemap(directorin) wstring %{ $input = SWIG_csharp_wstring_callback($1.c_str()); %}
     47 
     48 %typemap(csin) wstring "$csinput"
     49 %typemap(csout, excode=SWIGEXCODE) wstring {
     50     string ret = $imcall;$excode
     51     return ret;
     52   }
     53 
     54 %typemap(typecheck) wstring = wchar_t *;
     55 
     56 %typemap(throws, canthrow=1) wstring
     57 %{ std::string message($1.begin(), $1.end());
     58    SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
     59    return $null; %}
     60 
     61 // const wstring &
     62 %typemap(ctype, out="void *") const wstring & "wchar_t *"
     63 %typemap(imtype, inattributes="[MarshalAs(UnmanagedType.LPWStr)]") const wstring & "string"
     64 %typemap(cstype) const wstring & "string"
     65 
     66 %typemap(csdirectorin) const wstring & "$iminput"
     67 %typemap(csdirectorout) const wstring & "$cscall"
     68 
     69 %typemap(in, canthrow=1) const wstring &
     70 %{ if (!$input) {
     71     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
     72     return $null;
     73    }
     74    std::wstring $1_str($input);
     75    $1 = &$1_str; %}
     76 %typemap(out) const wstring & %{ $result = SWIG_csharp_wstring_callback($1->c_str()); %}
     77 
     78 %typemap(csin) const wstring & "$csinput"
     79 %typemap(csout, excode=SWIGEXCODE) const wstring & {
     80     string ret = $imcall;$excode
     81     return ret;
     82   }
     83 
     84 %typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const wstring &
     85 %{ if (!$input) {
     86     SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
     87     return $null;
     88    }
     89    /* possible thread/reentrant code problem */
     90    static std::wstring $1_str;
     91    $1_str = $input;
     92    $result = &$1_str; %}
     93 
     94 %typemap(directorin) const wstring & %{ $input = SWIG_csharp_wstring_callback($1.c_str()); %}
     95 
     96 %typemap(csvarin, excode=SWIGEXCODE2) const wstring & %{
     97     set {
     98       $imcall;$excode
     99     } %}
    100 %typemap(csvarout, excode=SWIGEXCODE2) const wstring & %{
    101     get {
    102       string ret = $imcall;$excode
    103       return ret;
    104     } %}
    105 
    106 %typemap(typecheck) const wstring & = wchar_t *;
    107 
    108 %typemap(throws, canthrow=1) const wstring &
    109 %{ std::string message($1.begin(), $1.end());
    110    SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
    111    return $null; %}
    112 
    113 }
    114 
    115