| 1 | // |
| 2 | // SWIG typemaps for std::string |
| 3 | // William Fulton |
| 4 | // |
| 5 | // C# implementation |
| 6 | // |
| 7 | /* ------------------------------------------------------------------------ |
| 8 | Typemaps for std::string and const std::string& |
| 9 | These are mapped to a C# String and are passed around by value. |
| 10 | |
| 11 | To use non-const std::string references use the following %apply. Note |
| 12 | that they are passed by value. |
| 13 | %apply const std::string & {std::string &}; |
| 14 | ------------------------------------------------------------------------ */ |
| 15 | |
| 16 | %{ |
| 17 | #include <string> |
| 18 | %} |
| 19 | |
| 20 | namespace std { |
| 21 | |
| 22 | class string; |
| 23 | |
| 24 | // string |
| 25 | %typemap(ctype) string "char *" |
| 26 | %typemap(imtype) string "string" |
| 27 | %typemap(cstype) string "string" |
| 28 | |
| 29 | %typemap(in, canthrow=1) string |
| 30 | %{ if (!$input) { |
| 31 | SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0); |
| 32 | return $null; |
| 33 | } |
| 34 | $1 = std::string($input); %} |
| 35 | %typemap(out) string %{ $result = SWIG_csharp_string_callback($1.c_str()); %} |
| 36 | |
| 37 | %typemap(csin) string "$csinput" |
| 38 | %typemap(csout, excode=SWIGEXCODE) string { |
| 39 | string ret = $imcall;$excode |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | %typemap(csvarin, excode=SWIGEXCODE2) string %{ |
| 44 | set { |
| 45 | $imcall;$excode |
| 46 | } %} |
| 47 | %typemap(csvarout, excode=SWIGEXCODE2) string %{ |
| 48 | get { |
| 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 | |
| 60 | // const string & |
| 61 | %typemap(ctype) const string & "char *" |
| 62 | %typemap(imtype) const string & "string" |
| 63 | %typemap(cstype) const string & "string" |
| 64 | |
| 65 | %typemap(in, canthrow=1) const string & |
| 66 | %{ if (!$input) { |
| 67 | SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null string", 0); |
| 68 | return $null; |
| 69 | } |
| 70 | std::string $1_str($input); |
| 71 | $1 = &$1_str; %} |
| 72 | %typemap(out) const string & %{ $result = SWIG_csharp_string_callback($1->c_str()); %} |
| 73 | |
| 74 | %typemap(csin) const string & "$csinput" |
| 75 | %typemap(csout, excode=SWIGEXCODE) const string & { |
| 76 | string ret = $imcall;$excode |
| 77 | return ret; |
| 78 | } |
| 79 | |
| 80 | %typemap(csvarin, excode=SWIGEXCODE2) const string & %{ |
| 81 | set { |
| 82 | $imcall;$excode |
| 83 | } %} |
| 84 | %typemap(csvarout, excode=SWIGEXCODE2) const string & %{ |
| 85 | get { |
| 86 | string ret = $imcall;$excode |
| 87 | return ret; |
| 88 | } %} |
| 89 | |
| 90 | %typemap(typecheck) const string & = char *; |
| 91 | |
| 92 | %typemap(throws, canthrow=1) const string & %{ |
| 93 | SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.c_str()); |
| 94 | return $null; |
| 95 | %} |
| 96 | |
| 97 | } |
| 98 | |