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.

120 lines
3.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. * Typemaps for std::string and const std::string&
  8. * These are mapped to a Java String and are passed around by value.
  9. *
  10. * To use non-const std::string references use the following %apply. Note
  11. * that they are passed by value.
  12. * %apply const std::string & {std::string &};
  13. * ----------------------------------------------------------------------------- */
  14. %{
  15. #include <string>
  16. %}
  17. namespace std {
  18. %naturalvar string;
  19. class string;
  20. // string
  21. %typemap(jni) string "jstring"
  22. %typemap(jtype) string "String"
  23. %typemap(jstype) string "String"
  24. %typemap(javadirectorin) string "$jniinput"
  25. %typemap(javadirectorout) string "$javacall"
  26. %typemap(in) string
  27. %{ if(!$input) {
  28. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
  29. return $null;
  30. }
  31. const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
  32. if (!$1_pstr) return $null;
  33. $1.assign($1_pstr);
  34. jenv->ReleaseStringUTFChars($input, $1_pstr); %}
  35. %typemap(directorout) string
  36. %{ if(!$input) {
  37. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
  38. return $null;
  39. }
  40. const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
  41. if (!$1_pstr) return $null;
  42. $result.assign($1_pstr);
  43. jenv->ReleaseStringUTFChars($input, $1_pstr); %}
  44. %typemap(directorin,descriptor="Ljava/lang/String;") string
  45. %{ $input = jenv->NewStringUTF($1.c_str()); %}
  46. %typemap(out) string
  47. %{ $result = jenv->NewStringUTF($1.c_str()); %}
  48. %typemap(javain) string "$javainput"
  49. %typemap(javaout) string {
  50. return $jnicall;
  51. }
  52. %typemap(typecheck) string = char *;
  53. %typemap(throws) string
  54. %{ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.c_str());
  55. return $null; %}
  56. // const string &
  57. %typemap(jni) const string & "jstring"
  58. %typemap(jtype) const string & "String"
  59. %typemap(jstype) const string & "String"
  60. %typemap(javadirectorin) const string & "$jniinput"
  61. %typemap(javadirectorout) const string & "$javacall"
  62. %typemap(in) const string &
  63. %{ if(!$input) {
  64. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
  65. return $null;
  66. }
  67. const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
  68. if (!$1_pstr) return $null;
  69. std::string $1_str($1_pstr);
  70. $1 = &$1_str;
  71. jenv->ReleaseStringUTFChars($input, $1_pstr); %}
  72. %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
  73. %{ if(!$input) {
  74. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
  75. return $null;
  76. }
  77. const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
  78. if (!$1_pstr) return $null;
  79. /* possible thread/reentrant code problem */
  80. static std::string $1_str;
  81. $1_str = $1_pstr;
  82. $result = &$1_str;
  83. jenv->ReleaseStringUTFChars($input, $1_pstr); %}
  84. %typemap(directorin,descriptor="Ljava/lang/String;") const string &
  85. %{ $input = jenv->NewStringUTF($1.c_str()); %}
  86. %typemap(out) const string &
  87. %{ $result = jenv->NewStringUTF($1->c_str()); %}
  88. %typemap(javain) const string & "$javainput"
  89. %typemap(javaout) const string & {
  90. return $jnicall;
  91. }
  92. %typemap(typecheck) const string & = char *;
  93. %typemap(throws) const string &
  94. %{ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.c_str());
  95. return $null; %}
  96. }