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.

100 lines
2.5 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
  8. * ----------------------------------------------------------------------------- */
  9. %{
  10. #include <string>
  11. %}
  12. namespace std {
  13. %naturalvar string;
  14. %insert(closprefix) %{ (declare (hide <std-string>)) %}
  15. %nodefault string;
  16. %rename("std-string") string;
  17. class string {
  18. public:
  19. ~string() {}
  20. };
  21. %extend string {
  22. char *str;
  23. }
  24. %{
  25. #define std_string_str_get(s) ((char *)((s)->c_str()))
  26. #define std_string_str_set(s,v) (s->assign((char *)(v)))
  27. %}
  28. %typemap(typecheck) string = char *;
  29. %typemap(typecheck) const string & = char *;
  30. %typemap(in) string (char* tempptr) {
  31. if ($input == C_SCHEME_FALSE) {
  32. $1.resize(0);
  33. } else {
  34. if (!C_swig_is_string ($input)) {
  35. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE,
  36. "Argument #$argnum is not a string");
  37. }
  38. tempptr = SWIG_MakeString($input);
  39. $1.assign(tempptr);
  40. if (tempptr) SWIG_free(tempptr);
  41. }
  42. }
  43. %typemap(in) const string& (std::string temp,
  44. char* tempptr) {
  45. if ($input == C_SCHEME_FALSE) {
  46. temp.resize(0);
  47. $1 = &temp;
  48. } else {
  49. if (!C_swig_is_string ($input)) {
  50. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE,
  51. "Argument #$argnum is not a string");
  52. }
  53. tempptr = SWIG_MakeString($input);
  54. temp.assign(tempptr);
  55. if (tempptr) SWIG_free(tempptr);
  56. $1 = &temp;
  57. }
  58. }
  59. %typemap(out) string {
  60. int size = $1.size();
  61. C_word *space = C_alloc (C_SIZEOF_STRING (size));
  62. $result = C_string (&space, size, (char *) $1.c_str());
  63. }
  64. %typemap(out) const string& {
  65. int size = $1->size();
  66. C_word *space = C_alloc (C_SIZEOF_STRING (size));
  67. $result = C_string (&space, size, (char *) $1->c_str());
  68. }
  69. %typemap(varin) string {
  70. if ($input == C_SCHEME_FALSE) {
  71. $1.resize(0);
  72. } else {
  73. char *tempptr;
  74. if (!C_swig_is_string ($input)) {
  75. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE,
  76. "Argument #$argnum is not a string");
  77. }
  78. tempptr = SWIG_MakeString($input);
  79. $1.assign(tempptr);
  80. if (tempptr) SWIG_free(tempptr);
  81. }
  82. }
  83. %typemap(varout) string {
  84. int size = $1.size();
  85. C_word *space = C_alloc (C_SIZEOF_STRING (size));
  86. $result = C_string (&space, size, (char *) $1.c_str());
  87. }
  88. }