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