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