Added std_string support. Renamed SWIG_exception to SWIG_exc to avoid name collision with macro in Lib/exception.i.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10720 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d4f62fda47
commit
dcec3c3fb0
6 changed files with 140 additions and 50 deletions
50
Lib/c/std_string.i
Normal file
50
Lib/c/std_string.i
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
// use "const string &" typemaps for wrapping member strings
|
||||
%naturalvar string;
|
||||
|
||||
class string;
|
||||
|
||||
%typemap(ctype) string "char *"
|
||||
%typemap(ctype) const string & "char *"
|
||||
%typemap(couttype) string "char *"
|
||||
%typemap(couttype) const string & "char *"
|
||||
|
||||
%typemap(in) string {
|
||||
if ($input) {
|
||||
$1.assign($input);
|
||||
}
|
||||
else {
|
||||
$1.resize(0);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const string & {
|
||||
if ($input) {
|
||||
$1 = new std::string($input);
|
||||
}
|
||||
else {
|
||||
$1 = new std::string();
|
||||
$1->resize(0);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(freearg) const string & {
|
||||
if ($1)
|
||||
delete $1;
|
||||
}
|
||||
|
||||
%typemap(out) string, const string & {
|
||||
const char *str = cppresult.c_str();
|
||||
size_t len = strlen(str);
|
||||
$result = (char *) malloc(len + 1);
|
||||
memcpy($result, str, len);
|
||||
$result[len] = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue