added wstring typemap. contributed by:
Wenyue Yu <wenyue@stud.ntnu.no>
tal@slt.atr.co.jp
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@683 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e5895fd8c2
commit
d84664faa8
1 changed files with 48 additions and 3 deletions
|
|
@ -127,7 +127,7 @@
|
|||
}
|
||||
|
||||
/*
|
||||
* typemaps for standard C++ string
|
||||
* typemaps for standard C++ string and wstring
|
||||
* by: Tal Shalif <tal@slt.atr.co.jp>
|
||||
*/
|
||||
/* what type to use in java source code */
|
||||
|
|
@ -148,7 +148,6 @@
|
|||
/* get the String from the StringBuffer */
|
||||
char *p = (char *)jenv->GetStringUTFChars($source, 0);
|
||||
$target = new string(p);
|
||||
/* free(p); HdH assuming string constructor makes a copy */
|
||||
JCALL(ReleaseStringUTFChars, jenv) $source, p);
|
||||
}
|
||||
}
|
||||
|
|
@ -161,4 +160,50 @@
|
|||
%typemap(java,jni) string & = const string &;
|
||||
%typemap(java,in) string & = const string &;
|
||||
%typemap(java,out) string & = const string &;
|
||||
%typemap(java,argout) string & = const string &;
|
||||
%typemap(java,freearg) string & = const string &;
|
||||
|
||||
/* what type to use in java source code */
|
||||
%typemap(java,jtype) const wstring & {String}
|
||||
|
||||
/* what is the corresponding jni type */
|
||||
%typemap(java,jni) const wstring & {jstring}
|
||||
|
||||
/* how to convert the c++ type to the java type */
|
||||
%typemap(java,out) const wstring & {
|
||||
unsigned int len = $source->length();
|
||||
jchar *conv_buf = new jchar[len];
|
||||
for (unsigned int i = 0; i < len; ++i) {
|
||||
conv_buf[i] = (jchar)(*$source)[i];
|
||||
}
|
||||
$target = JCALL(NewString, jenv) conv_buf, len);
|
||||
delete [] conv_buf;
|
||||
}
|
||||
|
||||
/* how to convert java type to requested c++ type */
|
||||
%typemap(java,in) const wstring & {
|
||||
$target = NULL;
|
||||
if($source != NULL) {
|
||||
/* get the String from the StringBuffer */
|
||||
const jchar *jchar_p = jenv->GetStringChars($source, 0);
|
||||
unsigned int len;
|
||||
for (len = 0; jchar_p[len]; ++len);
|
||||
if (len) {
|
||||
wchar_t *conv_buf = new wchar_t[len];
|
||||
for (unsigned int i = 0; i < len; ++i) {
|
||||
conv_buf[i] = jchar_p[i];
|
||||
}
|
||||
$target = new wstring(conv_buf, len);
|
||||
delete [] conv_buf;
|
||||
}
|
||||
|
||||
JCALL(ReleaseStringChars, jenv) $source, jchar_p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%typemap(java,jtype) wstring & = const wstring &;
|
||||
%typemap(java,jni) wstring & = const wstring &;
|
||||
%typemap(java,in) wstring & = const wstring &;
|
||||
%typemap(java,out) wstring & = const wstring &;
|
||||
%typemap(java,freearg) wstring & = const wstring &;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue