diff --git a/Lib/python/std_vector.i b/Lib/python/std_vector.i index 3b0ee93f1..11380f9d9 100644 --- a/Lib/python/std_vector.i +++ b/Lib/python/std_vector.i @@ -360,23 +360,23 @@ namespace std { // Partial specialization for vectors of pointers. [ beazley ] template class vector { - %typemap(in) vector (std::vector* v) { + %typemap(in) vector (std::vector* v) { if (PyTuple_Check($input) || PyList_Check($input)) { unsigned int size = (PyTuple_Check($input) ? PyTuple_Size($input) : PyList_Size($input)); - $1 = std::vector(size); + $1 = std::vector(size); for (unsigned int i=0; i expected"); + "vector<" #T "*> expected"); SWIG_fail; } } @@ -384,56 +384,56 @@ namespace std { $&1_descriptor,0) != -1) { $1 = *v; } else { - PyErr_SetString(PyExc_TypeError,"vector<" #T "> expected"); + PyErr_SetString(PyExc_TypeError,"vector<" #T "*> expected"); SWIG_fail; } } - %typemap(outv) vector (std::vector* v) { + %typemap(outv) vector (std::vector* v) { if (PyTuple_Check($input) || PyList_Check($input)) { unsigned int size = (PyTuple_Check($input) ? PyTuple_Size($input) : PyList_Size($input)); - $result = std::vector(size); + $result = std::vector(size); for (unsigned int i=0; i expected"); + throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); } } } else if (SWIG_ConvertPtr($input,(void **) &v, $&descriptor,1) != -1){ $result = *v; } else { - throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); + throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); } } - %typemap(in) const vector& (std::vector temp, - std::vector* v), - const vector* (std::vector temp, - std::vector* v) { + %typemap(in) const vector& (std::vector temp, + std::vector* v), + const vector* (std::vector temp, + std::vector* v) { if (PyTuple_Check($input) || PyList_Check($input)) { unsigned int size = (PyTuple_Check($input) ? PyTuple_Size($input) : PyList_Size($input)); - temp = std::vector(size); + temp = std::vector(size); $1 = &temp; for (unsigned int i=0; i expected"); + "vector<" #T "*> expected"); SWIG_fail; } } @@ -441,58 +441,58 @@ namespace std { $1_descriptor,0) != -1) { $1 = v; } else { - PyErr_SetString(PyExc_TypeError,"vector<" #T "> expected"); + PyErr_SetString(PyExc_TypeError,"vector<" #T "*> expected"); SWIG_fail; } } - %typemap(outv) const vector& (std::vector temp, - std::vector* v), - const vector* (std::vector temp, - std::vector* v) { + %typemap(outv) const vector& (std::vector temp, + std::vector* v), + const vector* (std::vector temp, + std::vector* v) { if (PyTuple_Check($input) || PyList_Check($input)) { unsigned int size = (PyTuple_Check($input) ? PyTuple_Size($input) : PyList_Size($input)); - temp = std::vector(size); + temp = std::vector(size); $result = &temp; for (unsigned int i=0; i expected"); + throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); } } } else if (SWIG_ConvertPtr($input,(void **) &v, $descriptor,1) != -1){ $result = v; } else { - throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "> expected"); + throw SWIG_DIRECTOR_TYPE_MISMATCH("vector<" #T "*> expected"); } } - %typemap(out) vector { + %typemap(out) vector { $result = PyTuple_New($1.size()); for (unsigned int i=0; i<$1.size(); i++) { - T ptr = (($1_type &)$1)[i]; + T *ptr = (($1_type &)$1)[i]; PyTuple_SetItem($result,i, SWIG_NewPointerObj((void *) ptr, - $descriptor(T), 0)); + $descriptor(T*), 0)); } } - %typemap(inv) vector { + %typemap(inv) vector { $input = PyTuple_New($1_name.size()); for (unsigned int i=0; i<$1_name.size(); i++) { - T ptr = (($1_type &)$1_name)[i]; + T *ptr = (($1_type &)$1_name)[i]; PyTuple_SetItem($input,i, SWIG_NewPointerObj((void *) ptr, - $descriptor(T), 0)); + $descriptor(T*), 0)); } } - %typecheck(SWIG_TYPECHECK_VECTOR) vector { + %typecheck(SWIG_TYPECHECK_VECTOR) vector { /* native sequence? */ if (PyTuple_Check($input) || PyList_Check($input)) { unsigned int size = (PyTuple_Check($input) ? @@ -503,10 +503,10 @@ namespace std { $1 = 1; } else { /* check the first element only */ - T x; + T *x; PyObject* o = PySequence_GetItem($input,0); if ((SWIG_ConvertPtr(o,(void **) &x, - $descriptor(T),0)) != -1) + $descriptor(T*),0)) != -1) $1 = 1; else $1 = 0; @@ -514,7 +514,7 @@ namespace std { } } else { /* wrapped vector? */ - std::vector* v; + std::vector* v; if (SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0) != -1) $1 = 1; @@ -522,8 +522,8 @@ namespace std { $1 = 0; } } - %typecheck(SWIG_TYPECHECK_VECTOR) const vector&, - const vector* { + %typecheck(SWIG_TYPECHECK_VECTOR) const vector&, + const vector* { /* native sequence? */ if (PyTuple_Check($input) || PyList_Check($input)) { unsigned int size = (PyTuple_Check($input) ? @@ -534,10 +534,10 @@ namespace std { $1 = 1; } else { /* check the first element only */ - T x; + T *x; PyObject* o = PySequence_GetItem($input,0); if ((SWIG_ConvertPtr(o,(void **) &x, - $descriptor(T),0)) != -1) + $descriptor(T*),0)) != -1) $1 = 1; else $1 = 0; @@ -545,7 +545,7 @@ namespace std { } } else { /* wrapped vector? */ - std::vector* v; + std::vector* v; if (SWIG_ConvertPtr($input,(void **) &v, $1_descriptor,0) != -1) $1 = 1; @@ -555,26 +555,26 @@ namespace std { } public: vector(unsigned int size = 0); - vector(unsigned int size, const T& value); - vector(const vector &); + vector(unsigned int size, T * &value); + vector(const vector &); %rename(__len__) size; unsigned int size() const; void clear(); %rename(append) push_back; - void push_back(T x); + void push_back(T * x); %extend { bool __nonzero__() { return !(self->empty()); } - T pop() { + T *pop() { if (self->size() == 0) throw std::out_of_range("pop from empty vector"); - T x = self->back(); + T *x = self->back(); self->pop_back(); return x; } - T __getitem__(int i) { + T * __getitem__(int i) { int size = int(self->size()); if (i<0) i += size; if (i>=0 && i __getslice__(int i, int j) { + std::vector __getslice__(int i, int j) { int size = int(self->size()); if (i<0) i = size+i; if (j<0) j = size+j; if (i<0) i = 0; if (j>size) j = size; - std::vector tmp(j-i); + std::vector tmp(j-i); std::copy(self->begin()+i,self->begin()+j,tmp.begin()); return tmp; } - void __setitem__(int i, const T& x) { + void __setitem__(int i, T *x) { int size = int(self->size()); if (i<0) i+= size; if (i>=0 && i& v) { + void __setslice__(int i, int j, const std::vector& v) { int size = int(self->size()); if (i<0) i = size+i; if (j<0) j = size+j;