PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Lib/typemaps/ptrtypes.swg

#
Unknown | 208 lines | 182 code | 26 blank | 0 comment | 0 complexity | a2eff76ead4e74e0d8972e28af2c3b15 MD5 | raw file
  1/* -----------------------------------------------------------------------------
  2 * ptrtypes.swg
  3 *
  4 * Value typemaps (Type, const Type&) for "Ptr" types, such as swig
  5 * wrapped classes, that define the AsPtr/From methods
  6 *
  7 * To apply them, just use one of the following macros:
  8 *
  9 *    %typemaps_asptr(CheckCode, AsPtrMeth, AsPtrFrag, Type)
 10 *    %typemaps_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type)
 11 *
 12 * or the simpler and normalize form:
 13 *
 14 *    %typemaps_asptrfromn(CheckCode, Type)
 15 *
 16 * Also, you can use the individual typemap definitions:
 17 *
 18 *    %ptr_in_typemap(asptr_meth,frag,Type)
 19 *    %ptr_varin_typemap(asptr_meth,frag,Type)
 20 *    %ptr_typecheck_typemap(check,asptr_meth,frag,Type)
 21 *    %ptr_directorout_typemap(asptr_meth,frag,Type)
 22 * ----------------------------------------------------------------------------- */
 23
 24%include <typemaps/valtypes.swg>
 25
 26/* in */
 27
 28%define %ptr_in_typemap(asptr_meth,frag,Type...)
 29  %typemap(in,fragment=frag) Type {
 30    Type *ptr = (Type *)0;
 31    int res = asptr_meth($input, &ptr);
 32    if (!SWIG_IsOK(res) || !ptr) { 
 33      %argument_fail((ptr ? res : SWIG_TypeError), "$type", $symname, $argnum); 
 34    }
 35    $1 = *ptr;
 36    if (SWIG_IsNewObj(res)) %delete(ptr);
 37  }
 38  %typemap(freearg) Type "";
 39  %typemap(in,fragment=frag) const Type & (int res = SWIG_OLDOBJ) {
 40    Type *ptr = (Type *)0;
 41    res = asptr_meth($input, &ptr);
 42    if (!SWIG_IsOK(res)) { %argument_fail(res,"$type",$symname, $argnum); }
 43    if (!ptr) { %argument_nullref("$type",$symname, $argnum); }
 44    $1 = ptr;
 45  }
 46  %typemap(freearg,noblock=1) const Type &  {
 47    if (SWIG_IsNewObj(res$argnum)) %delete($1);
 48  }
 49%enddef
 50
 51/* varin */
 52
 53%define %ptr_varin_typemap(asptr_meth,frag,Type...)
 54  %typemap(varin,fragment=frag) Type {
 55    Type *ptr = (Type *)0;
 56    int res = asptr_meth($input, &ptr);
 57    if (!SWIG_IsOK(res) || !ptr) { 
 58      %variable_fail((ptr ? res : SWIG_TypeError), "$type", "$name"); 
 59    }
 60    $1 = *ptr;
 61    if (SWIG_IsNewObj(res)) %delete(ptr);
 62  }
 63%enddef
 64
 65#if defined(SWIG_DIRECTOR_TYPEMAPS)
 66/* directorout */
 67
 68%define %ptr_directorout_typemap(asptr_meth,frag,Type...)
 69  %typemap(directorargout,noblock=1,fragment=frag) Type *DIRECTOROUT ($*ltype temp, int swig_ores) {
 70    Type *swig_optr = 0;
 71    swig_ores = $result ? asptr_meth($result, &swig_optr) : 0;
 72    if (!SWIG_IsOK(swig_ores) || !swig_optr) { 
 73      %dirout_fail((swig_optr ? swig_ores : SWIG_TypeError),"$type");
 74    }
 75    temp = *swig_optr;
 76    $1 = &temp;
 77    if (SWIG_IsNewObj(swig_ores)) %delete(swig_optr);
 78  }
 79
 80  %typemap(directorout,noblock=1,fragment=frag) Type {
 81    Type *swig_optr = 0;
 82    int swig_ores = asptr_meth($input, &swig_optr);
 83    if (!SWIG_IsOK(swig_ores) || !swig_optr) { 
 84      %dirout_fail((swig_optr ? swig_ores : SWIG_TypeError),"$type");
 85    }
 86    $result = *swig_optr;
 87    if (SWIG_IsNewObj(swig_ores)) %delete(swig_optr);
 88  }
 89
 90  %typemap(directorout,noblock=1,fragment=frag,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Type* {
 91    Type *swig_optr = 0;
 92    int swig_ores = asptr_meth($input, &swig_optr);
 93    if (!SWIG_IsOK(swig_ores)) { 
 94      %dirout_fail(swig_ores,"$type");
 95    }    
 96    $result = swig_optr;
 97    if (SWIG_IsNewObj(swig_ores)) {
 98      swig_acquire_ownership(swig_optr);
 99    }
100  }
101  %typemap(directorfree,noblock=1) Type*
102  {
103    if (director)  {
104      director->swig_release_ownership(%as_voidptr($input));
105    }
106  }
107
108  %typemap(directorout,noblock=1,fragment=frag,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Type& {
109    Type *swig_optr = 0;
110    int swig_ores = asptr_meth($input, &swig_optr);
111    if (!SWIG_IsOK(swig_ores)) { 
112      %dirout_fail(swig_ores,"$type");
113    } else {
114      if (!swig_optr) { 
115	%dirout_nullref("$type");
116      } 
117    }    
118    $result = swig_optr;
119    if (SWIG_IsNewObj(swig_ores)) {
120      swig_acquire_ownership(swig_optr);
121    }
122  }
123  %typemap(directorfree,noblock=1) Type&
124  {
125    if (director) {
126      director->swig_release_ownership(%as_voidptr($input));
127    }
128  }
129
130
131  %typemap(directorout,fragment=frag) Type &DIRECTOROUT = Type
132
133%enddef
134
135#else
136
137#define %ptr_directorout_typemap(asptr_meth,frag,Type...) 
138
139#endif /* SWIG_DIRECTOR_TYPEMAPS */
140
141/* typecheck */
142
143%define %ptr_typecheck_typemap(check,asptr_meth,frag,Type...)
144%typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type * {
145  int res = asptr_meth($input, (Type**)(0));
146  $1 = SWIG_CheckState(res);
147}
148
149%typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type, const Type& {  
150  int res = asptr_meth($input, (Type**)(0));
151  $1 = SWIG_CheckState(res);
152}
153%enddef
154
155
156/*---------------------------------------------------------------------
157 * typemap definition for types with asptr method
158 *---------------------------------------------------------------------*/
159
160%define %typemaps_asptr(CheckCode, AsPtrMeth, AsPtrFrag, Type...)
161  %fragment(SWIG_AsVal_frag(Type),"header",fragment=SWIG_AsPtr_frag(Type)) {
162    SWIGINTERNINLINE int
163    SWIG_AsVal(Type)(SWIG_Object obj, Type *val)
164    {
165      Type *v = (Type *)0;
166      int res = SWIG_AsPtr(Type)(obj, &v);
167      if (!SWIG_IsOK(res)) return res;
168      if (v) {
169	if (val) *val = *v;
170	if (SWIG_IsNewObj(res)) {
171	  %delete(v);
172	  res = SWIG_DelNewMask(res);
173	}
174	return res;
175      }
176      return SWIG_ERROR;
177    }
178  }
179  %ptr_in_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
180  %ptr_varin_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
181  %ptr_directorout_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
182  %ptr_typecheck_typemap(%arg(CheckCode), %arg(AsPtrMeth),%arg(AsPtrFrag), Type);
183  %ptr_input_typemap(%arg(CheckCode),%arg(AsPtrMeth),%arg(AsPtrFrag),Type);
184%enddef
185
186/*---------------------------------------------------------------------
187 * typemap definition for types with asptr/from methods
188 *---------------------------------------------------------------------*/
189
190%define %typemaps_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type...)
191  %typemaps_asptr(%arg(CheckCode), %arg(AsPtrMeth), %arg(AsPtrFrag), Type)
192  %typemaps_from(%arg(FromMeth), %arg(FromFrag), Type);
193  %value_output_typemap(%arg(FromMeth), %arg(FromFrag), Type);
194  %ptr_inout_typemap(Type);
195%enddef
196
197/*---------------------------------------------------------------------
198 * typemap definition for types  with for 'normalized' asptr/from methods
199 *---------------------------------------------------------------------*/
200
201%define %typemaps_asptrfromn(CheckCode, Type...)
202%typemaps_asptrfrom(%arg(CheckCode),
203		   %arg(SWIG_AsPtr(Type)), 
204		   %arg(SWIG_From(Type)), 
205		   %arg(SWIG_AsPtr_frag(Type)), 
206		   %arg(SWIG_From_frag(Type)), 
207		   Type);
208%enddef