| 1 | // |
| 2 | // SWIG typemaps for std::string types |
| 3 | // Luigi Ballabio |
| 4 | // May 7, 2002 |
| 5 | // |
| 6 | // PHP implementation |
| 7 | |
| 8 | |
| 9 | // ------------------------------------------------------------------------ |
| 10 | // std::string is typemapped by value |
| 11 | // This can prevent exporting methods which return a string |
| 12 | // in order for the user to modify it. |
| 13 | // However, I think I'll wait until someone asks for it... |
| 14 | // ------------------------------------------------------------------------ |
| 15 | |
| 16 | %include exception.i |
| 17 | |
| 18 | %{ |
| 19 | #include <string> |
| 20 | %} |
| 21 | |
| 22 | namespace std { |
| 23 | |
| 24 | class string; |
| 25 | |
| 26 | %typemap(in) string { |
| 27 | convert_to_string_ex($input); |
| 28 | $1 = std::string(Z_STRVAL_PP($input)); |
| 29 | } |
| 30 | |
| 31 | %typemap(in) const string & (std::string temp) { |
| 32 | convert_to_string_ex($input); |
| 33 | temp = std::string(Z_STRVAL_PP($input)); |
| 34 | $1 = &temp; |
| 35 | } |
| 36 | |
| 37 | %typemap(out) string { |
| 38 | ZVAL_STRINGL($result,const_cast<char*>($1.c_str()),$1.length(),1); |
| 39 | } |
| 40 | |
| 41 | %typemap(out) const string & { |
| 42 | ZVAL_STRINGL($result,const_cast<char*>($1->c_str()),$1->length(),1); |
| 43 | } |
| 44 | |
| 45 | %typemap(throws) string %{ |
| 46 | SWIG_PHP_Error(E_ERROR, (char *)$1.c_str()); |
| 47 | %} |
| 48 | |
| 49 | %typemap(throws) const string& %{ |
| 50 | SWIG_PHP_Error(E_ERROR, (char *)$1.c_str()); |
| 51 | %} |
| 52 | } |