- 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:
Marcelo Matus 2004-03-31 11:27:53 +00:00
commit 29a30e2dcc
10 changed files with 79 additions and 77 deletions

View file

@ -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))
}
}
}
};
// ***