2
* Typemaps for standard C++ STL string and wstring
3
* Contributed by: Tal Shalif <tal@slt.atr.co.jp>
5
/* what type to use in java source code */
6
%typemap(jni) const string & "jstring"
7
%typemap(jtype) const string & "String"
8
%typemap(jstype) const string & "String"
10
/* how to convert java type to requested c++ type */
11
%typemap(in) const string & {
14
/* get the String from the StringBuffer */
15
char *p = (char *)jenv->GetStringUTFChars($input, 0);
17
jenv->ReleaseStringUTFChars($input, p);
20
/* free resource once finished using */
21
%typemap(freearg) const string & {
24
/* how to convert the c++ type to the java type */
25
%typemap(out) const string & {
26
$result = jenv->NewStringUTF($1->c_str());
30
%typemap(jni) string & = const string &;
31
%typemap(jtype) string & = const string &;
32
%typemap(jstype) string & = const string &;
33
%typemap(in) string & = const string &;
34
%typemap(freearg) string & = const string &;
35
%typemap(out) string & = const string &;
37
%typemap(jni) const wstring & "jstring"
38
%typemap(jtype) const wstring & "String"
39
%typemap(jstype) const wstring & "String"
41
/* how to convert java type to requested c++ type */
42
%typemap(in) const wstring & {
45
/* get the String from the StringBuffer */
46
const jchar *jchar_p = jenv->GetStringChars($input, 0);
48
for (len = 0; jchar_p[len]; ++len);
50
wchar_t *conv_buf = new wchar_t[len];
51
for (unsigned int i = 0; i < len; ++i) {
52
conv_buf[i] = jchar_p[i];
54
$1 = new wstring(conv_buf, len);
57
jenv->ReleaseStringChars($input, jchar_p);
60
/* how to convert the c++ type to the java type */
61
%typemap(out) const wstring & {
62
unsigned int len = $1->length();
63
jchar *conv_buf = new jchar[len];
64
for (unsigned int i = 0; i < len; ++i) {
65
conv_buf[i] = (jchar)(*$1)[i];
67
$result = jenv->NewString(conv_buf, len);
72
%typemap(jni) wstring & = const wstring &;
73
%typemap(jtype) wstring & = const wstring &;
74
%typemap(jstype) wstring & = const wstring &;
75
%typemap(in) wstring & = const wstring &;
76
%typemap(out) wstring & = const wstring &;