1 // Users can provide their own SWIG_SHARED_PTR_TYPEMAPS macro before including this file to change the 2 // visibility of the constructor and getCPtr method if desired to public if using multiple modules. 3 #ifndef SWIG_SHARED_PTR_TYPEMAPS 4 #define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...) SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(protected, protected, CONST, TYPE) 5 #endif 6 7 %include <shared_ptr.i> 8 9 // Language specific macro implementing all the customisations for handling the smart pointer 10 %define SWIG_SHARED_PTR_TYPEMAPS_IMPLEMENTATION(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, CONST, TYPE...) 11 12 // %naturalvar is as documented for member variables 13 %naturalvar TYPE; 14 %naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; 15 16 // destructor wrapper customisation 17 %feature("unref") TYPE 18 //"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" 19 "(void)arg1; delete smartarg1;" 20 21 // Typemap customisations... 22 23 // plain value 24 %typemap(in) CONST TYPE ($&1_type argp = 0) %{ 25 argp = (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0; 26 if (!argp) { 27 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); 28 return $null; 29 } 30 $1 = *argp; %} 31 %typemap(out) CONST TYPE 32 %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %} 33 34 // plain pointer 35 %typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{ 36 smartarg = *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input; 37 $1 = (TYPE *)(smartarg ? smartarg->get() : 0); %} 38 %typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{ 39 *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; 40 %} 41 42 // plain reference 43 %typemap(in) CONST TYPE & %{ 44 $1 = ($1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); 45 if (!$1) { 46 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); 47 return $null; 48 } %} 49 %typemap(out, fragment="SWIG_null_deleter") CONST TYPE & 50 %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %} 51 52 // plain pointer by reference 53 %typemap(in) TYPE *CONST& ($*1_ltype temp = 0) 54 %{ temp = (TYPE *)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); 55 $1 = &temp; %} 56 %typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& 57 %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %} 58 59 // shared_ptr by value 60 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ($&1_type argp) 61 %{ argp = *($&1_ltype*)&$input; 62 if (argp) $1 = *argp; %} 63 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > 64 %{ *($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0; %} 65 66 // shared_ptr by reference 67 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & ($*1_ltype tempnull) 68 %{ $1 = $input ? *($&1_ltype)&$input : &tempnull; %} 69 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & 70 %{ *($&1_ltype)&$result = *$1 ? new $*1_ltype(*$1) : 0; %} 71 72 // shared_ptr by pointer 73 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull) 74 %{ $1 = $input ? *($&1_ltype)&$input : &tempnull; %} 75 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * 76 %{ *($&1_ltype)&$result = ($1 && *$1) ? new $*1_ltype(*$1) : 0; 77 if ($owner) delete $1; %} 78 79 // shared_ptr by pointer reference 80 %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempnull, $*1_ltype temp = 0) 81 %{ temp = $input ? *($1_ltype)&$input : &tempnull; 82 $1 = &temp; %} 83 %typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& 84 %{ *($1_ltype)&$result = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %} 85 86 // various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug 87 %typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ 88 #error "typemaps for $1_type not available" 89 %} 90 %typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{ 91 #error "typemaps for $1_type not available" 92 %} 93 94 95 %typemap (jni) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 96 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, 97 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, 98 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "jlong" 99 %typemap (jtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 100 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, 101 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, 102 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "long" 103 %typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 104 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, 105 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, 106 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(jstype, TYPE)" 107 108 %typemap(javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, 109 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, 110 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, 111 SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(jstype, TYPE).getCPtr($javainput)" 112 113 %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > { 114 long cPtr = $jnicall; 115 return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); 116 } 117 %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & { 118 long cPtr = $jnicall; 119 return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); 120 } 121 %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * { 122 long cPtr = $jnicall; 123 return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); 124 } 125 %typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& { 126 long cPtr = $jnicall; 127 return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); 128 } 129 130 131 %typemap(javaout) CONST TYPE { 132 return new $typemap(jstype, TYPE)($jnicall, true); 133 } 134 %typemap(javaout) CONST TYPE & { 135 return new $typemap(jstype, TYPE)($jnicall, true); 136 } 137 %typemap(javaout) CONST TYPE * { 138 long cPtr = $jnicall; 139 return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); 140 } 141 %typemap(javaout) TYPE *CONST& { 142 long cPtr = $jnicall; 143 return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); 144 } 145 146 // Base proxy classes 147 %typemap(javabody) TYPE %{ 148 private long swigCPtr; 149 private boolean swigCMemOwn; 150 151 PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { 152 swigCMemOwn = cMemoryOwn; 153 swigCPtr = cPtr; 154 } 155 156 CPTR_VISIBILITY static long getCPtr($javaclassname obj) { 157 return (obj == null) ? 0 : obj.swigCPtr; 158 } 159 %} 160 161 // Derived proxy classes 162 %typemap(javabody_derived) TYPE %{ 163 private long swigCPtr; 164 private boolean swigCMemOwnDerived; 165 166 PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) { 167 super($imclassname.$javaclazznameSWIGSmartPtrUpcast(cPtr), true); 168 swigCMemOwnDerived = cMemoryOwn; 169 swigCPtr = cPtr; 170 } 171 172 CPTR_VISIBILITY static long getCPtr($javaclassname obj) { 173 return (obj == null) ? 0 : obj.swigCPtr; 174 } 175 %} 176 177 %typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE { 178 if (swigCPtr != 0) { 179 if (swigCMemOwn) { 180 swigCMemOwn = false; 181 $jnicall; 182 } 183 swigCPtr = 0; 184 } 185 } 186 187 %typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE { 188 if (swigCPtr != 0) { 189 if (swigCMemOwnDerived) { 190 swigCMemOwnDerived = false; 191 $jnicall; 192 } 193 swigCPtr = 0; 194 } 195 super.delete(); 196 } 197 198 199 %template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >; 200 %enddef 201 202