diff options
author | Jan Jezabek <jezabek@poczta.onet.pl> | 2008-11-05 12:05:14 +0000 |
---|---|---|
committer | Jan Jezabek <jezabek@poczta.onet.pl> | 2008-11-05 12:05:14 +0000 |
commit | 810aa9117c59b5a0de496316d590d0732d1391c7 (patch) | |
tree | 8efafe2cafc00f83ba53f5b256a15017be8d203e | |
parent | d19fc193d121ebf575f70bee0ac184a1a120feb1 (diff) | |
download | swig-810aa9117c59b5a0de496316d590d0732d1391c7.tar.gz |
Add typemaps for const string & and const wstring &. Based on patch by David Piepgrass.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-jezabek@10914 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | Lib/com/std_string.i | 27 | ||||
-rw-r--r-- | Lib/com/std_wstring.i | 23 |
2 files changed, 46 insertions, 4 deletions
diff --git a/Lib/com/std_string.i b/Lib/com/std_string.i index 7f201dde4..2c89b82a6 100644 --- a/Lib/com/std_string.i +++ b/Lib/com/std_string.i @@ -16,8 +16,8 @@ namespace std { %naturalvar string; class string; -%typemap(ctype) string "WCHAR *" -%typemap(comtype) string "BSTR" +%typemap(ctype) string, const string & "WCHAR *" +%typemap(comtype) string, const string & "BSTR" %typemap(in) string { if ($input) { @@ -29,6 +29,18 @@ class string; } } +%typemap(in) const string & ($*1_ltype temp) { + if ($input) { + int SWIG_len = WideCharToMultiByte(CP_ACP, 0, $input, -1, 0, 0, 0, 0); + char *$1_pstr = (char *) malloc(SWIG_len); + WideCharToMultiByte(CP_ACP, 0, $input, -1, $1_pstr, SWIG_len, 0, 0); + temp.assign($1_pstr); + free($1_pstr); + } + + $1 = &temp; +} + %typemap(out) string %{ { int SWIG_len = MultiByteToWideChar(CP_ACP, 0, $1.c_str(), -1, 0, 0); @@ -40,4 +52,15 @@ class string; } %} +%typemap(out) const string & %{ + { + int SWIG_len = MultiByteToWideChar(CP_ACP, 0, (*$1).c_str(), -1, 0, 0); + WCHAR *SWIG_res = (WCHAR *) CoTaskMemAlloc((SWIG_len + 2) * sizeof(WCHAR)); + /* First 4 bytes contain length in bytes */ + *((unsigned int *) SWIG_res) = (unsigned int) (SWIG_len - 1) * sizeof(WCHAR); + MultiByteToWideChar(CP_ACP, 0, (*$1).c_str(), -1, SWIG_res + 2, SWIG_len); + $result = SWIG_res + 2; + } +%} + } diff --git a/Lib/com/std_wstring.i b/Lib/com/std_wstring.i index cbe65ce6d..675cdd45d 100644 --- a/Lib/com/std_wstring.i +++ b/Lib/com/std_wstring.i @@ -17,8 +17,8 @@ namespace std { %naturalvar wstring; class wstring; -%typemap(ctype) wstring "WCHAR *" -%typemap(comtype) wstring "BSTR" +%typemap(ctype) wstring, const wstring& "WCHAR *" +%typemap(comtype) wstring, const wstring& "BSTR" %typemap(in) wstring { if ($input) { @@ -26,6 +26,13 @@ class wstring; } } +%typemap(in) const wstring & ($*1_ltype temp) +%{ + if ($input) + temp.assign($input); + $1 = &temp; +%} + %typemap(out) wstring %{ { int SWIG_len = $1.size() + 1; @@ -37,4 +44,16 @@ class wstring; } %} +%typemap(out) const wstring & %{ + { + int SWIG_len = (*$1).size() + 1; + WCHAR *SWIG_res = (WCHAR *) CoTaskMemAlloc((SWIG_len + 2) * sizeof(WCHAR)); + /* First 4 bytes contain length in bytes */ + *((unsigned int *) SWIG_res) = (unsigned int) (SWIG_len - 1) * sizeof(WCHAR); + wcsncpy(SWIG_res + 2, (*$1).c_str(), SWIG_len); + $result = SWIG_res + 2; + } +%} + + } |