Home | History | Annotate | Download | only in r
      1 %include <shared_ptr.i>
      2 
      3 // Language specific macro implementing all the customisations for handling the smart pointer
      4 %define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
      5 
      6 // %naturalvar is as documented for member variables
      7 %naturalvar TYPE;
      8 %naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
      9 
     10 // destructor wrapper customisation
     11 %feature("unref") TYPE
     12 //"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
     13                                "(void)arg1; delete smartarg1;"
     14 
     15 // Typemap customisations...
     16 
     17 // plain value
     18 %typemap(in) CONST TYPE (void *argp, int res = 0) {
     19   int newmem = 0;
     20   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
     21   if (!SWIG_IsOK(res)) {
     22     %argument_fail(res, "$type", $symname, $argnum);
     23   }
     24   if (!argp) {
     25     %argument_nullref("$type", $symname, $argnum);
     26   } else {
     27     $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get());
     28     if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     29   }
     30 }
     31 %typemap(out) CONST TYPE {
     32   %set_output(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
     33 }
     34 
     35 %typemap(varin) CONST TYPE {
     36   void *argp = 0;
     37   int newmem = 0;
     38   int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
     39   if (!SWIG_IsOK(res)) {
     40     %variable_fail(res, "$type", "$name");
     41   }
     42   if (!argp) {
     43     %argument_nullref("$type", $symname, $argnum);
     44   } else {
     45     $1 = *(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get());
     46     if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     47   }
     48 }
     49 %typemap(varout) CONST TYPE {
     50   %set_varoutput(SWIG_NewPointerObj(new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
     51 }
     52 
     53 // plain pointer
     54 // Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance
     55 %typemap(in) CONST TYPE * (void  *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) {
     56   int newmem = 0;
     57   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
     58   if (!SWIG_IsOK(res)) {
     59     %argument_fail(res, "$type", $symname, $argnum);
     60   }
     61   if (newmem & SWIG_CAST_NEW_MEMORY) {
     62     tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     63     delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     64     $1 = %const_cast(tempshared.get(), $1_ltype);
     65   } else {
     66     smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     67     $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
     68   }
     69 }
     70 %typemap(out, fragment="SWIG_null_deleter") CONST TYPE * {
     71   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
     72   %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN));
     73 }
     74 
     75 %typemap(varin) CONST TYPE * {
     76   void *argp = 0;
     77   int newmem = 0;
     78   int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
     79   if (!SWIG_IsOK(res)) {
     80     %variable_fail(res, "$type", "$name");
     81   }
     82   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared;
     83   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0;
     84   if (newmem & SWIG_CAST_NEW_MEMORY) {
     85     tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     86     delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     87     $1 = %const_cast(tempshared.get(), $1_ltype);
     88   } else {
     89     smartarg = %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
     90     $1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
     91   }
     92 }
     93 %typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * {
     94   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
     95   %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
     96 }
     97 
     98 // plain reference
     99 %typemap(in) CONST TYPE & (void  *argp = 0, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) {
    100   int newmem = 0;
    101   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    102   if (!SWIG_IsOK(res)) {
    103     %argument_fail(res, "$type", $symname, $argnum);
    104   }
    105   if (!argp) { %argument_nullref("$type", $symname, $argnum); }
    106   if (newmem & SWIG_CAST_NEW_MEMORY) {
    107     tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
    108     delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
    109     $1 = %const_cast(tempshared.get(), $1_ltype);
    110   } else {
    111     $1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
    112   }
    113 }
    114 %typemap(out, fragment="SWIG_null_deleter") CONST TYPE & {
    115   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner);
    116   %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    117 }
    118 
    119 %typemap(varin) CONST TYPE & {
    120   void *argp = 0;
    121   int newmem = 0;
    122   int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    123   if (!SWIG_IsOK(res)) {
    124     %variable_fail(res, "$type", "$name");
    125   }
    126   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared;
    127   if (!argp) { %argument_nullref("$type", $symname, $argnum); }
    128   if (newmem & SWIG_CAST_NEW_MEMORY) {
    129     tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
    130     delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
    131     $1 = *%const_cast(tempshared.get(), $1_ltype);
    132   } else {
    133     $1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
    134   }
    135 }
    136 %typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & {
    137   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0);
    138   %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    139 }
    140 
    141 // plain pointer by reference
    142 // Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance
    143 %typemap(in) TYPE *CONST& (void  *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) {
    144   int newmem = 0;
    145   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    146   if (!SWIG_IsOK(res)) {
    147     %argument_fail(res, "$type", $symname, $argnum);
    148   }
    149   if (newmem & SWIG_CAST_NEW_MEMORY) {
    150     tempshared = *%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
    151     delete %reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *);
    152     temp = %const_cast(tempshared.get(), $*1_ltype);
    153   } else {
    154     temp = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $*1_ltype);
    155   }
    156   $1 = &temp;
    157 }
    158 %typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& {
    159   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner);
    160   %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    161 }
    162 
    163 %typemap(varin) TYPE *CONST& %{
    164 #error "varin typemap not implemented"
    165 %}
    166 %typemap(varout) TYPE *CONST& %{
    167 #error "varout typemap not implemented"
    168 %}
    169 
    170 // shared_ptr by value
    171 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (void *argp, int res = 0) {
    172   int newmem = 0;
    173   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    174   if (!SWIG_IsOK(res)) {
    175     %argument_fail(res, "$type", $symname, $argnum);
    176   }
    177   if (argp) $1 = *(%reinterpret_cast(argp, $&ltype));
    178   if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $&ltype);
    179 }
    180 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
    181   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
    182   %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    183 }
    184 
    185 %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
    186   int newmem = 0;
    187   void *argp = 0;
    188   int res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    189   if (!SWIG_IsOK(res)) {
    190     %variable_fail(res, "$type", "$name");
    191   }
    192   $1 = argp ? *(%reinterpret_cast(argp, $&ltype)) : SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE >();
    193   if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $&ltype);
    194 }
    195 %typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
    196   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1) : 0;
    197   %set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    198 }
    199 
    200 // shared_ptr by reference
    201 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & (void *argp, int res = 0, $*1_ltype tempshared) {
    202   int newmem = 0;
    203   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    204   if (!SWIG_IsOK(res)) {
    205     %argument_fail(res, "$type", $symname, $argnum);
    206   }
    207   if (newmem & SWIG_CAST_NEW_MEMORY) {
    208     if (argp) tempshared = *%reinterpret_cast(argp, $ltype);
    209     delete %reinterpret_cast(argp, $ltype);
    210     $1 = &tempshared;
    211   } else {
    212     $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared;
    213   }
    214 }
    215 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
    216   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
    217   %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    218 }
    219 
    220 %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
    221 #error "varin typemap not implemented"
    222 %}
    223 %typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & %{
    224 #error "varout typemap not implemented"
    225 %}
    226 
    227 // shared_ptr by pointer
    228 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * (void *argp, int res = 0, $*1_ltype tempshared) {
    229   int newmem = 0;
    230   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    231   if (!SWIG_IsOK(res)) {
    232     %argument_fail(res, "$type", $symname, $argnum);
    233   }
    234   if (newmem & SWIG_CAST_NEW_MEMORY) {
    235     if (argp) tempshared = *%reinterpret_cast(argp, $ltype);
    236     delete %reinterpret_cast(argp, $ltype);
    237     $1 = &tempshared;
    238   } else {
    239     $1 = (argp) ? %reinterpret_cast(argp, $ltype) : &tempshared;
    240   }
    241 }
    242 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
    243   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 && *$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1) : 0;
    244   %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    245   if ($owner) delete $1;
    246 }
    247 
    248 %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
    249 #error "varin typemap not implemented"
    250 %}
    251 %typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %{
    252 #error "varout typemap not implemented"
    253 %}
    254 
    255 // shared_ptr by pointer reference
    256 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (void *argp, int res = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared, $*1_ltype temp = 0) {
    257   int newmem = 0;
    258   res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem);
    259   if (!SWIG_IsOK(res)) {
    260     %argument_fail(res, "$type", $symname, $argnum);
    261   }
    262   if (argp) tempshared = *%reinterpret_cast(argp, $*ltype);
    263   if (newmem & SWIG_CAST_NEW_MEMORY) delete %reinterpret_cast(argp, $*ltype);
    264   temp = &tempshared;
    265   $1 = &temp;
    266 }
    267 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
    268   SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = *$1 && **$1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0;
    269   %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
    270 }
    271 
    272 %typemap(varin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
    273 #error "varin typemap not implemented"
    274 %}
    275 %typemap(varout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& %{
    276 #error "varout typemap not implemented"
    277 %}
    278 
    279 // Typecheck typemaps
    280 // Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting
    281 // function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain.
    282 %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1)
    283                       TYPE CONST,
    284                       TYPE CONST &,
    285                       TYPE CONST *,
    286                       TYPE *CONST&,
    287                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
    288                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
    289                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
    290                       SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
    291   int res = SWIG_ConvertPtr($input, 0, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), 0);
    292   $1 = SWIG_CheckState(res);
    293 }
    294 
    295 
    296 // various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
    297 %typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
    298 #error "typemaps for $1_type not available"
    299 %}
    300 %typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
    301 #error "typemaps for $1_type not available"
    302 %}
    303 
    304 
    305 %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
    306 %enddef
    307 
    308