PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/d/std_string.i

#
Swig | 98 lines | 68 code | 19 blank | 11 comment | 0 complexity | 4b9517621f8a1743ae10aa8c28c96dcc 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 D char[] 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. %define SWIGD_STD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
  18. // string
  19. %typemap(ctype) string, const string & "char *"
  20. %typemap(imtype) string, const string & #DW_STRING_TYPE
  21. %typemap(dtype) string, const string & #DP_STRING_TYPE
  22. %typemap(in, canthrow=1) string, const string &
  23. %{ if (!$input) {
  24. SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
  25. return $null;
  26. }
  27. $1.assign($input); %}
  28. %typemap(in, canthrow=1) const string &
  29. %{ if (!$input) {
  30. SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
  31. return $null;
  32. }
  33. std::string $1_str($input);
  34. $1 = &$1_str; %}
  35. %typemap(out) string %{ $result = SWIG_d_string_callback($1.c_str()); %}
  36. %typemap(out) const string & %{ $result = SWIG_d_string_callback($1->c_str()); %}
  37. %typemap(din) string, const string & "($dinput ? TO_STRINGZ($dinput) : null)"
  38. %typemap(dout, excode=SWIGEXCODE) string, const string & {
  39. DP_STRING_TYPE ret = FROM_STRINGZ($imcall);$excode
  40. return ret;
  41. }
  42. %typemap(directorin) string, const string & %{ $input = SWIG_d_string_callback($1.c_str()); %}
  43. %typemap(directorout, canthrow=1) string
  44. %{ if (!$input) {
  45. SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
  46. return $null;
  47. }
  48. $result.assign($input); %}
  49. %typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
  50. %{ if (!$input) {
  51. SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
  52. return $null;
  53. }
  54. /* possible thread/reentrant code problem */
  55. static std::string $1_str;
  56. $1_str = $input;
  57. $result = &$1_str; %}
  58. %typemap(ddirectorin) string, const string & "FROM_STRINGZ($winput)"
  59. %typemap(ddirectorout) string, const string & "TO_STRINGZ($dcall)"
  60. %typemap(throws, canthrow=1) string, const string &
  61. %{ SWIG_DSetPendingException(SWIG_DException, $1.c_str());
  62. return $null; %}
  63. %typemap(typecheck) string, const string & = char *;
  64. %enddef
  65. // We need to have the \0-terminated string conversion functions available in
  66. // the D proxy modules.
  67. #if (SWIG_D_VERSION == 1)
  68. // Could be easily extended to support Phobos as well.
  69. SWIGD_STD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
  70. %pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
  71. #else
  72. SWIGD_STD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
  73. %pragma(d) globalproxyimports = %{
  74. static import std.conv;
  75. static import std.string;
  76. %}
  77. #endif
  78. #undef SWIGD_STD_STRING_TYPEMAPS
  79. } // namespace std