Fixes for partial specialization change.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5062 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2003-09-01 20:00:05 +00:00
commit ec6d8dbd46

View file

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