1/* ----------------------------------------------------------------------------- 2 * swig.swg 3 * 4 * Common macro definitions for various SWIG directives. This file is always 5 * included at the top of each input file. 6 * ----------------------------------------------------------------------------- */ 7 8/* ----------------------------------------------------------------------------- 9 * User Directives 10 * ----------------------------------------------------------------------------- */ 11 12/* Deprecated SWIG directives */ 13 14#define %disabledoc %warn "104:%disabledoc is deprecated" 15#define %enabledoc %warn "105:%enabledoc is deprecated" 16#define %doconly %warn "106:%doconly is deprecated" 17#define %style %warn "107:%style is deprecated" /##/ 18#define %localstyle %warn "108:%localstyle is deprecated" /##/ 19#define %title %warn "109:%title is deprecated" /##/ 20#define %section %warn "110:%section is deprecated" /##/ 21#define %subsection %warn "111:%subsection is deprecated" /##/ 22#define %subsubsection %warn "112:%subsubsection is deprecated" /##/ 23#define %new %warn "117:%new is deprecated. Use %newobject" 24#define %text %insert("null") 25 26/* Code insertion directives such as %wrapper %{ ... %} */ 27 28#define %begin %insert("begin") 29#define %runtime %insert("runtime") 30#define %header %insert("header") 31#define %wrapper %insert("wrapper") 32#define %init %insert("init") 33 34/* Class extension */ 35 36#define %addmethods %warn "113:%addmethods is now %extend" %extend 37 38/* %ignore directive */ 39 40#define %ignore %rename($ignore) 41#define %ignorewarn(x) %rename("$ignore:" x) 42 43/* Access control directives */ 44 45#define %readonly %warn "114:%readonly is deprecated. Use %immutable; " %feature("immutable"); 46#define %readwrite %warn "115:%readwrite is deprecated. Use %mutable; " %feature("immutable",""); 47 48#define %immutable %feature("immutable") 49#define %noimmutable %feature("immutable","0") 50#define %clearimmutable %feature("immutable","") 51#define %mutable %clearimmutable 52 53/* Generation of default constructors/destructors (old form, don't use) */ 54#define %nodefault %feature("nodefault","1") 55#define %default %feature("nodefault","0") 56#define %clearnodefault %feature("nodefault","") 57#define %makedefault %clearnodefault 58 59/* Disable the generation of implicit default constructor */ 60#define %nodefaultctor %feature("nodefaultctor","1") 61#define %defaultctor %feature("nodefaultctor","0") 62#define %clearnodefaultctor %feature("nodefaultctor","") 63 64/* Disable the generation of implicit default destructor (dangerous) */ 65#define %nodefaultdtor %feature("nodefaultdtor","1") 66#define %defaultdtor %feature("nodefaultdtor","0") 67#define %clearnodefaultdtor %feature("nodefaultdtor","") 68 69/* Enable the generation of copy constructor */ 70#define %copyctor %feature("copyctor","1") 71#define %nocopyctor %feature("copyctor","0") 72#define %clearcopyctor %feature("copyctor","") 73 74/* Force the old nodefault behavior, ie disable both constructor and destructor */ 75#define %oldnodefault %feature("oldnodefault","1") 76#define %nooldnodefault %feature("oldnodefault","0") 77#define %clearoldnodefault %feature("oldnodefault","") 78 79/* the %exception directive */ 80#ifdef SWIGCSHARP 81#define %exception %feature("except", canthrow=1) 82#else 83#define %exception %feature("except") 84#endif 85#define %noexception %feature("except","0") 86#define %clearexception %feature("except","") 87 88/* the %allowexception directive allows the %exception feature to 89 be applied to set/get variable methods */ 90#define %allowexception %feature("allowexcept") 91#define %noallowexception %feature("allowexcept","0") 92#define %clearallowexception %feature("allowexcept","") 93 94/* the %exceptionvar directive, as %exception but it is only applied 95 to set/get variable methods. You don't need to use the 96 %allowexception directive when using %exceptionvar. 97*/ 98#ifdef SWIGCSHARP 99#define %exceptionvar %feature("exceptvar", canthrow=1) 100#else 101#define %exceptionvar %feature("exceptvar") 102#endif 103#define %noexceptionvar %feature("exceptvar","0") 104#define %clearexceptionvar %feature("exceptvar","") 105 106/* the %catches directive */ 107#define %catches(tlist...) %feature("catches","("`tlist`")") 108#define %clearcatches %feature("catches","") 109 110/* the %exceptionclass directive */ 111#define %exceptionclass %feature("exceptionclass") 112#define %noexceptionclass %feature("exceptionclass","0") 113#define %clearexceptionclass %feature("exceptionclass","") 114 115/* the %newobject directive */ 116#define %newobject %feature("new") 117#define %nonewobject %feature("new","0") 118#define %clearnewobject %feature("new","") 119 120/* the %delobject directive */ 121#define %delobject %feature("del") 122#define %nodelobject %feature("del","0") 123#define %cleardelobject %feature("del","") 124 125/* the %refobject/%unrefobject directives */ 126#define %refobject %feature("ref") 127#define %norefobject %feature("ref","0") 128#define %clearrefobject %feature("ref","") 129 130#define %unrefobject %feature("unref") 131#define %nounrefobject %feature("unref","0") 132#define %clearunrefobject %feature("unref","") 133 134/* Directives for callback functions (experimental) */ 135#define %callback(x) %feature("callback",`x`) 136#define %nocallback %feature("callback","0") 137#define %clearcallback %feature("callback","") 138 139/* the %fastdispatch directive */ 140#define %fastdispatch %feature("fastdispatch") 141#define %nofastdispatch %feature("fastdispatch","0") 142#define %clearfastdispatch %feature("fastdispatch","") 143 144/* directors directives */ 145#define %director %feature("director") 146#define %nodirector %feature("director","0") 147#define %cleardirector %feature("director","") 148 149/* naturalvar directives */ 150#define %naturalvar %feature("naturalvar") 151#define %nonaturalvar %feature("naturalvar","0") 152#define %clearnaturalvar %feature("naturalvar","") 153 154/* valuewrapper directives */ 155#define %valuewrapper %feature("valuewrapper") 156#define %clearvaluewrapper %feature("valuewrapper","") 157#define %novaluewrapper %feature("novaluewrapper") 158#define %clearnovaluewrapper %feature("novaluewrapper","") 159 160/* Contract support - Experimental and undocumented */ 161#define %contract %feature("contract") 162#define %nocontract %feature("contract","0") 163#define %clearcontract %feature("contract","") 164 165/* Macro for setting a dynamic cast function */ 166%define DYNAMIC_CAST(mangle,func) 167%init %{ 168 mangle->dcast = (swig_dycast_func) func; 169%} 170%enddef 171 172/* aggregation support */ 173/* 174 This macro performs constant aggregation. Basically the idea of 175 constant aggregation is that you can group a collection of constants 176 together. For example, suppose you have some code like this: 177 178 #define UP 1 179 #define DOWN 2 180 #define LEFT 3 181 #define RIGHT 4 182 183 Now, suppose you had a function like this: 184 185 int move(int direction) 186 187 In this case, you might want to restrict the direction argument to 188 one of the supplied constant names. To do this, you could write some 189 typemap code by hand. Alternatively, you can use the 190 %aggregate_check macro defined here to create a simple check 191 function for you. Here is an example: 192 193 %aggregate_check(int, check_direction, UP, DOWN, LEFT, RIGHT); 194 195 Now, using a typemap 196 197 %typemap(check) int direction { 198 if (!check_direction($1)) SWIG_exception(SWIG_ValueError,"Bad direction."); 199 } 200 201 or a contract (better) 202 203 %contract move(int x) { 204 require: 205 check_direction(x); 206 } 207 208*/ 209 210%define %aggregate_check(TYPE, NAME, FIRST, ...) 211%wrapper %{ 212static int NAME(TYPE x) { 213 static TYPE values[] = { FIRST, ##__VA_ARGS__ }; 214 static int size = sizeof(values); 215 int i,j; 216 for (i = 0, j = 0; i < size; i+=sizeof(TYPE),j++) { 217 if (x == values[j]) return 1; 218 } 219 return 0; 220} 221%} 222%enddef 223 224 225/* ----------------------------------------------------------------------------- 226 * %rename predicates 227 * ----------------------------------------------------------------------------- */ 228/* 229 Predicates to be used with %rename, for example: 230 231 - to rename all the functions: 232 233 %rename("%(utitle)s", %$isfunction) ""; 234 235 - to rename only the member methods: 236 237 %rename("m_%(utitle)s", %$isfunction, %$ismember) ""; 238 239 - to rename only the global functions: 240 241 %rename("m_%(utitle)s", %$isfunction, %$not %$ismember) ""; 242 243 or 244 245 %rename("g_%(utitle)s", %$isfunction, %$isglobal) ""; 246 247 - to ignore the enumitems in a given class: 248 249 %rename("$ignore", %$isenumitem, %$classname="MyClass") ""; 250 251 we use the prefix '%$' to avoid clashings with other swig 252 macros/directives. 253 254*/ 255 256%define %$not "not" %enddef 257%define %$isenum "match"="enum" %enddef 258%define %$isenumitem "match"="enumitem" %enddef 259%define %$isaccess "match"="access" %enddef 260%define %$isclass "match"="class","notmatch$template$templatetype"="class" %enddef 261%define %$isextend "match"="extend" %enddef 262%define %$isextend "match"="extend" %enddef 263%define %$isconstructor "match"="constructor" %enddef 264%define %$isdestructor "match"="destructor" %enddef 265%define %$isnamespace "match"="namespace" %enddef 266%define %$istemplate "match"="template" %enddef 267%define %$isconstant "match"="constant" %enddef /* %constant definition */ 268 269%define %$isunion "match$kind"="union" %enddef 270%define %$isfunction "match$kind"="function" %enddef 271%define %$isvariable "match$kind"="variable" %enddef 272%define %$isimmutable "match$feature:immutable"="1" %enddef 273%define %$hasconsttype "match$hasconsttype"="1" %enddef 274%define %$hasvalue "match$hasvalue"="1" %enddef 275%define %$isextension "match$isextension"="1" %enddef 276 277%define %$isstatic "match$storage"="static" %enddef 278%define %$isfriend "match$storage"="friend" %enddef 279%define %$istypedef "match$storage"="typedef" %enddef 280%define %$isvirtual "match$storage"="virtual" %enddef 281%define %$isexplicit "match$storage"="explicit" %enddef 282%define %$isextern "match$storage"="extern" %enddef 283 284%define %$ismember "match$ismember"="1" %enddef 285%define %$isglobal %not %ismember %enddef 286%define %$innamespace "match$parentNode$nodeType"="namespace" %enddef 287 288%define %$ispublic "match$access"="public" %enddef 289%define %$isprotected "match$access"="protected" %enddef 290%define %$isprivate "match$access"="private" %enddef 291 292%define %$ismemberget "match$memberget"="1" %enddef 293%define %$ismemberset "match$memberset"="1" %enddef 294 295%define %$classname %ismember,match$parentNode$name %enddef 296 297/* ----------------------------------------------------------------------------- 298 * Include all the warnings labels and macros 299 * ----------------------------------------------------------------------------- */ 300 301%include <swigwarnings.swg> 302 303/* ----------------------------------------------------------------------------- 304 * Default handling of certain overloaded operators 305 * ----------------------------------------------------------------------------- */ 306 307#ifdef __cplusplus 308%ignoreoperator(NEW) operator new; 309%ignoreoperator(DELETE) operator delete; 310%ignoreoperator(NEWARR) operator new[]; 311%ignoreoperator(DELARR) operator delete[]; 312 313/* add C++ operator aliases */ 314%rename("operator &&") operator and; // `and' `&&' 315%rename("operator ||") operator or; // `or' `||' 316%rename("operator !") operator not; // `not' `!' 317%rename("operator &=") operator and_eq; // `and_eq' `&=' 318%rename("operator &") operator bitand; // `bitand' `&' 319%rename("operator |") operator bitor; // `bitor' `|' 320%rename("operator ~") operator compl; // `compl' `~' 321%rename("operator !=") operator not_eq; // `not_eq' `!=' 322%rename("operator |=") operator or_eq; // `or_eq' `|=' 323%rename("operator ^") operator xor; // `xor' `^' 324%rename("operator ^=") operator xor_eq; // `xor_eq' `^=' 325 326/* Smart pointer handling */ 327 328%rename(__deref__) *::operator->; 329%rename(__ref__) *::operator*(); 330%rename(__ref__) *::operator*() const; 331 332/* Define std namespace */ 333namespace std { 334} 335#endif 336 337/* ----------------------------------------------------------------------------- 338 * Default char * and C array typemaps 339 * ----------------------------------------------------------------------------- */ 340 341/* Set up the typemap for handling new return strings */ 342 343#ifdef __cplusplus 344%typemap(newfree) char * "delete [] $1;"; 345#else 346%typemap(newfree) char * "free($1);"; 347#endif 348 349/* Default typemap for handling char * members */ 350 351#ifdef __cplusplus 352%typemap(memberin) char * { 353 if ($1) delete [] $1; 354 if ($input) { 355 $1 = ($1_type) (new char[strlen((const char *)$input)+1]); 356 strcpy((char *)$1, (const char *)$input); 357 } else { 358 $1 = 0; 359 } 360} 361%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { 362 if ($input) { 363 $1 = ($1_type) (new char[strlen((const char *)$input)+1]); 364 strcpy((char *)$1, (const char *)$input); 365 } else { 366 $1 = 0; 367 } 368} 369%typemap(globalin) char * { 370 if ($1) delete [] $1; 371 if ($input) { 372 $1 = ($1_type) (new char[strlen((const char *)$input)+1]); 373 strcpy((char *)$1, (const char *)$input); 374 } else { 375 $1 = 0; 376 } 377} 378%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { 379 if ($input) { 380 $1 = ($1_type) (new char[strlen((const char *)$input)+1]); 381 strcpy((char *)$1, (const char *)$input); 382 } else { 383 $1 = 0; 384 } 385} 386#else 387%typemap(memberin) char * { 388 if ($1) free((char *)$1); 389 if ($input) { 390 $1 = ($1_type) malloc(strlen((const char *)$input)+1); 391 strcpy((char *)$1, (const char *)$input); 392 } else { 393 $1 = 0; 394 } 395} 396%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { 397 if ($input) { 398 $1 = ($1_type) malloc(strlen((const char *)$input)+1); 399 strcpy((char *)$1, (const char *)$input); 400 } else { 401 $1 = 0; 402 } 403} 404%typemap(globalin) char * { 405 if ($1) free((char *)$1); 406 if ($input) { 407 $1 = ($1_type) malloc(strlen((const char *)$input)+1); 408 strcpy((char *)$1, (const char *)$input); 409 } else { 410 $1 = 0; 411 } 412} 413%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { 414 if ($input) { 415 $1 = ($1_type) malloc(strlen((const char *)$input)+1); 416 strcpy((char *)$1, (const char *)$input); 417 } else { 418 $1 = 0; 419 } 420} 421 422#endif 423 424/* Character array handling */ 425 426%typemap(memberin) char [ANY] { 427 if($input) { 428 strncpy((char*)$1, (const char *)$input, $1_dim0-1); 429 $1[$1_dim0-1] = 0; 430 } else { 431 $1[0] = 0; 432 } 433} 434 435%typemap(globalin) char [ANY] { 436 if($input) { 437 strncpy((char*)$1, (const char *)$input, $1_dim0-1); 438 $1[$1_dim0-1] = 0; 439 } else { 440 $1[0] = 0; 441 } 442} 443 444%typemap(memberin) char [] { 445 if ($input) strcpy((char *)$1, (const char *)$input); 446 else $1[0] = 0; 447} 448 449%typemap(globalin) char [] { 450 if ($input) strcpy((char *)$1, (const char *)$input); 451 else $1[0] = 0; 452} 453 454/* memberin/globalin typemap for arrays. */ 455 456%typemap(memberin) SWIGTYPE [ANY] { 457 size_t ii; 458 $1_basetype *b = ($1_basetype *) $1; 459 for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); 460} 461 462%typemap(globalin) SWIGTYPE [ANY] { 463 size_t ii; 464 $1_basetype *b = ($1_basetype *) $1; 465 for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); 466} 467 468/* memberin/globalin typemap for double arrays. */ 469 470%typemap(memberin) SWIGTYPE [ANY][ANY] { 471 $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); 472 $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); 473 size_t ii = 0; 474 for (; ii < $1_dim0; ++ii) { 475 $basetype *ip = inp[ii]; 476 $basetype *dp = dest[ii]; 477 size_t jj = 0; 478 for (; jj < $1_dim1; ++jj) dp[jj] = ip[jj]; 479 } 480} 481 482%typemap(globalin) SWIGTYPE [ANY][ANY] { 483 $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); 484 $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); 485 size_t ii = 0; 486 for (; ii < $1_dim0; ++ii) { 487 $basetype *ip = inp[ii]; 488 $basetype *dp = dest[ii]; 489 size_t jj = 0; 490 for (; jj < $1_dim1; ++jj) dp[jj] = ip[jj]; 491 } 492} 493 494/* Typemap for variable length arguments sentinel value. Used 495 by the %varargs directive. */ 496 497%typemap(in,numinputs=0) SWIGTYPE *VARARGS_SENTINEL, SWIGTYPE VARARGS_SENTINEL ""; 498 499 500/* ----------------------------------------------------------------------------- 501 * Overloading support 502 * ----------------------------------------------------------------------------- */ 503 504/* 505 * Function/method overloading support. This is done through typemaps, 506 * but also involve a precedence level. 507 */ 508 509/* Macro for overload resolution */ 510 511%define %typecheck(_x...) %typemap(typecheck, precedence=_x) %enddef 512 513/* Macros for precedence levels */ 514 515%define SWIG_TYPECHECK_POINTER 0 %enddef 516%define SWIG_TYPECHECK_ITERATOR 5 %enddef 517%define SWIG_TYPECHECK_VOIDPTR 10 %enddef 518%define SWIG_TYPECHECK_BOOL 15 %enddef 519%define SWIG_TYPECHECK_UINT8 20 %enddef 520%define SWIG_TYPECHECK_INT8 25 %enddef 521%define SWIG_TYPECHECK_UINT16 30 %enddef 522%define SWIG_TYPECHECK_INT16 35 %enddef 523%define SWIG_TYPECHECK_UINT32 40 %enddef 524%define SWIG_TYPECHECK_INT32 45 %enddef 525%define SWIG_TYPECHECK_SIZE 47 %enddef 526%define SWIG_TYPECHECK_PTRDIFF 48 %enddef 527%define SWIG_TYPECHECK_UINT64 50 %enddef 528%define SWIG_TYPECHECK_INT64 55 %enddef 529%define SWIG_TYPECHECK_UINT128 60 %enddef 530%define SWIG_TYPECHECK_INT128 65 %enddef 531%define SWIG_TYPECHECK_INTEGER 70 %enddef 532%define SWIG_TYPECHECK_FLOAT 80 %enddef 533%define SWIG_TYPECHECK_DOUBLE 90 %enddef 534%define SWIG_TYPECHECK_CPLXFLT 95 %enddef 535%define SWIG_TYPECHECK_CPLXDBL 100 %enddef 536%define SWIG_TYPECHECK_COMPLEX 105 %enddef 537%define SWIG_TYPECHECK_UNICHAR 110 %enddef 538%define SWIG_TYPECHECK_STDUNISTRING 115 %enddef 539%define SWIG_TYPECHECK_UNISTRING 120 %enddef 540%define SWIG_TYPECHECK_CHAR 130 %enddef 541%define SWIG_TYPECHECK_STDSTRING 135 %enddef 542%define SWIG_TYPECHECK_STRING 140 %enddef 543%define SWIG_TYPECHECK_PAIR 150 %enddef 544%define SWIG_TYPECHECK_VECTOR 160 %enddef 545%define SWIG_TYPECHECK_DEQUE 170 %enddef 546%define SWIG_TYPECHECK_LIST 180 %enddef 547%define SWIG_TYPECHECK_SET 190 %enddef 548%define SWIG_TYPECHECK_MULTISET 200 %enddef 549%define SWIG_TYPECHECK_MAP 210 %enddef 550%define SWIG_TYPECHECK_MULTIMAP 220 %enddef 551%define SWIG_TYPECHECK_STACK 230 %enddef 552%define SWIG_TYPECHECK_QUEUE 240 %enddef 553 554%define SWIG_TYPECHECK_BOOL_ARRAY 1015 %enddef 555%define SWIG_TYPECHECK_INT8_ARRAY 1025 %enddef 556%define SWIG_TYPECHECK_INT16_ARRAY 1035 %enddef 557%define SWIG_TYPECHECK_INT32_ARRAY 1045 %enddef 558%define SWIG_TYPECHECK_INT64_ARRAY 1055 %enddef 559%define SWIG_TYPECHECK_INT128_ARRAY 1065 %enddef 560%define SWIG_TYPECHECK_FLOAT_ARRAY 1080 %enddef 561%define SWIG_TYPECHECK_DOUBLE_ARRAY 1090 %enddef 562%define SWIG_TYPECHECK_CHAR_ARRAY 1130 %enddef 563%define SWIG_TYPECHECK_STRING_ARRAY 1140 %enddef 564%define SWIG_TYPECHECK_OBJECT_ARRAY 1150 %enddef 565 566%define SWIG_TYPECHECK_BOOL_PTR 2015 %enddef 567%define SWIG_TYPECHECK_UINT8_PTR 2020 %enddef 568%define SWIG_TYPECHECK_INT8_PTR 2025 %enddef 569%define SWIG_TYPECHECK_UINT16_PTR 2030 %enddef 570%define SWIG_TYPECHECK_INT16_PTR 2035 %enddef 571%define SWIG_TYPECHECK_UINT32_PTR 2040 %enddef 572%define SWIG_TYPECHECK_INT32_PTR 2045 %enddef 573%define SWIG_TYPECHECK_UINT64_PTR 2050 %enddef 574%define SWIG_TYPECHECK_INT64_PTR 2055 %enddef 575%define SWIG_TYPECHECK_FLOAT_PTR 2080 %enddef 576%define SWIG_TYPECHECK_DOUBLE_PTR 2090 %enddef 577%define SWIG_TYPECHECK_CHAR_PTR 2130 %enddef 578 579 580%define SWIG_TYPECHECK_SWIGOBJECT 5000 %enddef 581 582 583/* ----------------------------------------------------------------------------- 584 * Runtime code 585 * ----------------------------------------------------------------------------- */ 586 587/* The SwigValueWrapper class */ 588 589/* 590 * This template wrapper is used to handle C++ objects that are passed or 591 * returned by value. This is necessary to handle objects that define 592 * no default-constructor (making it difficult for SWIG to properly declare 593 * local variables). 594 * 595 * The wrapper is used as follows. First consider a function like this: 596 * 597 * Vector cross_product(Vector a, Vector b) 598 * 599 * Now, if Vector is defined as a C++ class with no default constructor, 600 * code is generated as follows: 601 * 602 * Vector *wrap_cross_product(Vector *inarg1, Vector *inarg2) { 603 * SwigValueWrapper<Vector> arg1; 604 * SwigValueWrapper<Vector> arg2; 605 * SwigValueWrapper<Vector> result; 606 * 607 * arg1 = *inarg1; 608 * arg2 = *inarg2; 609 * ... 610 * result = cross_product(arg1,arg2); 611 * ... 612 * return new Vector(result); 613 * } 614 * 615 * In the wrappers, the template SwigValueWrapper simply provides a thin 616 * layer around a Vector *. However, it does this in a way that allows 617 * the object to be bound after the variable declaration (which is not possible 618 * with the bare object when it lacks a default constructor). 619 * 620 * An observant reader will notice that the code after the variable declarations 621 * is *identical* to the code used for classes that do define default constructors. 622 * Thus, this neat trick allows us to fix this special case without having to 623 * make massive changes to typemaps and other parts of the SWIG code generator. 624 * 625 * Note: this code is not included when SWIG runs in C-mode, when classes 626 * define default constructors, or when pointers and references are used. 627 * SWIG tries to avoid doing this except in very special circumstances. 628 * 629 * Note: This solution suffers from making a large number of copies 630 * of the underlying object. However, this is needed in the interest of 631 * safety and in order to cover all of the possible ways in which a value 632 * might be assigned. For example: 633 * 634 * arg1 = *inarg1; // Assignment from a pointer 635 * arg1 = Vector(1,2,3); // Assignment from a value 636 * 637 * The class offers a strong guarantee of exception safety. 638 * With regards to the implementation, the private SwigMovePointer nested class is 639 * a simple smart pointer with move semantics, much like std::auto_ptr. 640 * 641 * This wrapping technique was suggested by William Fulton and is henceforth 642 * known as the "Fulton Transform" :-). 643 */ 644 645#ifdef __cplusplus 646%insert("runtime") %{ 647#ifdef __cplusplus 648/* SwigValueWrapper is described in swig.swg */ 649template<typename T> class SwigValueWrapper { 650 struct SwigMovePointer { 651 T *ptr; 652 SwigMovePointer(T *p) : ptr(p) { } 653 ~SwigMovePointer() { delete ptr; } 654 SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } 655 } pointer; 656 SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs); 657 SwigValueWrapper(const SwigValueWrapper<T>& rhs); 658public: 659 SwigValueWrapper() : pointer(0) { } 660 SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } 661 operator T&() const { return *pointer.ptr; } 662 T *operator&() { return pointer.ptr; } 663};%} 664 665/* 666 * SwigValueInit() is a generic initialisation solution as the following approach: 667 * 668 * T c_result = T(); 669 * 670 * doesn't compile for all types for example: 671 * 672 * unsigned int c_result = unsigned int(); 673 */ 674%insert("runtime") %{ 675template <typename T> T SwigValueInit() { 676 return T(); 677} 678#endif 679%} 680#endif 681 682/* The swiglabels */ 683 684%insert("runtime") "swiglabels.swg" 685 686 687