fix pair for ptrs, and add SWIG_STD_NOEXTEND_COMPARISON to reduce swig times
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5820 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
1c1f6acf4c
commit
b85f90a6ed
9 changed files with 75 additions and 43 deletions
|
|
@ -14,10 +14,10 @@
|
||||||
//#define SWIG_STD_DEFAULT_INSTANTIATION
|
//#define SWIG_STD_DEFAULT_INSTANTIATION
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use the following macro to enable the generation of the comparison
|
// Use the following macro to disable the generation of the comparison
|
||||||
// methods, ie, ==, !=, <=, >=, <,>, whenever is needed.
|
// methods, ie, ==, !=, <=, >=, <,>, whenever is needed.
|
||||||
//
|
//
|
||||||
#define SWIG_STD_EXTEND_COMPARISON
|
//#define SWIG_STD_NOEXTEND_COMPARISON
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -112,14 +112,21 @@ namespace swigpy {
|
||||||
/*
|
/*
|
||||||
Traits that provides the from method
|
Traits that provides the from method
|
||||||
*/
|
*/
|
||||||
template <class Type> struct traits_from {
|
template <class Type> struct traits_from_ptr {
|
||||||
typedef Type value_type;
|
static PyObject *from(Type *val, int owner = 0) {
|
||||||
static PyObject *from(value_type *val, int owner = 0) {
|
return SWIG_NewPointerObj(val, type_info<Type>(), owner);
|
||||||
return SWIG_NewPointerObj(val, type_info<value_type>(), owner);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static PyObject *from(const value_type& val) {
|
template <class Type> struct traits_from {
|
||||||
return traits_from<Type>::from(new value_type(val), 1);
|
static PyObject *from(const Type& val) {
|
||||||
|
return traits_from_ptr<Type>::from(new Type(val), 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Type> struct traits_from<Type *> {
|
||||||
|
static PyObject *from(Type* val) {
|
||||||
|
return traits_from_ptr<Type>::from(val, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -129,8 +136,8 @@ namespace swigpy {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline PyObject *from(Type* val, int owner = 0) {
|
inline PyObject *from_ptr(Type* val, int owner) {
|
||||||
return traits_from<Type>::from(val, owner);
|
return traits_from_ptr<Type>::from(val, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -138,11 +145,10 @@ namespace swigpy {
|
||||||
*/
|
*/
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_asptr {
|
struct traits_asptr {
|
||||||
typedef Type value_type;
|
static int asptr(PyObject *obj, Type **val) {
|
||||||
static int asptr(PyObject *obj, value_type **val) {
|
Type *p;
|
||||||
value_type *p;
|
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) != -1)
|
||||||
int res = (SWIG_ConvertPtr(obj, (void**)&p,
|
? SWIG_OLDOBJ : 0;
|
||||||
type_info<value_type>(), 0) != -1) ? 1 : 0;
|
|
||||||
if (res) {
|
if (res) {
|
||||||
if (val) *val = p;
|
if (val) *val = p;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -174,25 +180,45 @@ namespace swigpy {
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_asval
|
struct traits_asval
|
||||||
{
|
{
|
||||||
typedef Type value_type;
|
static bool asval(PyObject *obj, Type *val) {
|
||||||
static bool asval(PyObject *obj, value_type *val) {
|
|
||||||
if (val) {
|
if (val) {
|
||||||
value_type *p = 0;
|
Type *p = 0;
|
||||||
int res = asptr(obj, &p);
|
int res = asptr(obj, &p);
|
||||||
if (res && p) {
|
if (res && p) {
|
||||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||||
*((noconst_type*)(val)) = *p;
|
*(const_cast<noconst_type*>(val)) = *p;
|
||||||
if (res == SWIG_NEWOBJ) delete p;
|
if (res == SWIG_NEWOBJ) delete p;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return asptr(obj, (value_type **)(0));
|
return asptr(obj, (Type **)(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <class Type> struct traits_asval<Type*>
|
||||||
|
{
|
||||||
|
static bool asval(PyObject *obj, Type **val) {
|
||||||
|
if (val) {
|
||||||
|
Type *p = 0;
|
||||||
|
int res = asptr(obj, &p);
|
||||||
|
if (res) {
|
||||||
|
typedef typename noconst_traits<Type*>::noconst_type noconst_type;
|
||||||
|
*(const_cast<noconst_type*>(val)) = p;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return asptr(obj, (Type **)(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline bool asval(PyObject *obj, Type *val) {
|
inline bool asval(PyObject *obj, Type *val) {
|
||||||
return traits_asval<Type>::asval(obj, val);
|
return traits_asval<Type>::asval(obj, val);
|
||||||
|
|
@ -206,9 +232,8 @@ namespace swigpy {
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_as<Type, value_category>
|
struct traits_as<Type, value_category>
|
||||||
{
|
{
|
||||||
typedef Type value_type;
|
static Type as(PyObject *obj, bool throw_error) {
|
||||||
static value_type as(PyObject *obj, bool throw_error) {
|
Type v;
|
||||||
value_type v;
|
|
||||||
if (!obj || !asval(obj, &v)) {
|
if (!obj || !asval(obj, &v)) {
|
||||||
std::string msg = "a value of type '";
|
std::string msg = "a value of type '";
|
||||||
msg += swigpy::type_name<Type>();
|
msg += swigpy::type_name<Type>();
|
||||||
|
|
@ -225,13 +250,12 @@ namespace swigpy {
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_as<Type, pointer_category>
|
struct traits_as<Type, pointer_category>
|
||||||
{
|
{
|
||||||
typedef Type value_type;
|
static Type as(PyObject *obj, bool throw_error) {
|
||||||
static value_type as(PyObject *obj, bool throw_error) {
|
Type *v = 0;
|
||||||
value_type *v = 0;
|
|
||||||
int res = (obj ? asptr(obj, &v) : 0) && v;
|
int res = (obj ? asptr(obj, &v) : 0) && v;
|
||||||
if (res) {
|
if (res) {
|
||||||
if (res == SWIG_NEWOBJ) {
|
if (res == SWIG_NEWOBJ) {
|
||||||
value_type r(*v);
|
Type r(*v);
|
||||||
delete v;
|
delete v;
|
||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -239,7 +263,7 @@ namespace swigpy {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Uninitialized return value, no Type() constructor required.
|
// Uninitialized return value, no Type() constructor required.
|
||||||
static value_type *v_def = (Type*) malloc(sizeof(Type));
|
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||||
std::string msg = "a value of type '";
|
std::string msg = "a value of type '";
|
||||||
msg += swigpy::type_name<Type>();
|
msg += swigpy::type_name<Type>();
|
||||||
msg += "' is expected";
|
msg += "' is expected";
|
||||||
|
|
@ -265,18 +289,16 @@ namespace swigpy {
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_check<Type, value_category>
|
struct traits_check<Type, value_category>
|
||||||
{
|
{
|
||||||
typedef Type value_type;
|
|
||||||
static bool check(PyObject *obj) {
|
static bool check(PyObject *obj) {
|
||||||
return obj && asval(obj, (value_type *)(0));
|
return obj && asval(obj, (Type *)(0));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_check<Type, pointer_category>
|
struct traits_check<Type, pointer_category>
|
||||||
{
|
{
|
||||||
typedef Type value_type;
|
|
||||||
static bool check(PyObject *obj) {
|
static bool check(PyObject *obj) {
|
||||||
return obj && asptr(obj, (value_type **)(0));
|
return obj && asptr(obj, (Type **)(0));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -322,6 +344,7 @@ namespace swigpy {
|
||||||
}
|
}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Generate the traits for a 'primitive' type, such as 'double',
|
Generate the traits for a 'primitive' type, such as 'double',
|
||||||
for which the SWIG_AsVal and SWIG_From methods are already defined.
|
for which the SWIG_AsVal and SWIG_From methods are already defined.
|
||||||
|
|
@ -436,7 +459,7 @@ namespace swigpy {
|
||||||
%std_order_methods(__VA_ARGS__ )
|
%std_order_methods(__VA_ARGS__ )
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#ifdef SWIG_STD_EXTEND_COMPARISON
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON)
|
||||||
%define %std_extcomp(Class,T)
|
%define %std_extcomp(Class,T)
|
||||||
%evalif(SWIG_EqualType(T), %std_equal_methods(std::Class<T >))
|
%evalif(SWIG_EqualType(T), %std_equal_methods(std::Class<T >))
|
||||||
%evalif(SWIG_OrderType(T), %std_order_methods(std::Class<T >))
|
%evalif(SWIG_OrderType(T), %std_order_methods(std::Class<T >))
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,6 @@ namespace std {
|
||||||
%std_definst(deque, __VA_ARGS__);
|
%std_definst(deque, __VA_ARGS__);
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes(%std_deque_ptypen);
|
%apply_cpptypes(%std_deque_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,6 @@ namespace std {
|
||||||
SWIG_arg(%std_extequal_list(__VA_ARGS__)));
|
SWIG_arg(%std_extequal_list(__VA_ARGS__)));
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes(%std_list_ptypen);
|
%apply_cpptypes(%std_list_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,6 @@ namespace std {
|
||||||
%std_definst_2(map, __VA_ARGS__);
|
%std_definst_2(map, __VA_ARGS__);
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes_2(%std_map_ptypen);
|
%apply_cpptypes_2(%std_map_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,6 @@ namespace std {
|
||||||
%std_definst_2(multimap, __VA_ARGS__);
|
%std_definst_2(multimap, __VA_ARGS__);
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes_2(%std_multimap_ptypen);
|
%apply_cpptypes_2(%std_multimap_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,6 @@ namespace std {
|
||||||
%std_definst(multiset, __VA_ARGS__);
|
%std_definst(multiset, __VA_ARGS__);
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes(%std_multiset_ptypen);
|
%apply_cpptypes(%std_multiset_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,11 @@ namespace std {
|
||||||
typedef U* second_type;
|
typedef U* second_type;
|
||||||
|
|
||||||
%traits_swigtype(T);
|
%traits_swigtype(T);
|
||||||
|
%traits_swigtype(U);
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(std::pair<T,U* >), "header",
|
%fragment(SWIG_Traits_frag(std::pair<T,U* >), "header",
|
||||||
fragment=SWIG_Traits_frag(T),
|
fragment=SWIG_Traits_frag(T),
|
||||||
|
fragment=SWIG_Traits_frag(U),
|
||||||
fragment="StdPairTraits") {
|
fragment="StdPairTraits") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <> struct traits<std::pair<T,U* > > {
|
template <> struct traits<std::pair<T,U* > > {
|
||||||
|
|
@ -149,16 +151,18 @@ namespace std {
|
||||||
typedef T* fisrt_type;
|
typedef T* fisrt_type;
|
||||||
typedef U second_type;
|
typedef U second_type;
|
||||||
|
|
||||||
|
%traits_swigtype(T);
|
||||||
%traits_swigtype(U);
|
%traits_swigtype(U);
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(std::pair<T*,U >), "header",
|
%fragment(SWIG_Traits_frag(std::pair<T*,U >), "header",
|
||||||
|
fragment=SWIG_Traits_frag(T),
|
||||||
fragment=SWIG_Traits_frag(U),
|
fragment=SWIG_Traits_frag(U),
|
||||||
fragment="StdPairTraits") {
|
fragment="StdPairTraits") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <> struct traits<std::pair<T*,U > > {
|
template <> struct traits<std::pair<T*,U > > {
|
||||||
typedef pointer_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 " >";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -179,14 +183,19 @@ namespace std {
|
||||||
template <class T, class U > struct pair<T*, U*> {
|
template <class T, class U > struct pair<T*, U*> {
|
||||||
typedef T* fisrt_type;
|
typedef T* fisrt_type;
|
||||||
typedef U* second_type;
|
typedef U* second_type;
|
||||||
|
|
||||||
|
%traits_swigtype(T);
|
||||||
|
%traits_swigtype(U);
|
||||||
|
|
||||||
%fragment(SWIG_Traits_frag(std::pair<T*,U* >), "header",
|
%fragment(SWIG_Traits_frag(std::pair<T*,U* >), "header",
|
||||||
|
fragment=SWIG_Traits_frag(T),
|
||||||
|
fragment=SWIG_Traits_frag(U),
|
||||||
fragment="StdPairTraits") {
|
fragment="StdPairTraits") {
|
||||||
namespace swigpy {
|
namespace swigpy {
|
||||||
template <> struct traits<std::pair<T*,U* > > {
|
template <> struct traits<std::pair<T*,U* > > {
|
||||||
typedef pointer_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 " * >";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -211,6 +220,6 @@ namespace std {
|
||||||
%std_definst_2(pair, __VA_ARGS__);
|
%std_definst_2(pair, __VA_ARGS__);
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes_2(%std_pair_ptypen);
|
%apply_cpptypes_2(%std_pair_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,6 @@ namespace std {
|
||||||
%std_definst(set, __VA_ARGS__);
|
%std_definst(set, __VA_ARGS__);
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes(%std_set_ptypen);
|
%apply_cpptypes(%std_set_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,6 @@ namespace std {
|
||||||
%std_definst(vector, __VA_ARGS__);
|
%std_definst(vector, __VA_ARGS__);
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
#if !defined(SWIG_STD_NOEXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||||
%apply_cpptypes(%std_vector_ptypen);
|
%apply_cpptypes(%std_vector_ptypen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue