added support for const, like std::pair<const int, int>

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5815 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-04-01 04:07:27 +00:00
commit 5822020fc7
2 changed files with 37 additions and 16 deletions

View file

@ -158,6 +158,19 @@ namespace swigpy {
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>
struct traits_asval
{
@ -167,7 +180,8 @@ namespace swigpy {
value_type *p = 0;
int res = asptr(obj, &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;
return true;
} else {

View file

@ -8,23 +8,30 @@
fragment="StdTraits",fragment="PyObject_var") {
namespace swigpy {
template <class T, class U >
struct traits_asval<std::pair<T,U> > {
static int asval(PyObject *obj, std::pair<T,U> *val) {
struct traits_asptr<std::pair<T,U> > {
static int asptr(PyObject *obj, std::pair<T,U> **val) {
typedef std::pair<T,U> value_type;
if (PySequence_Check(obj) && (PySequence_Size(obj) == 2)) {
swigpy::PyObject_var first = PySequence_GetItem(obj,0);
swigpy::PyObject_var second = PySequence_GetItem(obj,1);
T *pfirst = val ? &(val->first) : 0;
U *psecond = val ? &(val->second) : 0;
T *pfirst = 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)) {
return 1;
return SWIG_NEWOBJ;
} else {
delete *val;
}
} else {
value_type *p;
if (SWIG_ConvertPtr(obj,(void**)&p,
swigpy::type_info<value_type>(),0) != -1) {
if (val) *val = *p;
return 1;
if (val) *val = p;
return SWIG_OLDOBJ;
}
}
if (val) {
@ -61,7 +68,7 @@ namespace std {
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T,U > > {
typedef value_category category;
typedef pointer_category category;
static const char* type_name() {
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(const T& __a, const U& __b);
pair(T __a, U __b);
pair(const pair& __p);
T first;
@ -102,7 +109,7 @@ namespace std {
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T,U* > > {
typedef value_category category;
typedef pointer_category category;
static const char* type_name() {
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(const T& __a, U* __b);
@ -131,7 +138,7 @@ namespace std {
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T*,U > > {
typedef value_category category;
typedef pointer_category category;
static const char* type_name() {
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(T* __a, const U& __b);
@ -157,7 +164,7 @@ namespace std {
fragment="StdPairTraits") {
namespace swigpy {
template <> struct traits<std::pair<T*,U* > > {
typedef value_category category;
typedef pointer_category category;
static const char* type_name() {
return "std::pair<" #T *"," #U " * >";
}