dstrings.swg 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* -----------------------------------------------------------------------------
  2. * dstrings.swg
  3. *
  4. * Typemaps for wrapping pointers to/arrays of C chars as D strings.
  5. * ----------------------------------------------------------------------------- */
  6. %define SWIGD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
  7. %typemap(ctype) char *, char *&, char[ANY], char[] "char *"
  8. %typemap(imtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE
  9. %typemap(dtype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE
  10. /*
  11. * char* typemaps.
  12. */
  13. %typemap(in) char * %{ $1 = ($1_ltype)$input; %}
  14. %typemap(out) char * %{ $result = SWIG_d_string_callback((const char *)$1); %}
  15. %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
  16. %typemap(directorin) char * %{ $input = SWIG_d_string_callback((const char *)$1); %}
  17. %typemap(ddirectorin) char * "FROM_STRINGZ($winput)"
  18. %typemap(ddirectorout) char * "TO_STRINGZ($dcall)"
  19. /*
  20. * char*& typemaps.
  21. */
  22. %typemap(in) char *& ($*1_ltype temp = 0) %{
  23. temp = ($*1_ltype)$input;
  24. $1 = &temp;
  25. %}
  26. %typemap(out) char *& %{ if ($1) $result = SWIG_d_string_callback((const char *)*$1); %}
  27. /*
  28. * char array typemaps.
  29. */
  30. %typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
  31. %typemap(out) char[ANY], char[] %{ $result = SWIG_d_string_callback((const char *)$1); %}
  32. %typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
  33. %typemap(directorin) char[ANY], char[] %{ $input = SWIG_d_string_callback((const char *)$1); %}
  34. %typemap(ddirectorin) char[ANY], char[] "$winput"
  35. %typemap(ddirectorout) char[ANY], char[] "$dcall"
  36. %typemap(din) char *, char *&, char[ANY], char[] "($dinput ? TO_STRINGZ($dinput) : null)"
  37. %typemap(dout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
  38. DP_STRING_TYPE ret = FROM_STRINGZ ## ($imcall);$excode
  39. return ret;
  40. }
  41. %typecheck(SWIG_TYPECHECK_STRING)
  42. char *,
  43. char *&,
  44. char[ANY],
  45. char[]
  46. ""
  47. %enddef
  48. // We need to have the \0-terminated string conversion functions available in
  49. // the D proxy modules.
  50. #if (SWIG_D_VERSION == 1)
  51. // Could be easily extended to support Phobos as well.
  52. SWIGD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
  53. %pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
  54. #else
  55. SWIGD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
  56. %pragma(d) globalproxyimports = %{
  57. static import std.conv;
  58. static import std.string;
  59. %}
  60. #endif
  61. #undef SWIGD_STRING_TYPEMAPS