PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/typemaps/ptrtypes.swg

#
Unknown | 208 lines | 182 code | 26 blank | 0 comment | 0 complexity | a2eff76ead4e74e0d8972e28af2c3b15 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. %include <typemaps/valtypes.swg>
  24. /* in */
  25. %define %ptr_in_typemap(asptr_meth,frag,Type...)
  26. %typemap(in,fragment=frag) Type {
  27. Type *ptr = (Type *)0;
  28. int res = asptr_meth($input, &ptr);
  29. if (!SWIG_IsOK(res) || !ptr) {
  30. %argument_fail((ptr ? res : SWIG_TypeError), "$type", $symname, $argnum);
  31. }
  32. $1 = *ptr;
  33. if (SWIG_IsNewObj(res)) %delete(ptr);
  34. }
  35. %typemap(freearg) Type "";
  36. %typemap(in,fragment=frag) const Type & (int res = SWIG_OLDOBJ) {
  37. Type *ptr = (Type *)0;
  38. res = asptr_meth($input, &ptr);
  39. if (!SWIG_IsOK(res)) { %argument_fail(res,"$type",$symname, $argnum); }
  40. if (!ptr) { %argument_nullref("$type",$symname, $argnum); }
  41. $1 = ptr;
  42. }
  43. %typemap(freearg,noblock=1) const Type & {
  44. if (SWIG_IsNewObj(res$argnum)) %delete($1);
  45. }
  46. %enddef
  47. /* varin */
  48. %define %ptr_varin_typemap(asptr_meth,frag,Type...)
  49. %typemap(varin,fragment=frag) Type {
  50. Type *ptr = (Type *)0;
  51. int res = asptr_meth($input, &ptr);
  52. if (!SWIG_IsOK(res) || !ptr) {
  53. %variable_fail((ptr ? res : SWIG_TypeError), "$type", "$name");
  54. }
  55. $1 = *ptr;
  56. if (SWIG_IsNewObj(res)) %delete(ptr);
  57. }
  58. %enddef
  59. #if defined(SWIG_DIRECTOR_TYPEMAPS)
  60. /* directorout */
  61. %define %ptr_directorout_typemap(asptr_meth,frag,Type...)
  62. %typemap(directorargout,noblock=1,fragment=frag) Type *DIRECTOROUT ($*ltype temp, int swig_ores) {
  63. Type *swig_optr = 0;
  64. swig_ores = $result ? asptr_meth($result, &swig_optr) : 0;
  65. if (!SWIG_IsOK(swig_ores) || !swig_optr) {
  66. %dirout_fail((swig_optr ? swig_ores : SWIG_TypeError),"$type");
  67. }
  68. temp = *swig_optr;
  69. $1 = &temp;
  70. if (SWIG_IsNewObj(swig_ores)) %delete(swig_optr);
  71. }
  72. %typemap(directorout,noblock=1,fragment=frag) Type {
  73. Type *swig_optr = 0;
  74. int swig_ores = asptr_meth($input, &swig_optr);
  75. if (!SWIG_IsOK(swig_ores) || !swig_optr) {
  76. %dirout_fail((swig_optr ? swig_ores : SWIG_TypeError),"$type");
  77. }
  78. $result = *swig_optr;
  79. if (SWIG_IsNewObj(swig_ores)) %delete(swig_optr);
  80. }
  81. %typemap(directorout,noblock=1,fragment=frag,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Type* {
  82. Type *swig_optr = 0;
  83. int swig_ores = asptr_meth($input, &swig_optr);
  84. if (!SWIG_IsOK(swig_ores)) {
  85. %dirout_fail(swig_ores,"$type");
  86. }
  87. $result = swig_optr;
  88. if (SWIG_IsNewObj(swig_ores)) {
  89. swig_acquire_ownership(swig_optr);
  90. }
  91. }
  92. %typemap(directorfree,noblock=1) Type*
  93. {
  94. if (director) {
  95. director->swig_release_ownership(%as_voidptr($input));
  96. }
  97. }
  98. %typemap(directorout,noblock=1,fragment=frag,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) Type& {
  99. Type *swig_optr = 0;
  100. int swig_ores = asptr_meth($input, &swig_optr);
  101. if (!SWIG_IsOK(swig_ores)) {
  102. %dirout_fail(swig_ores,"$type");
  103. } else {
  104. if (!swig_optr) {
  105. %dirout_nullref("$type");
  106. }
  107. }
  108. $result = swig_optr;
  109. if (SWIG_IsNewObj(swig_ores)) {
  110. swig_acquire_ownership(swig_optr);
  111. }
  112. }
  113. %typemap(directorfree,noblock=1) Type&
  114. {
  115. if (director) {
  116. director->swig_release_ownership(%as_voidptr($input));
  117. }
  118. }
  119. %typemap(directorout,fragment=frag) Type &DIRECTOROUT = Type
  120. %enddef
  121. #else
  122. #define %ptr_directorout_typemap(asptr_meth,frag,Type...)
  123. #endif /* SWIG_DIRECTOR_TYPEMAPS */
  124. /* typecheck */
  125. %define %ptr_typecheck_typemap(check,asptr_meth,frag,Type...)
  126. %typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type * {
  127. int res = asptr_meth($input, (Type**)(0));
  128. $1 = SWIG_CheckState(res);
  129. }
  130. %typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type, const Type& {
  131. int res = asptr_meth($input, (Type**)(0));
  132. $1 = SWIG_CheckState(res);
  133. }
  134. %enddef
  135. /*---------------------------------------------------------------------
  136. * typemap definition for types with asptr method
  137. *---------------------------------------------------------------------*/
  138. %define %typemaps_asptr(CheckCode, AsPtrMeth, AsPtrFrag, Type...)
  139. %fragment(SWIG_AsVal_frag(Type),"header",fragment=SWIG_AsPtr_frag(Type)) {
  140. SWIGINTERNINLINE int
  141. SWIG_AsVal(Type)(SWIG_Object obj, Type *val)
  142. {
  143. Type *v = (Type *)0;
  144. int res = SWIG_AsPtr(Type)(obj, &v);
  145. if (!SWIG_IsOK(res)) return res;
  146. if (v) {
  147. if (val) *val = *v;
  148. if (SWIG_IsNewObj(res)) {
  149. %delete(v);
  150. res = SWIG_DelNewMask(res);
  151. }
  152. return res;
  153. }
  154. return SWIG_ERROR;
  155. }
  156. }
  157. %ptr_in_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
  158. %ptr_varin_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
  159. %ptr_directorout_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
  160. %ptr_typecheck_typemap(%arg(CheckCode), %arg(AsPtrMeth),%arg(AsPtrFrag), Type);
  161. %ptr_input_typemap(%arg(CheckCode),%arg(AsPtrMeth),%arg(AsPtrFrag),Type);
  162. %enddef
  163. /*---------------------------------------------------------------------
  164. * typemap definition for types with asptr/from methods
  165. *---------------------------------------------------------------------*/
  166. %define %typemaps_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type...)
  167. %typemaps_asptr(%arg(CheckCode), %arg(AsPtrMeth), %arg(AsPtrFrag), Type)
  168. %typemaps_from(%arg(FromMeth), %arg(FromFrag), Type);
  169. %value_output_typemap(%arg(FromMeth), %arg(FromFrag), Type);
  170. %ptr_inout_typemap(Type);
  171. %enddef
  172. /*---------------------------------------------------------------------
  173. * typemap definition for types with for 'normalized' asptr/from methods
  174. *---------------------------------------------------------------------*/
  175. %define %typemaps_asptrfromn(CheckCode, Type...)
  176. %typemaps_asptrfrom(%arg(CheckCode),
  177. %arg(SWIG_AsPtr(Type)),
  178. %arg(SWIG_From(Type)),
  179. %arg(SWIG_AsPtr_frag(Type)),
  180. %arg(SWIG_From_frag(Type)),
  181. Type);
  182. %enddef