add faster pair typemap
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7994 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
1f2953ccdd
commit
aa3e2ea2d3
3 changed files with 46 additions and 25 deletions
|
|
@ -57,7 +57,7 @@ namespace swig {
|
||||||
static int asval(PyObject *obj, Type *val) {
|
static int asval(PyObject *obj, Type *val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
Type *p = 0;
|
Type *p = 0;
|
||||||
int res = traits_asptr<Type>::asptr(obj, &p);
|
int res = traits_asptr<Type>::asptr(obj, (val ? &p : 0));
|
||||||
if ((res != 0) && p) {
|
if ((res != 0) && p) {
|
||||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||||
*(const_cast<noconst_type*>(val)) = *p;
|
*(const_cast<noconst_type*>(val)) = *p;
|
||||||
|
|
@ -77,7 +77,7 @@ namespace swig {
|
||||||
if (val) {
|
if (val) {
|
||||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||||
noconst_type *p = 0;
|
noconst_type *p = 0;
|
||||||
int res = traits_asptr<noconst_type>::asptr(obj, &p);
|
int res = traits_asptr<noconst_type>::asptr(obj, (val ? &p : 0));
|
||||||
if (res) {
|
if (res) {
|
||||||
*(const_cast<noconst_type**>(val)) = p;
|
*(const_cast<noconst_type**>(val)) = p;
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
|
|
|
||||||
|
|
@ -7,38 +7,58 @@
|
||||||
namespace swig {
|
namespace swig {
|
||||||
template <class T, class U >
|
template <class T, class U >
|
||||||
struct traits_asptr<std::pair<T,U> > {
|
struct traits_asptr<std::pair<T,U> > {
|
||||||
static int asptr(PyObject *obj, std::pair<T,U> **val) {
|
typedef std::pair<T,U> value_type;
|
||||||
typedef std::pair<T,U> value_type;
|
|
||||||
if (PySequence_Check(obj) && (PySequence_Size(obj) == 2)) {
|
static int get_pair(PyObject* first, PyObject* second,
|
||||||
swig::PyObject_var first = PySequence_GetItem(obj,0);
|
std::pair<T,U> **val)
|
||||||
swig::PyObject_var second = PySequence_GetItem(obj,1);
|
{
|
||||||
T *pfirst = 0;
|
if (val) {
|
||||||
U *psecond = 0;
|
value_type *vp = %new_instance(std::pair<T,U>);
|
||||||
value_type *vp = 0;
|
T *pfirst = &(vp->first);
|
||||||
if (val) {
|
U *psecond = &(vp->second);
|
||||||
vp = %new_instance(std::pair<T,U>);
|
if ((swig::asval((PyObject*)first, pfirst) == SWIG_OK)
|
||||||
pfirst = &(vp->first);
|
&& (swig::asval((PyObject*)second, psecond) == SWIG_OK)) {
|
||||||
psecond = &(vp->second);
|
*val = vp;
|
||||||
}
|
|
||||||
if ((swig::asval(first,pfirst) == SWIG_OK) && (swig::asval(second,psecond) == SWIG_OK)) {
|
|
||||||
if (val) *val = vp;
|
|
||||||
return SWIG_NEWOBJ;
|
return SWIG_NEWOBJ;
|
||||||
} else {
|
} else {
|
||||||
%delete(vp);
|
%delete(vp);
|
||||||
|
return SWIG_BADOBJ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
T *pfirst = 0;
|
||||||
|
U *psecond = 0;
|
||||||
|
if ((swig::asval((PyObject*)first, pfirst) == SWIG_OK)
|
||||||
|
&& (swig::asval((PyObject*)second, psecond) == SWIG_OK)) {
|
||||||
|
return SWIG_NEWOBJ;
|
||||||
|
} else {
|
||||||
|
return SWIG_BADOBJ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int asptr(PyObject *obj, std::pair<T,U> **val) {
|
||||||
|
int res = SWIG_BADOBJ;
|
||||||
|
if (PyTuple_Check(obj)) {
|
||||||
|
if (PyTuple_GET_SIZE(obj) == 2) {
|
||||||
|
res = get_pair(PyTuple_GET_ITEM(obj,0),PyTuple_GET_ITEM(obj,1), val);
|
||||||
|
}
|
||||||
|
} else if (PySequence_Check(obj)) {
|
||||||
|
if (PySequence_Size(obj) == 2) {
|
||||||
|
swig::PyObject_var first = PySequence_GetItem(obj,0);
|
||||||
|
swig::PyObject_var second = PySequence_GetItem(obj,1);
|
||||||
|
res = get_pair(first, second, val);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value_type *p;
|
value_type *p;
|
||||||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
if (SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0) == SWIG_OK) {
|
||||||
swig::type_info<value_type>(),0) != -1) {
|
|
||||||
if (val) *val = p;
|
if (val) *val = p;
|
||||||
return SWIG_OLDOBJ;
|
res = SWIG_OLDOBJ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val) {
|
if ((res == SWIG_BADOBJ) && val) {
|
||||||
PyErr_Format(PyExc_TypeError, "a %s is expected",
|
PyErr_Format(PyExc_TypeError, "a %s is expected", swig::type_name<value_type>());
|
||||||
swig::type_name<value_type>());
|
|
||||||
}
|
}
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@
|
||||||
#define SWIG_POINTER_OWN 0x1
|
#define SWIG_POINTER_OWN 0x1
|
||||||
|
|
||||||
/* Alloc. memory flags */
|
/* Alloc. memory flags */
|
||||||
|
#define SWIG_BADOBJ 0
|
||||||
#define SWIG_OLDOBJ 1
|
#define SWIG_OLDOBJ 1
|
||||||
#define SWIG_NEWOBJ 2
|
#define SWIG_NEWOBJ 2
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue