Fixes for partial specialization change.

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

View file

@ -360,23 +360,23 @@ namespace std {
// Partial specialization for vectors of pointers. [ beazley ]
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)) {
unsigned int size = (PyTuple_Check($input) ?
PyTuple_Size($input) :
PyList_Size($input));
$1 = std::vector<T >(size);
$1 = std::vector<T *>(size);
for (unsigned int i=0; i<size; i++) {
T x;
T *x;
PyObject* o = PySequence_GetItem($input,i);
if ((SWIG_ConvertPtr(o,(void **) &x,
$descriptor(T),0)) != -1) {
$descriptor(T *),0)) != -1) {
(($1_type &)$1)[i] = x;
Py_DECREF(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_TypeError,
"vector<" #T "> 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<T> (std::vector<T>* v) {
%typemap(outv) vector<T*> (std::vector<T*>* v) {
if (PyTuple_Check($input) || PyList_Check($input)) {
unsigned int size = (PyTuple_Check($input) ?
PyTuple_Size($input) :
PyList_Size($input));
$result = std::vector<T >(size);
$result = std::vector<T* >(size);
for (unsigned int i=0; i<size; i++) {
T x;
T *x;
PyObject* o = PySequence_GetItem($input,i);
if ((SWIG_ConvertPtr(o,(void **) &x,
$descriptor(T),0)) != -1) {
$descriptor(T*),0)) != -1) {
(($type &)$result)[i] = x;
Py_DECREF(o);
} else {
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,
$&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<T>& (std::vector<T> temp,
std::vector<T>* v),
const vector<T>* (std::vector<T> temp,
std::vector<T>* v) {
%typemap(in) const vector<T*>& (std::vector<T*> temp,
std::vector<T*>* v),
const vector<T*>* (std::vector<T*> temp,
std::vector<T*>* v) {
if (PyTuple_Check($input) || PyList_Check($input)) {
unsigned int size = (PyTuple_Check($input) ?
PyTuple_Size($input) :
PyList_Size($input));
temp = std::vector<T >(size);
temp = std::vector<T *>(size);
$1 = &temp;
for (unsigned int i=0; i<size; i++) {
T x;
T *x;
PyObject* o = PySequence_GetItem($input,i);
if ((SWIG_ConvertPtr(o,(void **) &x,
$descriptor(T),0)) != -1) {
$descriptor(T *),0)) != -1) {
temp[i] = x;
Py_DECREF(o);
} else {
Py_DECREF(o);
PyErr_SetString(PyExc_TypeError,
"vector<" #T "> 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<T>& (std::vector<T> temp,
std::vector<T>* v),
const vector<T>* (std::vector<T> temp,
std::vector<T>* v) {
%typemap(outv) const vector<T *>& (std::vector<T *> temp,
std::vector<T *>* v),
const vector<T *>* (std::vector<T *> temp,
std::vector<T *>* v) {
if (PyTuple_Check($input) || PyList_Check($input)) {
unsigned int size = (PyTuple_Check($input) ?
PyTuple_Size($input) :
PyList_Size($input));
temp = std::vector<T >(size);
temp = std::vector<T * >(size);
$result = &temp;
for (unsigned int i=0; i<size; i++) {
T x;
T *x;
PyObject* o = PySequence_GetItem($input,i);
if ((SWIG_ConvertPtr(o,(void **) &x,
$descriptor(T),0)) != -1) {
$descriptor(T *),0)) != -1) {
temp[i] = x;
Py_DECREF(o);
} else {
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,
$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<T> {
%typemap(out) vector<T*> {
$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<T> {
%typemap(inv) vector<T*> {
$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<T> {
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T*> {
/* 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<T >* v;
std::vector<T* >* 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<T>&,
const vector<T>* {
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T*>&,
const vector<T*>* {
/* 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<T >* v;
std::vector<T *>* 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<T> &);
vector(unsigned int size, T * &value);
vector(const vector<T*> &);
%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<size)
@ -582,17 +582,17 @@ namespace std {
else
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());
if (i<0) i = size+i;
if (j<0) j = size+j;
if (i<0) i = 0;
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());
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<size)
@ -600,7 +600,7 @@ namespace std {
else
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());
if (i<0) i = size+i;
if (j<0) j = size+j;