Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / share / swig / 1.3.26 / java / std_wstring.i
CommitLineData
920dae64
AT
1/* ------------------------------------------------------------------------
2 Typemaps for std::wstring and const std::wstring&
3
4 These are mapped to a Java String and are passed around by value.
5 Warning: Unicode / multibyte characters are handled differently on different
6 OSs so the std::wstring typemaps may not always work as intended.
7
8 To use non-const std::wstring references use the following %apply. Note
9 that they are passed by value.
10 %apply const std::wstring & {std::wstring &};
11 ------------------------------------------------------------------------ */
12
13namespace std {
14
15class wstring;
16
17// wstring
18%typemap(jni) wstring "jstring"
19%typemap(jtype) wstring "String"
20%typemap(jstype) wstring "String"
21%typemap(javadirectorin) wstring "$jniinput"
22%typemap(javadirectorout) wstring "$javacall"
23
24%typemap(in) wstring
25%{if(!$input) {
26 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
27 return $null;
28 }
29 const jchar *$1_pstr = jenv->GetStringChars($input, 0);
30 if (!$1_pstr) return $null;
31 jsize $1_len = jenv->GetStringLength($input);
32 if ($1_len) {
33 wchar_t *conv_buf = new wchar_t[$1_len];
34 for (jsize i = 0; i < $1_len; ++i) {
35 conv_buf[i] = $1_pstr[i];
36 }
37 $1 = std::wstring(conv_buf, $1_len);
38 delete [] conv_buf;
39 }
40 jenv->ReleaseStringChars($input, $1_pstr);
41 %}
42
43%typemap(directorout) wstring
44%{if(!$input) {
45 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
46 return $null;
47 }
48 const jchar *$1_pstr = jenv->GetStringChars($input, 0);
49 if (!$1_pstr) return $null;
50 jsize $1_len = jenv->GetStringLength($input);
51 if ($1_len) {
52 wchar_t *conv_buf = new wchar_t[$1_len];
53 for (jsize i = 0; i < $1_len; ++i) {
54 conv_buf[i] = $1_pstr[i];
55 }
56 $1 = std::wstring(conv_buf, $1_len);
57 delete [] conv_buf;
58 }
59 jenv->ReleaseStringChars($input, $1_pstr);
60 %}
61
62%typemap(directorin,descriptor="Ljava/lang/String;") wstring
63%{jsize $1_len = $1.length();
64 jchar *conv_buf = new jchar[$1_len];
65 for (jsize i = 0; i < $1_len; ++i) {
66 conv_buf[i] = (jchar)$1[i];
67 }
68 $input = jenv->NewString(conv_buf, $1_len);
69 delete [] conv_buf; %}
70
71%typemap(out) wstring
72%{jsize $1_len = $1.length();
73 jchar *conv_buf = new jchar[$1_len];
74 for (jsize i = 0; i < $1_len; ++i) {
75 conv_buf[i] = (jchar)$1[i];
76 }
77 $result = jenv->NewString(conv_buf, $1_len);
78 delete [] conv_buf; %}
79
80%typemap(javain) wstring "$javainput"
81
82%typemap(javaout) wstring {
83 return $jnicall;
84 }
85
86// const wstring &
87%typemap(jni) const wstring & "jstring"
88%typemap(jtype) const wstring & "String"
89%typemap(jstype) const wstring & "String"
90%typemap(javadirectorin) const wstring & "$jniinput"
91%typemap(javadirectorout) const wstring & "$javacall"
92
93%typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const wstring &
94%{if(!$input) {
95 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
96 return $null;
97 }
98 const jchar *$1_pstr = jenv->GetStringChars($input, 0);
99 if (!$1_pstr) return $null;
100 jsize $1_len = jenv->GetStringLength($input);
101 static std::wstring $1_str;
102 if ($1_len) {
103 wchar_t *conv_buf = new wchar_t[$1_len];
104 for (jsize i = 0; i < $1_len; ++i) {
105 conv_buf[i] = $1_pstr[i];
106 }
107 $1_str = std::wstring(conv_buf, $1_len);
108 delete [] conv_buf;
109 }
110 $1 = &$1_str;
111 jenv->ReleaseStringChars($input, $1_pstr); %}
112
113%typemap(directorout) const wstring &
114%{if(!$input) {
115 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
116 return $null;
117 }
118 const jchar *$1_pstr = jenv->GetStringChars($input, 0);
119 if (!$1_pstr) return $null;
120 jsize $1_len = jenv->GetStringLength($input);
121 std::wstring $1_str;
122 if ($1_len) {
123 wchar_t *conv_buf = new wchar_t[$1_len];
124 for (jsize i = 0; i < $1_len; ++i) {
125 conv_buf[i] = $1_pstr[i];
126 }
127 $1_str = std::wstring(conv_buf, $1_len);
128 delete [] conv_buf;
129 }
130 $1 = &$1_str;
131 jenv->ReleaseStringChars($input, $1_pstr); %}
132
133%typemap(directorin,descriptor="Ljava/lang/String;") const wstring &
134%{jsize $1_len = $1.length();
135 jchar *conv_buf = new jchar[$1_len];
136 for (jsize i = 0; i < $1_len; ++i) {
137 conv_buf[i] = (jchar)($1)[i];
138 }
139 $input = jenv->NewString(conv_buf, $1_len);
140 delete [] conv_buf; %}
141
142%typemap(out) const wstring &
143%{jsize $1_len = $1->length();
144 jchar *conv_buf = new jchar[$1_len];
145 for (jsize i = 0; i < $1_len; ++i) {
146 conv_buf[i] = (jchar)(*$1)[i];
147 }
148 $result = jenv->NewString(conv_buf, $1_len);
149 delete [] conv_buf; %}
150
151%typemap(javain) const wstring & "$javainput"
152
153%typemap(javaout) const wstring & {
154 return $jnicall;
155 }
156
157}
158