- better support for classes with no default constructor, equal or
comparison methods.
you will be able to do
struct Foo {
Foo(int) {}
};
%std_nodefconst_type(Foo); // Says Foo has no def. constructor
%template(vector_Foo) std::vector<Foo>;
and the conflicting vector/list/deque methods will not be generated.
more cosmetic, and a note about the relation between std::map and
std::pair.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5810 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
efdc4c83dd
commit
29a30e2dcc
10 changed files with 79 additions and 77 deletions
|
|
@ -255,42 +255,37 @@ namespace swigpy
|
|||
// __getitem__ is required to raise an IndexError for for-loops to work
|
||||
// other methods which can raise are made to throw an IndexError as well
|
||||
%exception __getitem__ {
|
||||
try {
|
||||
$action;
|
||||
} catch (std::out_of_range& e) {
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception __setitem__ {
|
||||
try {
|
||||
$action;
|
||||
} catch (std::out_of_range& e) {
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception __setslice__ {
|
||||
try {
|
||||
$action;
|
||||
} catch (std::invalid_argument& e) {
|
||||
try { $action }
|
||||
catch (std::invalid_argument& e) {
|
||||
SWIG_exception(SWIG_TypeError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception __delitem__ {
|
||||
try {
|
||||
$action;
|
||||
} catch (std::out_of_range& e) {
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception pop {
|
||||
try {
|
||||
$action;
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
try { $action }
|
||||
catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -301,8 +296,7 @@ namespace swigpy
|
|||
return !(self->empty());
|
||||
}
|
||||
|
||||
size_type __len__() const
|
||||
{
|
||||
size_type __len__() const {
|
||||
return self->size();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,3 +175,15 @@
|
|||
}
|
||||
%}
|
||||
|
||||
|
||||
//
|
||||
// Ignore member methods for Type with no default constructor
|
||||
//
|
||||
%define %std_nodefconst_type(...)
|
||||
%feature("ignore") std::vector<__VA_ARGS__ >::vector(size_type size);
|
||||
%feature("ignore") std::vector<__VA_ARGS__ >::resize(size_type size);
|
||||
%feature("ignore") std::deque<__VA_ARGS__ >::deque(size_type size);
|
||||
%feature("ignore") std::deque<__VA_ARGS__ >::resize(size_type size);
|
||||
%feature("ignore") std::list<__VA_ARGS__ >::list(size_type size);
|
||||
%feature("ignore") std::list<__VA_ARGS__ >::resize(size_type size);
|
||||
%enddef
|
||||
|
|
|
|||
|
|
@ -54,18 +54,15 @@
|
|||
namespace swigpy {
|
||||
template <class T>
|
||||
struct traits_asptr<std::deque<T> > {
|
||||
typedef std::deque<T> deque_type;
|
||||
typedef T value_type;
|
||||
static int asptr(PyObject *obj, deque_type **vec) {
|
||||
return traits_asptr_stdseq<deque_type>::asptr(obj, vec);
|
||||
static int asptr(PyObject *obj, std::deque<T> **vec) {
|
||||
return traits_asptr_stdseq<std::deque<T> >::asptr(obj, vec);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct traits_from<std::deque<T> > {
|
||||
typedef std::deque<T> deque_type;
|
||||
static PyObject *from(const deque_type& vec) {
|
||||
return traits_from_stdseq<deque_type>::from(vec);
|
||||
static PyObject *from(const std::deque<T> & vec) {
|
||||
return traits_from_stdseq<std::deque<T> >::from(vec);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -102,7 +99,7 @@ namespace std {
|
|||
|
||||
%typemap_traits_ptr(SWIG_CCode(DEQUE), std::deque<T >);
|
||||
|
||||
%std_deque_methods(std::deque<T >);
|
||||
%std_deque_methods(deque);
|
||||
%pysequence_methods(std::deque<T >);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,8 @@
|
|||
void pop_front();
|
||||
void push_front(const value_type& x);
|
||||
|
||||
void remove(const value_type& x);
|
||||
void unique();
|
||||
void reverse();
|
||||
void sort();
|
||||
|
||||
void merge(list& x);
|
||||
%enddef
|
||||
|
||||
|
||||
|
|
@ -69,18 +65,15 @@
|
|||
namespace swigpy {
|
||||
template <class T >
|
||||
struct traits_asptr<std::list<T> > {
|
||||
typedef std::list<T> list_type;
|
||||
typedef T value_type;
|
||||
static int asptr(PyObject *obj, list_type **lis) {
|
||||
return traits_asptr_stdseq<list_type>::asptr(obj, lis);
|
||||
static int asptr(PyObject *obj, std::list<T> **lis) {
|
||||
return traits_asptr_stdseq<std::list<T> >::asptr(obj, lis);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct traits_from<std::list<T> > {
|
||||
typedef std::list<T> list_type;
|
||||
static PyObject *from(const list_type& vec) {
|
||||
return traits_from_stdseq<list_type>::from(vec);
|
||||
static PyObject *from(const std::list<T> & vec) {
|
||||
return traits_from_stdseq<std::list<T> >::from(vec);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -117,7 +110,7 @@ namespace std {
|
|||
|
||||
%typemap_traits_ptr(SWIG_CCode(LIST), std::list<T >);
|
||||
|
||||
%std_list_methods(std::list<T >);
|
||||
%std_list_methods(list);
|
||||
%pysequence_methods(std::list<T >);
|
||||
};
|
||||
|
||||
|
|
@ -145,15 +138,26 @@ namespace std {
|
|||
|
||||
%typemap_traits_ptr(SWIG_CCode(LIST), std::list<T* >);
|
||||
|
||||
%std_list_methods_val(std::list<T* >);
|
||||
%std_list_methods_val(list);
|
||||
%pysequence_methods_val(std::list<T* >);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
%define %std_extequal_list(...)
|
||||
%extend std::list<__VA_ARGS__ > {
|
||||
void remove(const value_type& x) { self->remove(x); }
|
||||
void merge(std::list<__VA_ARGS__ >& x){ self->merge(x); }
|
||||
void unique() { self->unique(); }
|
||||
void sort() { self->sort(); }
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define %std_list_ptypen(...)
|
||||
%std_extcomp(list, __VA_ARGS__);
|
||||
%std_definst(list, __VA_ARGS__);
|
||||
%evalif(SWIG_EqualType(__VA_ARGS__),
|
||||
SWIG_arg(%std_extequal_list(__VA_ARGS__)));
|
||||
%enddef
|
||||
|
||||
#if defined(SWIG_STD_EXTEND_COMPARISON) || defined(SWIG_STD_DEFAULT_INSTANTIATION)
|
||||
|
|
|
|||
|
|
@ -34,6 +34,20 @@
|
|||
%enddef
|
||||
|
||||
|
||||
// **** Note ****
|
||||
//
|
||||
// If you are going to use a map, you need to instantiate both the
|
||||
// map and the pair class:
|
||||
//
|
||||
// %template(pair_ii) std::pair<int, int>;
|
||||
// %template(map_ii) std::map<int, int>;
|
||||
//
|
||||
// or
|
||||
//
|
||||
// %template() std::pair<int, int>;
|
||||
// %template(map_ii) std::map<int, int>;
|
||||
//
|
||||
// **** Note ****
|
||||
// ------------------------------------------------------------------------
|
||||
// std::map
|
||||
//
|
||||
|
|
@ -82,8 +96,6 @@
|
|||
template <class K, class T>
|
||||
struct traits_asptr<std::map<K,T> > {
|
||||
typedef std::map<K,T> map_type;
|
||||
typedef K key_type;
|
||||
|
||||
static int asptr(PyObject *obj, map_type **val) {
|
||||
if (PyDict_Check(obj)) {
|
||||
PyObject_var items = PyMapping_Items(obj);
|
||||
|
|
@ -157,7 +169,7 @@ namespace std {
|
|||
|
||||
%typemap_traits_ptr(SWIG_CCode(MAP), std::map<K, T >);
|
||||
|
||||
%std_map_methods(std::map<K, T >);
|
||||
%std_map_methods(map);
|
||||
%pydict_methods(SWIG_arg(std::map<K, T >));
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -57,10 +57,7 @@
|
|||
|
||||
template <class K, class T>
|
||||
struct traits_asptr<std::multimap<K,T> > {
|
||||
typedef std::multimap<K,T> multimap_type;
|
||||
typedef K key_type;
|
||||
|
||||
static int asptr(PyObject *obj, multimap_type **val) {
|
||||
static int asptr(PyObject *obj, std::multimap<K,T> **val) {
|
||||
if (PyDict_Check(obj)) {
|
||||
PyObject_var items = PyMapping_Items(obj);
|
||||
return traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >
|
||||
|
|
@ -133,7 +130,7 @@ namespace std {
|
|||
|
||||
%typemap_traits_ptr(SWIG_CCode(MULTIMAP), std::multimap<K, T >);
|
||||
|
||||
%std_multimap_methods(std::multimap<K, T >);
|
||||
%std_multimap_methods(multimap);
|
||||
%pydict_methods(SWIG_arg(std::multimap<K, T >));
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@
|
|||
|
||||
template <class T>
|
||||
struct traits_asptr<std::multiset<T> > {
|
||||
typedef std::multiset<T> multiset_type;
|
||||
static int asptr(PyObject *obj, multiset_type **m) {
|
||||
static int asptr(PyObject *obj, std::multiset<T> **m) {
|
||||
return traits_asptr_stdseq<std::multiset<T> >::asptr(obj, m);
|
||||
}
|
||||
};
|
||||
|
|
@ -98,7 +97,7 @@ namespace std {
|
|||
|
||||
%typemap_traits_ptr(SWIG_CCode(MULTISET), std::multiset<T >);
|
||||
|
||||
%std_multiset_methods(std::multiset<T >);
|
||||
%std_multiset_methods(multiset);
|
||||
%pycontainer_methods(std::multiset<T >);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -9,16 +9,13 @@
|
|||
namespace swigpy {
|
||||
template <class T, class U >
|
||||
struct traits_asval<std::pair<T,U> > {
|
||||
typedef std::pair<T,U> value_type;
|
||||
typedef T first_type;
|
||||
typedef U second_type;
|
||||
|
||||
static int asval(PyObject *obj, value_type *val) {
|
||||
static int asval(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);
|
||||
first_type *pfirst = val ? &(val->first) : 0;
|
||||
second_type *psecond = val ? &(val->second) : 0;
|
||||
T *pfirst = val ? &(val->first) : 0;
|
||||
U *psecond = val ? &(val->second) : 0;
|
||||
if (swigpy::asval(first,pfirst) && swigpy::asval(second,psecond)) {
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -40,8 +37,7 @@
|
|||
|
||||
template <class T, class U >
|
||||
struct traits_from<std::pair<T,U> > {
|
||||
typedef std::pair<T,U> value_type;
|
||||
static PyObject *from(const value_type& val) {
|
||||
static PyObject *from(const std::pair<T,U>& val) {
|
||||
PyObject* obj = PyTuple_New(2);
|
||||
PyTuple_SetItem(obj,0,swigpy::from(val.first));
|
||||
PyTuple_SetItem(obj,1,swigpy::from(val.second));
|
||||
|
|
@ -83,17 +79,12 @@ namespace std {
|
|||
U second;
|
||||
|
||||
%extend
|
||||
{
|
||||
const T& f() {
|
||||
return self->first;
|
||||
}
|
||||
|
||||
{
|
||||
%pythoncode {
|
||||
def __repr__(self):
|
||||
return "(%s, %s)" %(str(self.first),str(self.second))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// ***
|
||||
|
|
|
|||
|
|
@ -73,8 +73,7 @@
|
|||
|
||||
template <class T>
|
||||
struct traits_asptr<std::set<T> > {
|
||||
typedef std::set<T> set_type;
|
||||
static int asptr(PyObject *obj, set_type **s) {
|
||||
static int asptr(PyObject *obj, std::set<T> **s) {
|
||||
return traits_asptr_stdseq<std::set<T> >::asptr(obj, s);
|
||||
}
|
||||
};
|
||||
|
|
@ -121,7 +120,7 @@ namespace std {
|
|||
|
||||
%typemap_traits_ptr(SWIG_CCode(SET), std::set<T >);
|
||||
|
||||
%std_set_methods(std::set<T >);
|
||||
%std_set_methods(set);
|
||||
%pycontainer_methods(std::set<T >);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -57,18 +57,15 @@
|
|||
namespace swigpy {
|
||||
template <class T>
|
||||
struct traits_asptr<std::vector<T> > {
|
||||
typedef std::vector<T> vector_type;
|
||||
typedef T value_type;
|
||||
static int asptr(PyObject *obj, vector_type **vec) {
|
||||
return traits_asptr_stdseq<vector_type>::asptr(obj, vec);
|
||||
static int asptr(PyObject *obj, std::vector<T> **vec) {
|
||||
return traits_asptr_stdseq<std::vector<T> >::asptr(obj, vec);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct traits_from<std::vector<T> > {
|
||||
typedef std::vector<T> vector_type;
|
||||
static PyObject *from(const vector_type& vec) {
|
||||
return traits_from_stdseq<vector_type>::from(vec);
|
||||
static PyObject *from(const std::vector<T>& vec) {
|
||||
return traits_from_stdseq<std::vector<T> >::from(vec);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue