PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/Lib/java/std_string.i

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