1 /* ----------------------------------------------------------------------------- 2 * dstrings.swg 3 * 4 * Typemaps for wrapping pointers to/arrays of C chars as D strings. 5 * ----------------------------------------------------------------------------- */ 6 7 %define SWIGD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ) 8 %typemap(ctype) char *, char *&, char[ANY], char[] "char *" 9 %typemap(imtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE 10 %typemap(dtype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE 11 12 13 /* 14 * char* typemaps. 15 */ 16 17 %typemap(in) char * %{ $1 = ($1_ltype)$input; %} 18 %typemap(out) char * %{ $result = SWIG_d_string_callback((const char *)$1); %} 19 %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %} 20 %typemap(directorin) char * %{ $input = SWIG_d_string_callback((const char *)$1); %} 21 %typemap(ddirectorin) char * "FROM_STRINGZ($winput)" 22 %typemap(ddirectorout) char * "TO_STRINGZ($dcall)" 23 24 25 /* 26 * char*& typemaps. 27 */ 28 29 %typemap(in) char *& ($*1_ltype temp = 0) %{ 30 temp = ($*1_ltype)$input; 31 $1 = &temp; 32 %} 33 %typemap(out) char *& %{ if ($1) $result = SWIG_d_string_callback((const char *)*$1); %} 34 35 36 /* 37 * char array typemaps. 38 */ 39 40 %typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %} 41 %typemap(out) char[ANY], char[] %{ $result = SWIG_d_string_callback((const char *)$1); %} 42 43 %typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %} 44 %typemap(directorin) char[ANY], char[] %{ $input = SWIG_d_string_callback((const char *)$1); %} 45 46 %typemap(ddirectorin) char[ANY], char[] "$winput" 47 %typemap(ddirectorout) char[ANY], char[] "$dcall" 48 49 50 %typemap(din) char *, char *&, char[ANY], char[] "($dinput ? TO_STRINGZ($dinput) : null)" 51 %typemap(dout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] { 52 DP_STRING_TYPE ret = FROM_STRINGZ ## ($imcall);$excode 53 return ret; 54 } 55 56 %typecheck(SWIG_TYPECHECK_STRING) 57 char *, 58 char *&, 59 char[ANY], 60 char[] 61 "" 62 %enddef 63 64 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_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz) 70 71 %pragma(d) globalproxyimports = "static import tango.stdc.stringz;"; 72 #else 73 SWIGD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz) 74 75 %pragma(d) globalproxyimports = %{ 76 static import std.conv; 77 static import std.string; 78 %} 79 #endif 80 #undef SWIGD_STRING_TYPEMAPS 81