added support for const, like std::pair<const int, int>
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5815 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
be560544f5
commit
0c8f4b34bf
2 changed files with 37 additions and 16 deletions
|
|
@ -158,6 +158,19 @@ namespace swigpy {
|
||||||
return traits_asptr<Type>::asptr(obj, vptr);
|
return traits_asptr<Type>::asptr(obj, vptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Type>
|
||||||
|
struct noconst_traits
|
||||||
|
{
|
||||||
|
typedef Type noconst_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <class Type>
|
||||||
|
struct noconst_traits<const Type>
|
||||||
|
{
|
||||||
|
typedef Type noconst_type;
|
||||||
|
};
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_asval
|
struct traits_asval
|
||||||
{
|
{
|
||||||
|
|
@ -167,7 +180,8 @@ namespace swigpy {
|
||||||
value_type *p = 0;
|
value_type *p = 0;
|
||||||
int res = asptr(obj, &p);
|
int res = asptr(obj, &p);
|
||||||
if (res && p) {
|
if (res && p) {
|
||||||
*val = *p;
|
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||||
|
*((noconst_type*)(val)) = *p;
|
||||||
if (res == SWIG_NEWOBJ) delete p;
|
if (res == SWIG_NEWOBJ) delete p;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,30 @@
|
||||||
fragment="StdTraits",fragment="PyObject_var") {
|
fragment="StdTraits",fragment="PyObject_var") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <class T, class U >
|
template <class T, class U >
|
||||||
struct traits_asval<std::pair<T,U> > {
|
struct traits_asptr<std::pair<T,U> > {
|
||||||
static int asval(PyObject *obj, std::pair<T,U> *val) {
|
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)) {
|
if (PySequence_Check(obj) && (PySequence_Size(obj) == 2)) {
|
||||||
swigpy::PyObject_var first = PySequence_GetItem(obj,0);
|
swigpy::PyObject_var first = PySequence_GetItem(obj,0);
|
||||||
swigpy::PyObject_var second = PySequence_GetItem(obj,1);
|
swigpy::PyObject_var second = PySequence_GetItem(obj,1);
|
||||||
T *pfirst = val ? &(val->first) : 0;
|
T *pfirst = 0;
|
||||||
U *psecond = val ? &(val->second) : 0;
|
U *psecond = 0;
|
||||||
|
if (val) {
|
||||||
|
*val = new std::pair<T,U>;
|
||||||
|
pfirst = &((*val)->first);
|
||||||
|
psecond = &((*val)->second);
|
||||||
|
}
|
||||||
if (swigpy::asval(first,pfirst) && swigpy::asval(second,psecond)) {
|
if (swigpy::asval(first,pfirst) && swigpy::asval(second,psecond)) {
|
||||||
return 1;
|
return SWIG_NEWOBJ;
|
||||||
|
} else {
|
||||||
|
delete *val;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value_type *p;
|
value_type *p;
|
||||||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||||
swigpy::type_info<value_type>(),0) != -1) {
|
swigpy::type_info<value_type>(),0) != -1) {
|
||||||
if (val) *val = *p;
|
if (val) *val = p;
|
||||||
return 1;
|
return SWIG_OLDOBJ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val) {
|
if (val) {
|
||||||
|
|
@ -61,7 +68,7 @@ namespace std {
|
||||||
fragment="StdPairTraits") {
|
fragment="StdPairTraits") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <> struct traits<std::pair<T,U > > {
|
template <> struct traits<std::pair<T,U > > {
|
||||||
typedef value_category category;
|
typedef pointer_category category;
|
||||||
static const char* type_name() {
|
static const char* type_name() {
|
||||||
return "std::pair<" #T "," #U " >";
|
return "std::pair<" #T "," #U " >";
|
||||||
}
|
}
|
||||||
|
|
@ -69,10 +76,10 @@ namespace std {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap_traits(SWIG_CCode(PAIR), std::pair<T,U >);
|
%typemap_traits_ptr(SWIG_CCode(PAIR), std::pair<T,U >);
|
||||||
|
|
||||||
pair();
|
pair();
|
||||||
pair(const T& __a, const U& __b);
|
pair(T __a, U __b);
|
||||||
pair(const pair& __p);
|
pair(const pair& __p);
|
||||||
|
|
||||||
T first;
|
T first;
|
||||||
|
|
@ -102,7 +109,7 @@ namespace std {
|
||||||
fragment="StdPairTraits") {
|
fragment="StdPairTraits") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <> struct traits<std::pair<T,U* > > {
|
template <> struct traits<std::pair<T,U* > > {
|
||||||
typedef value_category category;
|
typedef pointer_category category;
|
||||||
static const char* type_name() {
|
static const char* type_name() {
|
||||||
return "std::pair<" #T "," #U " * >";
|
return "std::pair<" #T "," #U " * >";
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +117,7 @@ namespace std {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap_traits(SWIG_CCode(PAIR), std::pair<T,U* >);
|
%typemap_traits_ptr(SWIG_CCode(PAIR), std::pair<T,U* >);
|
||||||
|
|
||||||
pair();
|
pair();
|
||||||
pair(const T& __a, U* __b);
|
pair(const T& __a, U* __b);
|
||||||
|
|
@ -131,7 +138,7 @@ namespace std {
|
||||||
fragment="StdPairTraits") {
|
fragment="StdPairTraits") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <> struct traits<std::pair<T*,U > > {
|
template <> struct traits<std::pair<T*,U > > {
|
||||||
typedef value_category category;
|
typedef pointer_category category;
|
||||||
static const char* type_name() {
|
static const char* type_name() {
|
||||||
return "std::pair<" #T *"," #U " >";
|
return "std::pair<" #T *"," #U " >";
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +146,7 @@ namespace std {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap_traits(SWIG_CCode(PAIR), std::pair<T*,U >);
|
%typemap_traits_ptr(SWIG_CCode(PAIR), std::pair<T*,U >);
|
||||||
|
|
||||||
pair();
|
pair();
|
||||||
pair(T* __a, const U& __b);
|
pair(T* __a, const U& __b);
|
||||||
|
|
@ -157,7 +164,7 @@ namespace std {
|
||||||
fragment="StdPairTraits") {
|
fragment="StdPairTraits") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <> struct traits<std::pair<T*,U* > > {
|
template <> struct traits<std::pair<T*,U* > > {
|
||||||
typedef value_category category;
|
typedef pointer_category category;
|
||||||
static const char* type_name() {
|
static const char* type_name() {
|
||||||
return "std::pair<" #T *"," #U " * >";
|
return "std::pair<" #T *"," #U " * >";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue