1 /* ----------------------------------------------------------------------------- 2 * modula3.swg 3 * 4 * Modula3 typemaps 5 * ----------------------------------------------------------------------------- */ 6 7 %include <modula3head.swg> 8 9 /* The ctype, m3rawtype and m3wraptype typemaps work together and so there should be one of each. 10 * The ctype typemap contains the C type used in the signature of C wrappers for C++ functions. 11 * The m3rawtype typemap contains the M3 type used in the raw interface. 12 * The m3rawintype typemap contains the M3 type used as function argument. 13 * The m3rawrettype typemap contains the M3 type used as return value. 14 * The m3wraptype typemap contains the M3 type used in the M3 type wrapper classes and module class. */ 15 16 /* Primitive types */ 17 %typemap(ctype) bool, const bool & "bool" 18 %typemap(ctype) char, const char & "char" 19 %typemap(ctype) signed char, const signed char & "signed char" 20 %typemap(ctype) unsigned char, const unsigned char & "unsigned short" 21 %typemap(ctype) short, const short & "short" 22 %typemap(ctype) unsigned short, const unsigned short & "unsigned short" 23 %typemap(ctype) int, const int & "int" 24 %typemap(ctype) unsigned int, const unsigned int & "unsigned int" 25 %typemap(ctype) long, const long & "long" 26 %typemap(ctype) unsigned long, const unsigned long & "unsigned long" 27 %typemap(ctype) long long, const long long & "long long" 28 %typemap(ctype) unsigned long long, const unsigned long long & "unsigned long long" 29 %typemap(ctype) float, const float & "float" 30 %typemap(ctype) double, const double & "double" 31 %typemap(ctype) char * "char *" 32 %typemap(ctype) void "void" 33 34 %typemap(m3rawtype) bool, const bool & "BOOLEAN" 35 %typemap(m3rawtype) char, const char & "C.char" 36 %typemap(m3rawtype) signed char, const signed char & "C.signed_char" 37 %typemap(m3rawtype) unsigned char, const unsigned char & "C.unsigned_char" 38 %typemap(m3rawtype) short, const short & "C.short" 39 %typemap(m3rawtype) unsigned short, const unsigned short & "C.unsigned_short" 40 %typemap(m3rawtype) int, const int & "C.int" 41 %typemap(m3rawtype) unsigned int, const unsigned int & "C.unsigned_int" 42 %typemap(m3rawtype) long, const long & "C.long" 43 %typemap(m3rawtype) unsigned long, const unsigned long & "C.unsigned_long" 44 %typemap(m3rawtype) long long, const long long & "C.long_long" 45 %typemap(m3rawtype) unsigned long long, const unsigned long long & "C.unsigned_long_long" 46 %typemap(m3rawtype) float, const float & "C.float" 47 %typemap(m3rawtype) double, const double & "C.double" 48 %typemap(m3rawtype) long double, const long double & "C.long_double" 49 %typemap(m3rawtype) char * "C.char_star" 50 %typemap(m3rawtype) void "" 51 %typemap(m3rawtype) FILE "Cstdio.FILE"; 52 %typemap(m3rawtype) FILE * "Cstdio.FILE_star"; 53 54 55 %typemap(m3rawintype) bool *, bool &, bool "BOOLEAN" 56 %typemap(m3rawintype) char *, char &, char "C.char" 57 %typemap(m3rawintype) signed char *, signed char &, signed char "C.signed_char" 58 %typemap(m3rawintype) unsigned char *, unsigned char &, unsigned char "C.unsigned_char" 59 %typemap(m3rawintype) short *, short &, short "C.short" 60 %typemap(m3rawintype) unsigned short *, unsigned short &, unsigned short "C.unsigned_short" 61 %typemap(m3rawintype) int *, int &, int "C.int" 62 %typemap(m3rawintype) unsigned int *, unsigned int &, unsigned int "C.unsigned_int" 63 %typemap(m3rawintype) long *, long &, long "C.long" 64 %typemap(m3rawintype) unsigned long *, unsigned long &, unsigned long "C.unsigned_long" 65 %typemap(m3rawintype) long long *, long long &, long long "C.long_long" 66 %typemap(m3rawintype) unsigned long long *, unsigned long long &, unsigned long long "C.unsigned_long_long" 67 %typemap(m3rawintype) float *, float &, float "C.float" 68 %typemap(m3rawintype) double *, double &, double "C.double" 69 %typemap(m3rawintype) long double *, long double &, long double "C.long_double" 70 %typemap(m3rawintype) char * "C.char_star" 71 %typemap(m3rawintype) void "" 72 %typemap(m3rawintype) void * "ADDRESS" 73 %typemap(m3rawintype) FILE "Cstdio.FILE"; 74 %typemap(m3rawintype) FILE * "Cstdio.FILE_star"; 75 76 %typemap(m3rawinmode) char *, void *, FILE * "" 77 78 79 %typemap(m3rawrettype) bool, const bool & "BOOLEAN" 80 %typemap(m3rawrettype) char, const char & "C.char" 81 %typemap(m3rawrettype) signed char, const signed char & "C.signed_char" 82 %typemap(m3rawrettype) unsigned char, const unsigned char & "C.unsigned_char" 83 %typemap(m3rawrettype) short, const short & "C.short" 84 %typemap(m3rawrettype) unsigned short, const unsigned short & "C.unsigned_short" 85 %typemap(m3rawrettype) int, const int & "C.int" 86 %typemap(m3rawrettype) unsigned int, const unsigned int & "C.unsigned_int" 87 %typemap(m3rawrettype) long, const long & "C.long" 88 %typemap(m3rawrettype) unsigned long, const unsigned long & "C.unsigned_long" 89 %typemap(m3rawrettype) long long, const long long & "C.long_long" 90 %typemap(m3rawrettype) unsigned long long, const unsigned long long & "C.unsigned_long_long" 91 %typemap(m3rawrettype) float, const float & "C.float" 92 %typemap(m3rawrettype) double, const double & "C.double" 93 %typemap(m3rawrettype) long double, const long double & "C.long_double" 94 %typemap(m3rawrettype) char * "C.char_star" 95 %typemap(m3rawrettype) void "" 96 %typemap(m3rawrettype) void * "ADDRESS" 97 %typemap(m3rawrettype) FILE "Cstdio.FILE"; 98 %typemap(m3rawrettype) FILE * "Cstdio.FILE_star"; 99 100 101 %typemap("m3rawtype:import") 102 char, const char &, 103 signed char, const signed char &, 104 unsigned char, const unsigned char &, 105 short, const short &, 106 unsigned short, const unsigned short &, 107 int, const int &, 108 unsigned int, const unsigned int &, 109 long, const long &, 110 unsigned long, const unsigned long &, 111 long long, const long long &, 112 unsigned long long, const unsigned long long &, 113 float, const float &, 114 double, const double &, 115 long double, const long double &, 116 char * 117 "Ctypes AS C" 118 119 %typemap("m3rawintype:import") 120 char, const char &, 121 signed char, const signed char &, 122 unsigned char, const unsigned char &, 123 short, const short &, 124 unsigned short, const unsigned short &, 125 int, const int &, 126 unsigned int, const unsigned int &, 127 long, const long &, 128 unsigned long, const unsigned long &, 129 long long, const long long &, 130 unsigned long long, const unsigned long long &, 131 float, const float &, 132 double, const double &, 133 long double, const long double &, 134 char * 135 "Ctypes AS C" 136 137 %typemap("m3rawrettype:import") 138 char, const char &, 139 signed char, const signed char &, 140 unsigned char, const unsigned char &, 141 short, const short &, 142 unsigned short, const unsigned short &, 143 int, const int &, 144 unsigned int, const unsigned int &, 145 long, const long &, 146 unsigned long, const unsigned long &, 147 long long, const long long &, 148 unsigned long long, const unsigned long long &, 149 float, const float &, 150 double, const double &, 151 long double, const long double &, 152 char * 153 "Ctypes AS C" 154 155 %typemap("m3rawtype:import") 156 FILE, FILE * 157 "Cstdio"; 158 159 %typemap("m3rawintype:import") 160 FILE, FILE * 161 "Cstdio"; 162 163 %typemap("m3rawrettype:import") 164 FILE, FILE * 165 "Cstdio"; 166 167 %typemap(m3wraptype) bool, const bool & "BOOLEAN" 168 %typemap(m3wraptype) char, const char & "CHAR" 169 %typemap(m3wraptype) signed char, const signed char & "CHAR" 170 %typemap(m3wraptype) unsigned char, const unsigned char & "CHAR" 171 %typemap(m3wraptype) short, const short & "Integer16.T" 172 %typemap(m3wraptype) unsigned short, const unsigned short & "Cardinal16.T" 173 %typemap(m3wraptype) int, const int & "INTEGER" 174 %typemap(m3wraptype) unsigned int, const unsigned int & "CARDINAL" 175 %typemap(m3wraptype) long, const long & "Integer32.T" 176 %typemap(m3wraptype) unsigned long, const unsigned long & "Cardinal32.T" 177 %typemap(m3wraptype) long long, const long long & "Integer64.T" 178 %typemap(m3wraptype) unsigned long long, const unsigned long long & "Cardinal64.T" 179 %typemap(m3wraptype) float, const float & "REAL" 180 %typemap(m3wraptype) double, const double & "LONGREAL" 181 %typemap(m3wraptype) long double, const long double & "EXTENDED" 182 %typemap(m3wraptype) char * "TEXT" 183 %typemap(m3wraptype) void "" 184 %typemap(m3wraptype) FILE "Cstdio.FILE"; 185 %typemap(m3wraptype) FILE * "Cstdio.FILE_star"; 186 187 %typemap(m3wrapintype) bool, const bool *, const bool & "BOOLEAN" 188 %typemap(m3wrapintype) char, const char *, const char & "CHAR" 189 %typemap(m3wrapintype) signed char, const signed char *, const signed char & "CHAR" 190 %typemap(m3wrapintype) unsigned char, const unsigned char *, const unsigned char & "CHAR" 191 %typemap(m3wrapintype) short, const short *, const short & "INTEGER" 192 %typemap(m3wrapintype) unsigned short, const unsigned short *, const unsigned short & "CARDINAL" 193 %typemap(m3wrapintype) int, const int *, const int & "INTEGER" 194 %typemap(m3wrapintype) unsigned int, const unsigned int *, const unsigned int & "CARDINAL" 195 %typemap(m3wrapintype) long, const long *, const long & "INTEGER" 196 %typemap(m3wrapintype) unsigned long, const unsigned long *, const unsigned long & "CARDINAL" 197 %typemap(m3wrapintype) long long, const long long *, const long long & "INTEGER" 198 %typemap(m3wrapintype) unsigned long long, const unsigned long long *, const unsigned long long & "CARDINAL" 199 %typemap(m3wrapintype) float, const float *, const float & "REAL" 200 %typemap(m3wrapintype) double, const double *, const double & "LONGREAL" 201 %typemap(m3wrapintype) long double, const long double *, const long double & "EXTENDED" 202 %typemap(m3wrapintype) const char *, const char [] "TEXT" 203 %typemap(m3wrapintype,numinputs=0) void "" 204 %typemap(m3wrapintype) FILE "Cstdio.FILE"; 205 %typemap(m3wrapintype) FILE * "Cstdio.FILE_star"; 206 207 208 %typemap(m3wrapouttype) bool, bool *, bool & "BOOLEAN" 209 %typemap(m3wrapouttype) char, char *, char & "CHAR" 210 %typemap(m3wrapouttype) signed char, signed char *, signed char & "CHAR" 211 %typemap(m3wrapouttype) unsigned char, unsigned char *, unsigned char & "CHAR" 212 %typemap(m3wrapouttype) short, short *, short & "INTEGER" 213 %typemap(m3wrapouttype) unsigned short, unsigned short *, unsigned short & "CARDINAL" 214 %typemap(m3wrapouttype) int, int *, int & "INTEGER" 215 %typemap(m3wrapouttype) unsigned int, unsigned int *, unsigned int & "CARDINAL" 216 %typemap(m3wrapouttype) long, long *, long & "INTEGER" 217 %typemap(m3wrapouttype) unsigned long, unsigned long *, unsigned long & "CARDINAL" 218 %typemap(m3wrapouttype) long long, long long *, long long & "INTEGER" 219 %typemap(m3wrapouttype) unsigned long long, unsigned long long *, unsigned long long & "CARDINAL" 220 %typemap(m3wrapouttype) float, float *, float & "REAL" 221 %typemap(m3wrapouttype) double, double *, double & "LONGREAL" 222 %typemap(m3wrapouttype) long double, long double *, long double & "EXTENDED" 223 %typemap(m3wrapouttype) char *, char [] "TEXT" 224 %typemap(m3wrapouttype,numinputs=0) void "" 225 226 %typemap(m3wraprettype) bool, const bool & "BOOLEAN" 227 %typemap(m3wraprettype) char, const char & "CHAR" 228 %typemap(m3wraprettype) signed char, const signed char & "CHAR" 229 %typemap(m3wraprettype) unsigned char, const unsigned char & "CHAR" 230 %typemap(m3wraprettype) short, const short & "INTEGER" 231 %typemap(m3wraprettype) unsigned short, const unsigned short & "CARDINAL" 232 %typemap(m3wraprettype) int, const int & "INTEGER" 233 %typemap(m3wraprettype) unsigned int, const unsigned int & "CARDINAL" 234 %typemap(m3wraprettype) long, const long & "INTEGER" 235 %typemap(m3wraprettype) unsigned long, const unsigned long & "CARDINAL" 236 %typemap(m3wraprettype) long long, const long long & "INTEGER" 237 %typemap(m3wraprettype) unsigned long long, const unsigned long long & "CARDINAL" 238 %typemap(m3wraprettype) float, const float & "REAL" 239 %typemap(m3wraprettype) double, const double & "LONGREAL" 240 %typemap(m3wraprettype) long double, const long double & "EXTENDED" 241 %typemap(m3wraprettype) char * "TEXT" 242 %typemap(m3wraprettype) void "" 243 %typemap(m3wraprettype) FILE "Cstdio.FILE"; 244 %typemap(m3wraprettype) FILE * "Cstdio.FILE_star"; 245 246 247 %typemap(ctype) char[ANY] "char *" 248 %typemap(m3rawtype) char[ANY] "C.char_star" 249 %typemap(m3rawintype) char[ANY] "C.char_star" 250 %typemap(m3rawrettype) char[ANY] "C.char_star" 251 %typemap(m3wraptype) char[ANY] "TEXT" 252 %typemap(m3wrapintype) char[ANY] "TEXT" 253 %typemap(m3wrapouttype) char[ANY] "TEXT" 254 %typemap(m3wraprettype) char[ANY] "TEXT" 255 256 %typemap(m3wrapinmode) const char * %{%} 257 %typemap(m3wrapargvar) const char * %{$1 : C.char_star;%} 258 %typemap(m3wrapinconv) const char * %{$1 := M3toC.SharedTtoS($1_name);%} 259 %typemap(m3wrapfreearg) const char * %{M3toC.FreeSharedS($1_name,$1);%} 260 %typemap(m3wrapargraw) const char * %{$1%} 261 %typemap("m3wrapargvar:import") const char * "Ctypes AS C" 262 %typemap("m3wrapinconv:import") const char * "M3toC" 263 %typemap("m3wrapfreearg:import") const char * "M3toC" 264 265 %typemap(m3wrapretvar) char * %{result : C.char_star;%} 266 %typemap(m3wrapretraw) char * %{result%} 267 %typemap(m3wrapretconv) char * %{M3toC.CopyStoT(result)%} 268 %typemap("m3wrapretvar:import") char * "Ctypes AS C" 269 %typemap("m3wrapretconv:import") char * "M3toC" 270 271 %typemap(m3wrapinmode) FILE * %{%} 272 273 274 %typemap("m3wraptype:import") 275 FILE, FILE * 276 "Cstdio"; 277 278 %typemap("m3wrapintype:import") 279 FILE, FILE * 280 "Cstdio"; 281 282 %typemap("m3wraprettype:import") 283 FILE, FILE * 284 "Cstdio"; 285 286 287 /* Composed types */ 288 %typemap(ctype) SWIGTYPE "$1_type" 289 %typemap(m3rawtype) SWIGTYPE "$1_basetype" 290 %typemap(m3rawrettype) SWIGTYPE "UNTRACED REF $1_basetype" 291 %typemap(m3wraptype) SWIGTYPE "$1_basetype" 292 %typemap(m3wrapintype) SWIGTYPE "$1_basetype" 293 %typemap(m3wrapouttype) SWIGTYPE "$1_basetype" 294 %typemap(m3wraprettype) SWIGTYPE "$1_basetype" 295 296 %typemap(ctype) SWIGTYPE [] "$1_type" 297 %typemap(m3rawtype) const SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" 298 %typemap(m3rawtype) SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" 299 %typemap(m3rawintype) const SWIGTYPE [] "(*ARRAY OF*) $1_basetype" 300 %typemap(m3rawinmode) const SWIGTYPE [] "READONLY" 301 %typemap(m3rawintype) SWIGTYPE [] "(*ARRAY OF*) $1_basetype" 302 %typemap(m3rawinmode) SWIGTYPE [] "VAR" 303 %typemap(m3rawrettype) const SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" 304 %typemap(m3rawrettype) SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" 305 %typemap(m3wraptype) SWIGTYPE [] "$1_basetype" 306 %typemap(m3wrapintype) const SWIGTYPE [] "ARRAY OF $1_basetype" 307 %typemap(m3wrapinmode) const SWIGTYPE [] "READONLY" 308 %typemap(m3wrapintype) SWIGTYPE [] "ARRAY OF $1_basetype" 309 %typemap(m3wrapinmode) SWIGTYPE [] "VAR" 310 %typemap(m3wrapouttype) SWIGTYPE [] "ARRAY OF $1_basetype" 311 %typemap(m3wraprettype) SWIGTYPE [] "REF ARRAY OF $1_basetype" 312 313 %typemap(ctype) SWIGTYPE * "$1_type" 314 %typemap(m3rawtype) const SWIGTYPE * "UNTRACED REF $1_basetype" 315 %typemap(m3rawtype) SWIGTYPE * "UNTRACED REF $1_basetype" 316 %typemap(m3rawintype) const SWIGTYPE * "$1_basetype" 317 %typemap(m3rawinmode) const SWIGTYPE * "READONLY" 318 %typemap(m3rawintype) SWIGTYPE * "$1_basetype" 319 %typemap(m3rawinmode) SWIGTYPE * "VAR" 320 %typemap(m3rawrettype) const SWIGTYPE * "UNTRACED REF $1_basetype" 321 %typemap(m3rawrettype) SWIGTYPE * "UNTRACED REF $1_basetype" 322 %typemap(m3wraptype) SWIGTYPE * "$1_basetype" 323 %typemap(m3wrapintype) const SWIGTYPE * "$1_basetype" 324 %typemap(m3wrapinmode) const SWIGTYPE * "READONLY" 325 %typemap(m3wrapintype) SWIGTYPE * "$1_basetype" 326 %typemap(m3wrapinmode) SWIGTYPE * "VAR" 327 %typemap(m3wrapouttype) SWIGTYPE * "$1_basetype" 328 %typemap(m3wraprettype) SWIGTYPE * "UNTRACED REF $1_basetype" 329 330 %typemap(ctype) SWIGTYPE & "$1_type" 331 %typemap(m3rawtype) const SWIGTYPE & "UNTRACED REF $1_basetype" 332 %typemap(m3rawtype) SWIGTYPE & "UNTRACED REF $1_basetype" 333 %typemap(m3rawintype) const SWIGTYPE & "$1_basetype" 334 %typemap(m3rawinmode) const SWIGTYPE & "READONLY" 335 %typemap(m3rawintype) SWIGTYPE & "$1_basetype" 336 %typemap(m3rawinmode) SWIGTYPE & "VAR" 337 %typemap(m3rawrettype) const SWIGTYPE & "UNTRACED REF $1_basetype" 338 %typemap(m3rawrettype) SWIGTYPE & "UNTRACED REF $1_basetype" 339 %typemap(m3wraptype) SWIGTYPE & "$1_basetype" 340 %typemap(m3wrapintype) const SWIGTYPE & "$1_basetype" 341 %typemap(m3wrapinmode) const SWIGTYPE & "READONLY" 342 %typemap(m3wrapintype) SWIGTYPE & "$1_basetype" 343 %typemap(m3wrapinmode) SWIGTYPE & "VAR" 344 %typemap(m3wrapouttype) SWIGTYPE & "$1_basetype" 345 %typemap(m3wraprettype) SWIGTYPE & "UNTRACED REF $1_basetype" 346 347 %typemap(ctype) enum SWIGTYPE "$1_type" 348 %typemap(m3rawtype) enum SWIGTYPE "C.int" 349 %typemap(m3rawintype) enum SWIGTYPE "C.int (* $1_type *)" 350 %typemap(m3rawrettype) enum SWIGTYPE "C.int" 351 %typemap(m3wraptype) enum SWIGTYPE "$*1_type" 352 %typemap(m3wrapintype) enum SWIGTYPE "$1_type" 353 %typemap(m3wrapouttype) enum SWIGTYPE "$1_type" 354 %typemap(m3wraprettype) enum SWIGTYPE "$*1_type" 355 356 /* pointer to a class member */ 357 %typemap(ctype) SWIGTYPE (CLASS::*) "$1_type" 358 %typemap(m3rawtype) SWIGTYPE (CLASS::*) "REFANY" 359 %typemap(m3wraptype) SWIGTYPE (CLASS::*) "$1_basetype" 360 361 /* The following are the in, out, freearg, argout typemaps. 362 These are the PInvoke code generating typemaps for converting from C# to C and visa versa. */ 363 364 /* primitive types */ 365 %typemap(in) bool 366 %{ $1 = $input ? true : false; %} 367 368 %typemap(in) char, 369 signed char, 370 unsigned char, 371 short, 372 unsigned short, 373 int, 374 unsigned int, 375 long, 376 unsigned long, 377 long long, 378 unsigned long long, 379 float, 380 double, 381 enum SWIGTYPE 382 %{ $1 = ($1_ltype)$input; %} 383 384 %typemap(out) bool %{ $result = $1; %} 385 %typemap(out) char %{ $result = $1; %} 386 %typemap(out) signed char %{ $result = $1; %} 387 %typemap(out) unsigned char %{ $result = $1; %} 388 %typemap(out) short %{ $result = $1; %} 389 %typemap(out) unsigned short %{ $result = $1; %} 390 %typemap(out) int %{ $result = $1; %} 391 %typemap(out) unsigned int %{ $result = $1; %} 392 %typemap(out) long %{ $result = $1; %} 393 %typemap(out) unsigned long %{ $result = $1; %} 394 %typemap(out) long long %{ $result = $1; %} 395 %typemap(out) unsigned long long %{ $result = $1; %} 396 %typemap(out) float %{ $result = $1; %} 397 %typemap(out) double %{ $result = $1; %} 398 %typemap(out) enum SWIGTYPE %{ $result = $1; %} 399 400 /* char * - treat as String */ 401 %typemap(in) char * { 402 $1 = $input; 403 } 404 //%typemap(freearg) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); } 405 //%typemap(out) char * { if($1) $result = JCALL1(NewStringUTF, jenv, $1); } 406 407 %typemap(out) void "" 408 409 /* primitive types by const reference */ 410 %typemap(in) const bool & (bool temp) 411 %{ temp = $input ? true : false; 412 $1 = &temp; %} 413 414 %typemap(in) const char & (char temp), 415 const signed char & (signed char temp), 416 const unsigned char & (unsigned char temp), 417 const short & (short temp), 418 const unsigned short & (unsigned short temp), 419 const int & (int temp), 420 const unsigned int & (unsigned int temp), 421 const long & (long temp), 422 const unsigned long & (unsigned long temp), 423 const long long & ($*1_ltype temp), 424 const unsigned long long & ($*1_ltype temp), 425 const float & (float temp), 426 const double & (double temp) 427 %{ temp = ($*1_ltype)$input; 428 $1 = &temp; %} 429 430 %typemap(out) const bool & %{ $result = *$1; %} 431 %typemap(out) const char & %{ $result = *$1; %} 432 %typemap(out) const signed char & %{ $result = *$1; %} 433 %typemap(out) const unsigned char & %{ $result = *$1; %} 434 %typemap(out) const short & %{ $result = *$1; %} 435 %typemap(out) const unsigned short & %{ $result = *$1; %} 436 %typemap(out) const int & %{ $result = *$1; %} 437 %typemap(out) const unsigned int & %{ $result = *$1; %} 438 %typemap(out) const long & %{ $result = *$1; %} 439 %typemap(out) const unsigned long & %{ $result = *$1; %} 440 %typemap(out) const long long & %{ $result = *$1; %} 441 %typemap(out) const unsigned long long & %{ $result = *$1; %} 442 %typemap(out) const float & %{ $result = *$1; %} 443 %typemap(out) const double & %{ $result = *$1; %} 444 445 /* Default handling. Object passed by value. Convert to a pointer */ 446 %typemap(in) SWIGTYPE ($&1_type argp) 447 %{ argp = *($&1_ltype*)&$input; 448 if (!argp) { 449 // SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); 450 RETURN $null; 451 } 452 $1 = *argp; %} 453 %typemap(out) SWIGTYPE 454 #ifdef __cplusplus 455 %{*($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1); %} 456 #else 457 { 458 $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); 459 memmove($1ptr, &$1, sizeof($1_type)); 460 *($&1_ltype*)&$result = $1ptr; 461 } 462 #endif 463 464 /* Generic pointers and references */ 465 %typemap(in) SWIGTYPE *, SWIGTYPE (CLASS::*) %{ $1 = *($&1_ltype)&$input; %} 466 %typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input; 467 if(!$1) { 468 //SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); 469 RETURN $null; 470 } %} 471 %typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE (CLASS::*) %{ *($&1_ltype)&$result = $1; %} 472 473 474 /* Default array handling */ 475 %typemap(in) SWIGTYPE [] %{ $1 = *($&1_ltype)&$input; %} 476 %typemap(out) SWIGTYPE [] %{ *($&1_ltype)&$result = $1; %} 477 478 /* char[ANY] - treat as String */ 479 %typemap(in) char[ANY] { 480 $1 = $input; 481 } 482 483 %typemap(argout) char[ANY] "" 484 %typemap(freearg) char[ANY] ""//{ if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); } 485 %typemap(out) char[ANY] { if($1) $result = $1; } 486 487 488 /* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions 489 * that cannot be overloaded in C# as more than one C++ type maps to a single C# type */ 490 491 %typecheck(SWIG_TYPECHECK_BOOL) /* Java boolean */ 492 bool, 493 const bool & 494 "" 495 496 %typecheck(SWIG_TYPECHECK_CHAR) /* Java char */ 497 char, 498 const char & 499 "" 500 501 %typecheck(SWIG_TYPECHECK_INT8) /* Java byte */ 502 signed char, 503 const signed char & 504 "" 505 506 %typecheck(SWIG_TYPECHECK_INT16) /* Java short */ 507 unsigned char, 508 short, 509 const unsigned char &, 510 const short & 511 "" 512 513 %typecheck(SWIG_TYPECHECK_INT32) /* Java int */ 514 unsigned short, 515 int, 516 long, 517 const unsigned short &, 518 const int &, 519 const long &, 520 enum SWIGTYPE 521 "" 522 523 %typecheck(SWIG_TYPECHECK_INT64) /* Java long */ 524 unsigned int, 525 unsigned long, 526 long long, 527 const unsigned int &, 528 const unsigned long &, 529 const long long & 530 "" 531 532 %typecheck(SWIG_TYPECHECK_INT128) /* Java BigInteger */ 533 unsigned long long 534 "" 535 536 %typecheck(SWIG_TYPECHECK_FLOAT) /* Java float */ 537 float, 538 const float & 539 "" 540 541 %typecheck(SWIG_TYPECHECK_DOUBLE) /* Java double */ 542 double, 543 const double & 544 "" 545 546 %typecheck(SWIG_TYPECHECK_STRING) /* Java String */ 547 char *, 548 char[ANY] 549 "" 550 551 %typecheck(SWIG_TYPECHECK_POINTER) /* Default */ 552 SWIGTYPE, 553 SWIGTYPE *, 554 SWIGTYPE &, 555 SWIGTYPE [], 556 SWIGTYPE (CLASS::*) 557 "" 558 559 /* Exception handling */ 560 561 %typemap(throws) int, 562 long, 563 short, 564 unsigned int, 565 unsigned long, 566 unsigned short { 567 char error_msg[256]; 568 sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1); 569 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, error_msg); 570 RETURN $null; 571 } 572 573 %typemap(throws) SWIGTYPE { 574 (void)$1; 575 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown"); 576 RETURN $null; 577 } 578 579 %typemap(throws) char * { 580 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1); 581 RETURN $null; 582 } 583 584 585 /* Typemaps for code generation in proxy classes and C# type wrapper classes */ 586 587 /* The in typemap is used for converting function parameter types from the type 588 * used in the proxy, module or type wrapper class to the type used in the PInvoke class. */ 589 %typemap(m3in) bool, const bool &, 590 char, const char &, 591 signed char, const signed char &, 592 unsigned char, const unsigned char &, 593 short, const short &, 594 unsigned short, const unsigned short &, 595 int, const int &, 596 unsigned int, const unsigned int &, 597 long, const long &, 598 unsigned long, const unsigned long &, 599 long long, const long long &, 600 unsigned long long, const unsigned long long &, 601 float, const float &, 602 double, const double &, 603 char *, 604 char[ANY], 605 enum SWIGTYPE 606 "$input" 607 %typemap(m3in) SWIGTYPE "$&*1_type.getCPtr($input)" 608 %typemap(m3in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "$1_basetype.getCPtr($input)" 609 610 /* The m3out typemap is used for converting function return types from the return type 611 * used in the PInvoke class to the type returned by the proxy, module or type wrapper class. */ 612 %typemap(m3out) bool, const bool &, 613 char, const char &, 614 signed char, const signed char &, 615 unsigned char, const unsigned char &, 616 short, const short &, 617 unsigned short, const unsigned short &, 618 int, const int &, 619 unsigned int, const unsigned int &, 620 long, const long &, 621 unsigned long, const unsigned long &, 622 long long, const long long &, 623 unsigned long long, const unsigned long long &, 624 float, const float &, 625 double, const double &, 626 char *, 627 char[ANY], 628 enum SWIGTYPE 629 %{$imcall%} 630 631 %typemap(m3out) void %{$imcall%} 632 633 %typemap(m3out) SWIGTYPE %{ 634 RETURN NEW(REF $1_basetype, $imcall); 635 %} 636 %typemap(m3out) SWIGTYPE & %{ 637 RETURN NEW($1_basetype, $imcall, $owner); 638 %} 639 %typemap(m3out) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ 640 cPtr := $imcall; 641 RETURN (cPtr = IntPtr.Zero) ? null : NEW($1_basetype, cPtr, $owner); 642 %} 643 644 /* Properties */ 645 %typemap(m3varin) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ 646 PROCEDURE Set$var (value: $vartype) = 647 BEGIN 648 $imcall; 649 END Set$var; 650 %} 651 652 %typemap(m3varout) bool, const bool &, 653 char, const char &, 654 signed char, const signed char &, 655 unsigned char, const unsigned char &, 656 short, const short &, 657 unsigned short, const unsigned short &, 658 int, const int &, 659 unsigned int, const unsigned int &, 660 long, const long &, 661 unsigned long, const unsigned long &, 662 long long, const long long &, 663 unsigned long long, const unsigned long long &, 664 float, const float &, 665 double, const double &, 666 char *, 667 char[ANY], 668 enum SWIGTYPE %{ 669 PROCEDURE Get$var (): $vartype = 670 BEGIN 671 RETURN $imcall; 672 END Get$var; 673 %} 674 675 %typemap(m3varout) void %{ 676 get { 677 $imcall; 678 } %} 679 %typemap(m3varout) SWIGTYPE %{ 680 get { 681 RETURN new $&*1_mangle($imcall, true); 682 } %} 683 %typemap(m3varout) SWIGTYPE & %{ 684 get { 685 RETURN new $1_basetype($imcall, $owner); 686 } %} 687 %typemap(m3varout) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ 688 get { 689 IntPtr cPtr = $imcall; 690 RETURN (cPtr == IntPtr.Zero) ? null : new $1_basetype(cPtr, $owner); 691 } %} 692 693 /* Typemaps used for the generation of proxy and type wrapper class code */ 694 %typemap(m3base) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" 695 %typemap(m3classmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public" 696 %typemap(m3code) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" 697 %typemap(m3imports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "using System;" 698 %typemap(m3interfaces) SWIGTYPE "IDisposable" 699 %typemap(m3interfaces_derived) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" 700 %typemap(m3ptrconstructormodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "internal" 701 702 %typemap(m3finalize) SWIGTYPE %{ 703 ~$1_basetype() { 704 Dispose(); 705 } 706 %} 707 708 %typemap(m3destruct, methodname="Dispose") SWIGTYPE { 709 if(swigCPtr != IntPtr.Zero && swigCMemOwn) { 710 $imcall; 711 swigCMemOwn = false; 712 } 713 swigCPtr = IntPtr.Zero; 714 GC.SuppressFinalize(this); 715 } 716 717 %typemap(m3destruct_derived, methodname="Dispose") SWIGTYPE { 718 if(swigCPtr != IntPtr.Zero && swigCMemOwn) { 719 $imcall; 720 swigCMemOwn = false; 721 } 722 swigCPtr = IntPtr.Zero; 723 GC.SuppressFinalize(this); 724 base.Dispose(); 725 } 726 727 %typemap(m3getcptr) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ 728 internal static IntPtr getCPtr($1_basetype obj) { 729 RETURN (obj == null) ? IntPtr.Zero : obj.swigCPtr; 730 } 731 %} 732 733 /* M3 specific directives */ 734 #define %m3multiretval %feature("modula3:multiretval") 735 #define %constnumeric(num) %feature("constnumeric","num") 736 737 %pragma(modula3) moduleimports=%{ 738 IMPORT BlaBla; 739 %} 740 741 %pragma(modula3) imclassimports=%{ 742 FROM BlaBla IMPORT Bla; 743 %} 744 745 /* Some ANSI C typemaps */ 746 747 %apply unsigned long { size_t }; 748 749 /* Array reference typemaps */ 750 %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } 751 752 /* const pointers */ 753 %apply SWIGTYPE * { SWIGTYPE *const } 754 755