1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/*
The %implicit macro allows a SwigType (Class) to be accepted
as an input parameter and use its implicit constructors when needed.
For example:
%implicit(A, int, double, B);
%inline
{
struct B { };
struct A
{
int ii;
A(int i) { ii = 1; }
A(double d) { ii = 2; }
A(const B& b) { ii = 3; }
};
int get(A a) { return a.ii; }
}
Here, you can call 'get' as
get(1) ==> get(A(1))
get(2.0) ==> get(A(2.0))
get(B()) ==> get(A(B()))
and swig will construct an 'A' temporal variable using the
corresponding implicit constructor.
The plain implicit macro takes care of simple type list. If it doesn't
work because you are passing template types with commas, then use
the %implicit_{1,2,3} versions and/or the %arg macro.
*/
%define %implicit_type(Type...)
%traits_swigtype(Type);
%enddef
%define %implicit_frag(Type...) ,fragment=SWIG_Traits_frag(Type) %enddef
%define %implicit_code(Type...)
{
Type _v;
int res = swig::asval<Type >(obj, &_v);
if (SWIG_IsOK(res)) {
if (val) *val = new value_type(static_cast<const Type& >(_v));
return SWIG_AddNewMask(res);
}
}
%enddef
/* implicit */
%define %implicit(Type, ...)
%formacro_1(%implicit_type,__VA_ARGS__);
%fragment(SWIG_Traits_frag(Type),"header",
fragment="StdTraits"
%formacro_1(%implicit_frag,__VA_ARGS__)) %{
namespace swig {
template <> struct traits<Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }
};
template <> struct traits_asptr< Type > {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return res;
} else {
%formacro_1(%implicit_code,__VA_ARGS__)
}
return SWIG_TypeError;
}
};
}
%}
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef
/* implicit_1 */
%define %implicit_1(Type, Imp1)
%traits_swigtype(Imp1);
%fragment(SWIG_Traits_frag(Type),"header",
fragment="StdTraits",
fragment=SWIG_Traits_frag(Imp1)) %{
namespace swig {
template <> struct traits< Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }
};
template <> struct traits_asptr< Type > {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return res;
} else {
%implicit_code(Imp1);
}
return SWIG_TypeError;
}
};
}
%}
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef
/* implicit_2 */
%define %implicit_2(Type, Imp1, Imp2)
%traits_swigtype(Imp1);
%traits_swigtype(Imp2);
%fragment(SWIG_Traits_frag(Type),"header",
fragment="StdTraits",
fragment=SWIG_Traits_frag(Imp1),
fragment=SWIG_Traits_frag(Imp2)) %{
namespace swig {
template <> struct traits< Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }
};
template <> struct traits_asptr< Type > {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
} else {
%implicit_code(Imp1);
%implicit_code(Imp2);
}
return SWIG_TypeError;
}
};
}
%}
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef
/* implicit_3 */
%define %implicit_3(Type, Imp1, Imp2, Imp3)
%traits_swigtype(Imp1);
%traits_swigtype(Imp2);
%traits_swigtype(Imp3);
%fragment(SWIG_Traits_frag(Type),"header",
fragment="StdTraits",
fragment=SWIG_Traits_frag(Imp1),
fragment=SWIG_Traits_frag(Imp2),
fragment=SWIG_Traits_frag(Imp3)) %{
namespace swig {
template <> struct traits< Type > {
typedef pointer_category category;
static const char* type_name() { return "Type"; }
};
template <> struct traits_asptr< Type > {
typedef Type value_type;
static int asptr(SWIG_Object obj, value_type **val) {
Type *vptr;
static swig_type_info* descriptor = SWIG_TypeQuery("Type *");
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&vptr, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res)) {
if (val) *val = vptr;
return res;
} else {
%implicit_code(Imp1);
%implicit_code(Imp2);
%implicit_code(Imp3);
}
return SWIG_TypeError;
}
};
}
%}
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef
|