1 /* ----------------------------------------------------------------------------- 2 * dprimitves.swg 3 * 4 * Typemaps for primitive types. 5 * ----------------------------------------------------------------------------- */ 6 7 // C long/ulong width depends on the target arch, use stdlib aliases for them. 8 #if (SWIG_D_VERSION == 1) 9 %pragma(d) imdmoduleimports = "static import tango.stdc.config;" 10 %pragma(d) globalproxyimports = "static import tango.stdc.config;" 11 #define SWIG_LONG_DTYPE tango.stdc.config.c_long 12 #define SWIG_ULONG_DTYPE tango.stdc.config.c_ulong 13 #else 14 %pragma(d) imdmoduleimports = "static import core.stdc.config;" 15 %pragma(d) globalproxyimports = "static import core.stdc.config;" 16 #define SWIG_LONG_DTYPE core.stdc.config.c_long 17 #define SWIG_ULONG_DTYPE core.stdc.config.c_ulong 18 #endif 19 20 /* 21 * The SWIG_D_PRIMITIVE macro is used to define the typemaps for the primitive 22 * types, because are more or less the same for all of them. The few special 23 * cases are handeled below. 24 */ 25 %define SWIG_D_PRIMITIVE(TYPE, DTYPE) 26 %typemap(ctype) TYPE, const TYPE & "TYPE" 27 %typemap(imtype) TYPE, const TYPE & "DTYPE" 28 %typemap(dtype, cprimitive="1") TYPE, const TYPE & "DTYPE" 29 30 %typemap(in) TYPE "$1 = ($1_ltype)$input;" 31 %typemap(out) TYPE "$result = $1;" 32 %typemap(directorin) TYPE "$input = $1;" 33 %typemap(directorout) TYPE "$result = ($1_ltype)$input;" 34 %typemap(ddirectorin) TYPE "$winput" 35 %typemap(ddirectorout) TYPE "$dcall" 36 37 %typemap(in) const TYPE & ($*1_ltype temp) 38 %{ temp = ($*1_ltype)$input; 39 $1 = &temp; %} 40 %typemap(out) const TYPE & "$result = *$1;" 41 %typemap(directorin) const TYPE & "$input = $1;" 42 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const TYPE & 43 %{ static $*1_ltype temp; 44 temp = ($*1_ltype)$input; 45 $result = &temp; %} 46 %typemap(ddirectorin) const TYPE & "$winput" 47 %typemap(ddirectorout) const TYPE & "$dcall" 48 49 %typemap(din) TYPE, const TYPE & "$dinput" 50 %typemap(dout, excode=SWIGEXCODE) TYPE, const TYPE & { 51 auto ret = $imcall;$excode 52 return ret; 53 } 54 %enddef 55 56 57 SWIG_D_PRIMITIVE(bool, bool) 58 SWIG_D_PRIMITIVE(char, char) 59 SWIG_D_PRIMITIVE(signed char, byte) 60 SWIG_D_PRIMITIVE(unsigned char, ubyte) 61 SWIG_D_PRIMITIVE(short, short) 62 SWIG_D_PRIMITIVE(unsigned short, ushort) 63 SWIG_D_PRIMITIVE(int, int) 64 SWIG_D_PRIMITIVE(unsigned int, uint) 65 SWIG_D_PRIMITIVE(long, SWIG_LONG_DTYPE) 66 SWIG_D_PRIMITIVE(unsigned long, SWIG_ULONG_DTYPE) 67 SWIG_D_PRIMITIVE(size_t, size_t) 68 SWIG_D_PRIMITIVE(long long, long) 69 SWIG_D_PRIMITIVE(unsigned long long, ulong) 70 SWIG_D_PRIMITIVE(float, float) 71 SWIG_D_PRIMITIVE(double, double) 72 73 74 // The C++ boolean type needs some special casing since it is not part of the 75 // C standard and is thus represented as unsigned int in the C wrapper layer. 76 %typemap(ctype) bool, const bool & "unsigned int" 77 %typemap(imtype) bool, const bool & "uint" 78 79 %typemap(in) bool "$1 = $input ? true : false;" 80 %typemap(in) const bool & ($*1_ltype temp) 81 %{ temp = $input ? true : false; 82 $1 = &temp; %} 83 84 %typemap(directorout) bool 85 "$result = $input ? true : false;" 86 %typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool & 87 %{ static $*1_ltype temp; 88 temp = $input ? true : false; 89 $result = &temp; %} 90 91 %typemap(ddirectorin) bool "($winput ? true : false)" 92 93 %typemap(dout, excode=SWIGEXCODE) bool, const bool & { 94 bool ret = $imcall ? true : false;$excode 95 return ret; 96 } 97 98 99 // Judging from the history of the C# module, the explicit casts are needed for 100 // certain versions of VC++. 101 %typemap(out) unsigned long "$result = (unsigned long)$1;" 102 %typemap(out) const unsigned long & "$result = (unsigned long)*$1;" 103 104 105 /* 106 * Typecheck typemaps. 107 */ 108 109 %typecheck(SWIG_TYPECHECK_BOOL) 110 bool, 111 const bool & 112 "" 113 114 %typecheck(SWIG_TYPECHECK_CHAR) 115 char, 116 const char & 117 "" 118 119 %typecheck(SWIG_TYPECHECK_INT8) 120 signed char, 121 const signed char & 122 "" 123 124 %typecheck(SWIG_TYPECHECK_UINT8) 125 unsigned char, 126 const unsigned char & 127 "" 128 129 %typecheck(SWIG_TYPECHECK_INT16) 130 short, 131 const short & 132 "" 133 134 %typecheck(SWIG_TYPECHECK_UINT16) 135 unsigned short, 136 const unsigned short & 137 "" 138 139 %typecheck(SWIG_TYPECHECK_INT32) 140 int, 141 long, 142 const int &, 143 const long & 144 "" 145 146 %typecheck(SWIG_TYPECHECK_UINT32) 147 unsigned int, 148 unsigned long, 149 const unsigned int &, 150 const unsigned long & 151 "" 152 153 %typecheck(SWIG_TYPECHECK_INT64) 154 long long, 155 const long long & 156 "" 157 158 %typecheck(SWIG_TYPECHECK_UINT64) 159 unsigned long long, 160 const unsigned long long & 161 "" 162 163 %typecheck(SWIG_TYPECHECK_FLOAT) 164 float, 165 const float & 166 "" 167 168 %typecheck(SWIG_TYPECHECK_DOUBLE) 169 double, 170 const double & 171 "" 172