Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.2 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * std_string.i
  6. *
  7. * SWIG typemaps for std::string types
  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. %include <exception.i>
  16. %{
  17. #include <string>
  18. %}
  19. namespace std {
  20. %naturalvar string;
  21. class string;
  22. %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string %{
  23. $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
  24. %}
  25. %typemap(in) string %{
  26. convert_to_string_ex($input);
  27. $1.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
  28. %}
  29. %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& %{
  30. $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
  31. %}
  32. %typemap(out) string %{
  33. ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
  34. %}
  35. %typemap(out) const string & %{
  36. ZVAL_STRINGL($result, const_cast<char*>($1->data()), $1->size(), 1);
  37. %}
  38. %typemap(throws) string %{
  39. SWIG_PHP_Error(E_ERROR, (char *)$1.c_str());
  40. %}
  41. %typemap(throws) const string& %{
  42. SWIG_PHP_Error(E_ERROR, (char *)$1.c_str());
  43. %}
  44. /* These next two handle a function which takes a non-const reference to
  45. * a std::string and modifies the string. */
  46. %typemap(in) string & (std::string temp) %{
  47. convert_to_string_ex($input);
  48. temp.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
  49. $1 = &temp;
  50. %}
  51. %typemap(argout) string & %{
  52. ZVAL_STRINGL(*($input), const_cast<char*>($1->data()), $1->size(), 1);
  53. %}
  54. /* SWIG will apply the non-const typemap above to const string& without
  55. * this more specific typemap. */
  56. %typemap(argout) const string & "";
  57. }