1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * Value typemaps (Type, const Type&) for "Ptr" types, such as swig
8 * wrapped classes, that define the AsPtr/From methods
10 * To apply them, just use one of the following macros:
12 * %typemaps_asptr(CheckCode, AsPtrMeth, AsPtrFrag, Type)
13 * %typemaps_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type)
15 * or the simpler and normalize form:
17 * %typemaps_asptrfromn(CheckCode, Type)
19 * Also, you can use the individual typemap definitions:
21 * %ptr_in_typemap(asptr_meth,frag,Type)
22 * %ptr_varin_typemap(asptr_meth,frag,Type)
23 * %ptr_typecheck_typemap(check,asptr_meth,frag,Type)
24 * %ptr_directorout_typemap(asptr_meth,frag,Type)
25 * ----------------------------------------------------------------------------- */
27 %include <typemaps/valtypes.swg>
31 %define %ptr_in_typemap(asptr_meth,frag,Type...)
32 %typemap(in,fragment=frag) Type {
33 Type *ptr = (Type *)0;
34 int res = asptr_meth($input, &ptr);
35 if (!SWIG_IsOK(res) || !ptr) {
36 %argument_fail((ptr ? res : SWIG_TypeError), "$type", $symname, $argnum);
39 if (SWIG_IsNewObj(res)) %delete(ptr);
41 %typemap(freearg) Type "";
42 %typemap(in,fragment=frag) const Type & (int res = SWIG_OLDOBJ) {
43 Type *ptr = (Type *)0;
44 res = asptr_meth($input, &ptr);
45 if (!SWIG_IsOK(res)) { %argument_fail(res,"$type",$symname, $argnum); }
46 if (!ptr) { %argument_nullref("$type",$symname, $argnum); }
49 %typemap(freearg,noblock=1) const Type & {
50 if (SWIG_IsNewObj(res$argnum)) %delete($1);
56 %define %ptr_varin_typemap(asptr_meth,frag,Type...)
57 %typemap(varin,fragment=frag) Type {
58 Type *ptr = (Type *)0;
59 int res = asptr_meth($input, &ptr);
60 if (!SWIG_IsOK(res) || !ptr) {
61 %variable_fail((ptr ? res : SWIG_TypeError), "$type", "$name");
64 if (SWIG_IsNewObj(res)) %delete(ptr);
68 #if defined(SWIG_DIRECTOR_TYPEMAPS)
71 %define %ptr_directorout_typemap(asptr_meth,frag,Type...)
72 %typemap(directorargout,noblock=1,fragment=frag) Type *DIRECTOROUT ($*ltype temp) {
74 int swig_ores = $input ? asptr_meth($input, &swig_optr) : 0;
75 if (!SWIG_IsOK(swig_ores) || !swig_optr) {
76 %dirout_fail((swig_optr ? swig_ores : SWIG_TypeError),"$type");
80 if (SWIG_IsNewObj(swig_ores)) %delete(swig_optr);
83 %typemap(directorout,noblock=1,fragment=frag) Type {
85 int swig_ores = asptr_meth($input, &swig_optr);
86 if (!SWIG_IsOK(swig_ores) || !swig_optr) {
87 %dirout_fail((swig_optr ? swig_ores : SWIG_TypeError),"$type");
90 if (SWIG_IsNewObj(swig_ores)) %delete(swig_optr);
93 %typemap(directorout,noblock=1,fragment=frag,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Type* {
95 int swig_ores = asptr_meth($input, &swig_optr);
96 if (!SWIG_IsOK(swig_ores)) {
97 %dirout_fail(swig_ores,"$type");
100 if (SWIG_IsNewObj(swig_ores)) {
101 swig_acquire_ownership(swig_optr);
104 %typemap(directorfree,noblock=1) Type*
107 director->swig_release_ownership(%as_voidptr($input));
111 %typemap(directorout,noblock=1,fragment=frag,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Type& {
113 int swig_ores = asptr_meth($input, &swig_optr);
114 if (!SWIG_IsOK(swig_ores)) {
115 %dirout_fail(swig_ores,"$type");
118 %dirout_nullref("$type");
122 if (SWIG_IsNewObj(swig_ores)) {
123 swig_acquire_ownership(swig_optr);
126 %typemap(directorfree,noblock=1) Type&
129 director->swig_release_ownership(%as_voidptr($input));
134 %typemap(directorout,fragment=frag) Type &DIRECTOROUT = Type
140 #define %ptr_directorout_typemap(asptr_meth,frag,Type...)
142 #endif /* SWIG_DIRECTOR_TYPEMAPS */
146 %define %ptr_typecheck_typemap(check,asptr_meth,frag,Type...)
147 %typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type * {
148 int res = asptr_meth($input, (Type**)(0));
149 $1 = SWIG_CheckState(res);
152 %typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type, const Type& {
153 int res = asptr_meth($input, (Type**)(0));
154 $1 = SWIG_CheckState(res);
159 /*---------------------------------------------------------------------
160 * typemap definition for types with asptr method
161 *---------------------------------------------------------------------*/
163 %define %typemaps_asptr(CheckCode, AsPtrMeth, AsPtrFrag, Type...)
164 %fragment(SWIG_AsVal_frag(Type),"header",fragment=SWIG_AsPtr_frag(Type)) {
166 SWIG_AsVal(Type)(SWIG_Object obj, Type *val)
169 int res = SWIG_AsPtr(Type)(obj, &v);
170 if (!SWIG_IsOK(res)) return res;
173 if (SWIG_IsNewObj(res)) {
175 res = SWIG_DelNewMask(res);
182 %ptr_in_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
183 %ptr_varin_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
184 %ptr_directorout_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
185 %ptr_typecheck_typemap(%arg(CheckCode), %arg(AsPtrMeth),%arg(AsPtrFrag), Type);
186 %ptr_input_typemap(%arg(CheckCode),%arg(AsPtrMeth),%arg(AsPtrFrag),Type);
189 /*---------------------------------------------------------------------
190 * typemap definition for types with asptr/from methods
191 *---------------------------------------------------------------------*/
193 %define %typemaps_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type...)
194 %typemaps_asptr(%arg(CheckCode), %arg(AsPtrMeth), %arg(AsPtrFrag), Type)
195 %typemaps_from(%arg(FromMeth), %arg(FromFrag), Type);
196 %value_output_typemap(%arg(FromMeth), %arg(FromFrag), Type);
197 %ptr_inout_typemap(Type);
200 /*---------------------------------------------------------------------
201 * typemap definition for types with for 'normalized' asptr/from methods
202 *---------------------------------------------------------------------*/
204 %define %typemaps_asptrfromn(CheckCode, Type...)
205 %typemaps_asptrfrom(%arg(CheckCode),
206 %arg(SWIG_AsPtr(Type)),
207 %arg(SWIG_From(Type)),
208 %arg(SWIG_AsPtr_frag(Type)),
209 %arg(SWIG_From_frag(Type)),