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.

175 lines
5.0 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_wstring.i
  6. *
  7. * Typemaps for std::wstring and const std::wstring&
  8. *
  9. * These are mapped to a Java String and are passed around by value.
  10. * Warning: Unicode / multibyte characters are handled differently on different
  11. * OSs so the std::wstring typemaps may not always work as intended.
  12. *
  13. * To use non-const std::wstring references use the following %apply. Note
  14. * that they are passed by value.
  15. * %apply const std::wstring & {std::wstring &};
  16. * ----------------------------------------------------------------------------- */
  17. namespace std {
  18. %naturalvar wstring;
  19. class wstring;
  20. // wstring
  21. %typemap(jni) wstring "jstring"
  22. %typemap(jtype) wstring "String"
  23. %typemap(jstype) wstring "String"
  24. %typemap(javadirectorin) wstring "$jniinput"
  25. %typemap(javadirectorout) wstring "$javacall"
  26. %typemap(in) wstring
  27. %{if(!$input) {
  28. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
  29. return $null;
  30. }
  31. const jchar *$1_pstr = jenv->GetStringChars($input, 0);
  32. if (!$1_pstr) return $null;
  33. jsize $1_len = jenv->GetStringLength($input);
  34. if ($1_len) {
  35. $1.reserve($1_len);
  36. for (jsize i = 0; i < $1_len; ++i) {
  37. $1.push_back((wchar_t)$1_pstr[i]);
  38. }
  39. }
  40. jenv->ReleaseStringChars($input, $1_pstr);
  41. %}
  42. %typemap(directorout) wstring
  43. %{if(!$input) {
  44. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
  45. return $null;
  46. }
  47. const jchar *$1_pstr = jenv->GetStringChars($input, 0);
  48. if (!$1_pstr) return $null;
  49. jsize $1_len = jenv->GetStringLength($input);
  50. if ($1_len) {
  51. $result.reserve($1_len);
  52. for (jsize i = 0; i < $1_len; ++i) {
  53. $result.push_back((wchar_t)$1_pstr[i]);
  54. }
  55. }
  56. jenv->ReleaseStringChars($input, $1_pstr);
  57. %}
  58. %typemap(directorin,descriptor="Ljava/lang/String;") wstring {
  59. jsize $1_len = $1.length();
  60. jchar *conv_buf = new jchar[$1_len];
  61. for (jsize i = 0; i < $1_len; ++i) {
  62. conv_buf[i] = (jchar)$1[i];
  63. }
  64. $input = jenv->NewString(conv_buf, $1_len);
  65. delete [] conv_buf;
  66. }
  67. %typemap(out) wstring
  68. %{jsize $1_len = $1.length();
  69. jchar *conv_buf = new jchar[$1_len];
  70. for (jsize i = 0; i < $1_len; ++i) {
  71. conv_buf[i] = (jchar)$1[i];
  72. }
  73. $result = jenv->NewString(conv_buf, $1_len);
  74. delete [] conv_buf; %}
  75. %typemap(javain) wstring "$javainput"
  76. %typemap(javaout) wstring {
  77. return $jnicall;
  78. }
  79. //%typemap(typecheck) wstring = wchar_t *;
  80. %typemap(throws) wstring
  81. %{ std::string message($1.begin(), $1.end());
  82. SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
  83. return $null; %}
  84. // const wstring &
  85. %typemap(jni) const wstring & "jstring"
  86. %typemap(jtype) const wstring & "String"
  87. %typemap(jstype) const wstring & "String"
  88. %typemap(javadirectorin) const wstring & "$jniinput"
  89. %typemap(javadirectorout) const wstring & "$javacall"
  90. %typemap(in) const wstring &
  91. %{if(!$input) {
  92. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
  93. return $null;
  94. }
  95. const jchar *$1_pstr = jenv->GetStringChars($input, 0);
  96. if (!$1_pstr) return $null;
  97. jsize $1_len = jenv->GetStringLength($input);
  98. std::wstring $1_str;
  99. if ($1_len) {
  100. $1_str.reserve($1_len);
  101. for (jsize i = 0; i < $1_len; ++i) {
  102. $1_str.push_back((wchar_t)$1_pstr[i]);
  103. }
  104. }
  105. $1 = &$1_str;
  106. jenv->ReleaseStringChars($input, $1_pstr);
  107. %}
  108. %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const wstring &
  109. %{if(!$input) {
  110. SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
  111. return $null;
  112. }
  113. const jchar *$1_pstr = jenv->GetStringChars($input, 0);
  114. if (!$1_pstr) return $null;
  115. jsize $1_len = jenv->GetStringLength($input);
  116. /* possible thread/reentrant code problem */
  117. static std::wstring $1_str;
  118. if ($1_len) {
  119. $1_str.reserve($1_len);
  120. for (jsize i = 0; i < $1_len; ++i) {
  121. $1_str.push_back((wchar_t)$1_pstr[i]);
  122. }
  123. }
  124. $result = &$1_str;
  125. jenv->ReleaseStringChars($input, $1_pstr); %}
  126. %typemap(directorin,descriptor="Ljava/lang/String;") const wstring & {
  127. jsize $1_len = $1.length();
  128. jchar *conv_buf = new jchar[$1_len];
  129. for (jsize i = 0; i < $1_len; ++i) {
  130. conv_buf[i] = (jchar)($1)[i];
  131. }
  132. $input = jenv->NewString(conv_buf, $1_len);
  133. delete [] conv_buf;
  134. }
  135. %typemap(out) const wstring &
  136. %{jsize $1_len = $1->length();
  137. jchar *conv_buf = new jchar[$1_len];
  138. for (jsize i = 0; i < $1_len; ++i) {
  139. conv_buf[i] = (jchar)(*$1)[i];
  140. }
  141. $result = jenv->NewString(conv_buf, $1_len);
  142. delete [] conv_buf; %}
  143. %typemap(javain) const wstring & "$javainput"
  144. %typemap(javaout) const wstring & {
  145. return $jnicall;
  146. }
  147. //%typemap(typecheck) const wstring & = wchar_t *;
  148. %typemap(throws) const wstring &
  149. %{ std::string message($1.begin(), $1.end());
  150. SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
  151. return $null; %}
  152. }