1/* ----------------------------------------------------------------------------- 2 * dswigtype.swg 3 * 4 * Typemaps for non-primitive types (C/C++ classes and structs). 5 * ----------------------------------------------------------------------------- */ 6 7%typemap(ctype) SWIGTYPE "void *" 8%typemap(imtype) SWIGTYPE "void*" 9%typemap(dtype) SWIGTYPE "$&dclassname" 10 11%typemap(ctype) SWIGTYPE [] "void *" 12%typemap(imtype) SWIGTYPE [] "void*" 13%typemap(dtype) SWIGTYPE [] "$dclassname" 14 15%typemap(ctype) SWIGTYPE * "void *" 16%typemap(imtype) SWIGTYPE * "void*" 17%typemap(dtype, nativepointer="$dtype") SWIGTYPE * "$dclassname" 18 19%typemap(ctype) SWIGTYPE & "void *" 20%typemap(imtype) SWIGTYPE & "void*" 21%typemap(dtype, nativepointer="$dtype") SWIGTYPE & "$dclassname" 22 23%typemap(ctype) SWIGTYPE *const& "void *" 24%typemap(imtype) SWIGTYPE *const& "void*" 25%typemap(dtype) SWIGTYPE *const& "$*dclassname" 26 27%typecheck(SWIG_TYPECHECK_POINTER) 28 SWIGTYPE, 29 SWIGTYPE *, 30 SWIGTYPE &, 31 SWIGTYPE [], 32 SWIGTYPE *const& 33 "" 34 35 36/* 37 * By-value conversion typemaps (parameter is converted to a pointer). 38 */ 39 40%typemap(in, canthrow=1) SWIGTYPE ($&1_type argp) 41%{ argp = ($&1_ltype)$input; 42 if (!argp) { 43 SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type"); 44 return $null; 45 } 46 $1 = *argp; %} 47 48%typemap(out) SWIGTYPE 49#ifdef __cplusplus 50%{ $result = new $1_ltype((const $1_ltype &)$1); %} 51#else 52{ 53 $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); 54 memmove($1ptr, &$1, sizeof($1_type)); 55 $result = $1ptr; 56} 57#endif 58 59%typemap(directorin) SWIGTYPE 60 "$input = (void *)new $1_ltype((const $1_ltype &)$1);" 61%typemap(directorout) SWIGTYPE 62%{ if (!$input) { 63 SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type"); 64 return $null; 65 } 66 $result = *($&1_ltype)$input; %} 67 68%typemap(ddirectorin) SWIGTYPE "new $&dclassname($winput, true)" 69%typemap(ddirectorout) SWIGTYPE "$&dclassname.swigGetCPtr($dcall)" 70 71%typemap(din) SWIGTYPE "$&dclassname.swigGetCPtr($dinput)" 72%typemap(dout, excode=SWIGEXCODE) SWIGTYPE { 73 $&dclassname ret = new $&dclassname($imcall, true);$excode 74 return ret; 75} 76 77 78/* 79 * Pointer conversion typemaps. 80 */ 81 82%typemap(in) SWIGTYPE * "$1 = ($1_ltype)$input;" 83%typemap(out) SWIGTYPE * "$result = (void *)$1;" 84 85%typemap(directorin) SWIGTYPE * 86 "$input = (void *) $1;" 87%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE * 88 "$result = ($1_ltype)$input;" 89 90%typemap(ddirectorin, 91 nativepointer="cast($dtype)$winput" 92) SWIGTYPE * "($winput is null) ? null : new $dclassname($winput, false)" 93 94%typemap(ddirectorout, 95 nativepointer="cast(void*)$dcall" 96) SWIGTYPE * "$dclassname.swigGetCPtr($dcall)" 97 98%typemap(din, 99 nativepointer="cast(void*)$dinput" 100) SWIGTYPE * "$dclassname.swigGetCPtr($dinput)" 101 102%typemap(dout, excode=SWIGEXCODE, 103 nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}" 104) SWIGTYPE * { 105 void* cPtr = $imcall; 106 $dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode 107 return ret; 108} 109 110// Use the same typemaps for const pointers. 111%apply SWIGTYPE * { SWIGTYPE *const } 112 113 114/* 115 * Reference conversion typemaps. 116 */ 117 118%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input; 119 if (!$1) { 120 SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null"); 121 return $null; 122 } %} 123%typemap(out) SWIGTYPE & "$result = (void *)$1;" 124 125%typemap(directorin) SWIGTYPE & 126 "$input = ($1_ltype) &$1;" 127%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE & 128%{ if (!$input) { 129 SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type"); 130 return $null; 131 } 132 $result = ($1_ltype)$input; %} 133 134%typemap(ddirectorin, 135 nativepointer="cast($dtype)$winput" 136) SWIGTYPE & "new $dclassname($winput, false)" 137%typemap(ddirectorout, 138 nativepointer="cast(void*)$dcall" 139) SWIGTYPE & "$dclassname.swigGetCPtr($dcall)" 140 141%typemap(din, 142 nativepointer="cast(void*)$dinput" 143) SWIGTYPE & "$dclassname.swigGetCPtr($dinput)" 144%typemap(dout, excode=SWIGEXCODE, 145 nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE & { 146 $dclassname ret = new $dclassname($imcall, $owner);$excode 147 return ret; 148} 149 150 151/* 152 * Array conversion typemaps. 153 */ 154 155%typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %} 156%typemap(out) SWIGTYPE [] %{ $result = $1; %} 157 158%typemap(din) SWIGTYPE [] "$dclassname.swigGetCPtr($dinput)" 159%typemap(dout, excode=SWIGEXCODE) SWIGTYPE [] { 160 void* cPtr = $imcall; 161 $dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode 162 return ret; 163} 164 165// Treat references to arrays like references to a single element. 166%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } 167 168 169/* 170 * Pointer reference conversion typemaps. 171 */ 172 173%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) 174%{ temp = ($*1_ltype)$input; 175 $1 = ($1_ltype)&temp; %} 176%typemap(out) SWIGTYPE *const& 177%{ $result = (void *)*$1; %} 178 179%typemap(din) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dinput)" 180%typemap(dout, excode=SWIGEXCODE) SWIGTYPE *const& { 181 void* cPtr = $imcall; 182 $*dclassname ret = (cPtr is null) ? null : new $*dclassname(cPtr, $owner);$excode 183 return ret; 184} 185%typemap(directorin) SWIGTYPE *const& 186 "$input = (void *) $1;" 187%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *const& 188%{ static $*1_ltype swig_temp; 189 swig_temp = ($*1_ltype)$input; 190 $result = &swig_temp; %} 191%typemap(ddirectorin, 192 nativepointer="cast($dtype)$winput" 193) SWIGTYPE *const& "($winput is null) ? null : new $*dclassname($winput, false)" 194%typemap(ddirectorout, 195 nativepointer="cast(void*)$dcall" 196) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dcall)" 197 198