PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/php/std_string.i

#
Swig | 79 lines | 53 code | 17 blank | 9 comment | 0 complexity | aab52e3effa5b19214b1e2469e9e50d9 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * std_string.i
  3. *
  4. * SWIG typemaps for std::string types
  5. * ----------------------------------------------------------------------------- */
  6. // ------------------------------------------------------------------------
  7. // std::string is typemapped by value
  8. // This can prevent exporting methods which return a string
  9. // in order for the user to modify it.
  10. // However, I think I'll wait until someone asks for it...
  11. // ------------------------------------------------------------------------
  12. %include <exception.i>
  13. %{
  14. #include <string>
  15. %}
  16. namespace std {
  17. %naturalvar string;
  18. class string;
  19. %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string, const string& %{
  20. $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
  21. %}
  22. %typemap(in) string %{
  23. convert_to_string_ex($input);
  24. $1.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
  25. %}
  26. %typemap(directorout) string %{
  27. convert_to_string_ex($input);
  28. $result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
  29. %}
  30. %typemap(out) string %{
  31. ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
  32. %}
  33. %typemap(directorin) string, const string& %{
  34. ZVAL_STRINGL($input, const_cast<char*>($1.data()), $1.size(), 1);
  35. %}
  36. %typemap(out) const string & %{
  37. ZVAL_STRINGL($result, const_cast<char*>($1->data()), $1->size(), 1);
  38. %}
  39. %typemap(throws) string, const string& %{
  40. zend_throw_exception(NULL, const_cast<char*>($1.c_str()), 0 TSRMLS_CC);
  41. return;
  42. %}
  43. /* These next two handle a function which takes a non-const reference to
  44. * a std::string and modifies the string. */
  45. %typemap(in) string & (std::string temp) %{
  46. convert_to_string_ex($input);
  47. temp.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
  48. $1 = &temp;
  49. %}
  50. %typemap(directorout) string & (std::string *temp) %{
  51. convert_to_string_ex($input);
  52. temp = new std::string(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
  53. swig_acquire_ownership(temp);
  54. $result = temp;
  55. %}
  56. %typemap(argout) string & %{
  57. ZVAL_STRINGL(*($input), const_cast<char*>($1->data()), $1->size(), 1);
  58. %}
  59. /* SWIG will apply the non-const typemap above to const string& without
  60. * this more specific typemap. */
  61. %typemap(argout) const string & "";
  62. }