fix vector of templated types

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11508 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-08-05 22:17:06 +00:00
commit 22c0b83cef

View file

@ -16,17 +16,17 @@
// const declarations are used to guess the intent of the function being // const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied: // exported; therefore, the following rationale is applied:
// //
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*): // -- f(std::vector< T >), f(const std::vector< T >&), f(const std::vector< T >*):
// the parameter being read-only, either a Tcl list or a // the parameter being read-only, either a Tcl list or a
// previously wrapped std::vector<T> can be passed. // previously wrapped std::vector< T > can be passed.
// -- f(std::vector<T>&), f(std::vector<T>*): // -- f(std::vector< T >&), f(std::vector< T >*):
// the parameter must be modified; therefore, only a wrapped std::vector // the parameter must be modified; therefore, only a wrapped std::vector
// can be passed. // can be passed.
// -- std::vector<T> f(): // -- std::vector< T > f():
// the vector is returned by copy; therefore, a Tcl list of T:s // the vector is returned by copy; therefore, a Tcl list of T:s
// is returned which is most easily used in other Tcl functions procs // is returned which is most easily used in other Tcl functions procs
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(), // -- std::vector< T >& f(), std::vector< T >* f(), const std::vector< T >& f(),
// const std::vector<T>* f(): // const std::vector< T >* f():
// the vector is returned by reference; therefore, a wrapped std::vector // the vector is returned by reference; therefore, a wrapped std::vector
// is returned // is returned
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -85,7 +85,7 @@ int SwigDouble_As(Tcl_Interp *interp, Tcl_Obj *o, Type *val) {
namespace std { namespace std {
template<class T> class vector { template<class T> class vector {
%typemap(in) vector<T> (std::vector<T> *v) { %typemap(in) vector< T > (std::vector< T > *v) {
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
int i; int i;
@ -95,11 +95,11 @@ namespace std {
$&1_descriptor, 0) == 0){ $&1_descriptor, 0) == 0){
$1 = *v; $1 = *v;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, \ if(Tcl_ListObjGetElements(interp, $input, \
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
$1 = std::vector<T>(); $1 = std::vector< T >();
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp, if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp,
$descriptor(T *),0)) != 0) { $descriptor(T *),0)) != 0) {
@ -113,8 +113,8 @@ namespace std {
} }
} }
%typemap(in) const vector<T>* (std::vector<T> *v, std::vector<T> w), %typemap(in) const vector< T >* (std::vector< T > *v, std::vector< T > w),
const vector<T>& (std::vector<T> *v, std::vector<T> w) { const vector< T >& (std::vector< T > *v, std::vector< T > w) {
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
int i; int i;
@ -124,11 +124,11 @@ namespace std {
$&1_descriptor, 0) == 0) { $&1_descriptor, 0) == 0) {
$1 = v; $1 = v;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
w = std::vector<T>(); w = std::vector< T >();
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp, if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp,
$descriptor(T *),0)) != 0) { $descriptor(T *),0)) != 0) {
@ -143,7 +143,7 @@ namespace std {
} }
} }
%typemap(out) vector<T> { %typemap(out) vector< T > {
for (unsigned int i=0; i<$1.size(); i++) { for (unsigned int i=0; i<$1.size(); i++) {
T* ptr = new T((($1_type &)$1)[i]); T* ptr = new T((($1_type &)$1)[i]);
Tcl_ListObjAppendElement(interp, $result, \ Tcl_ListObjAppendElement(interp, $result, \
@ -153,18 +153,18 @@ namespace std {
} }
} }
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> { %typecheck(SWIG_TYPECHECK_VECTOR) vector< T > {
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
T* temp; T* temp;
std::vector<T> *v; std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \ if(SWIG_ConvertPtr($input, (void **) &v, \
$&1_descriptor, 0) == 0) { $&1_descriptor, 0) == 0) {
/* wrapped vector */ /* wrapped vector */
$1 = 1; $1 = 1;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
$1 = 0; $1 = 0;
@ -181,19 +181,19 @@ namespace std {
} }
} }
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&, %typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&,
const vector<T>* { const vector< T >* {
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
T* temp; T* temp;
std::vector<T> *v; std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \ if(SWIG_ConvertPtr($input, (void **) &v, \
$1_descriptor, 0) == 0){ $1_descriptor, 0) == 0){
/* wrapped vector */ /* wrapped vector */
$1 = 1; $1 = 1;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
$1 = 0; $1 = 0;
@ -213,7 +213,7 @@ 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, const T& value);
vector(const vector<T> &); vector(const vector< T > &);
unsigned int size() const; unsigned int size() const;
bool empty() const; bool empty() const;
@ -251,9 +251,9 @@ namespace std {
// specializations for built-ins // specializations for built-ins
%define specialize_std_vector(T, CONVERT_FROM, CONVERT_TO) %define specialize_std_vector(T, CONVERT_FROM, CONVERT_TO)
template<> class vector<T> { template<> class vector< T > {
%typemap(in) vector<T> (std::vector<T> *v){ %typemap(in) vector< T > (std::vector< T > *v){
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
int i; int i;
@ -263,11 +263,11 @@ namespace std {
$&1_descriptor, 0) == 0) { $&1_descriptor, 0) == 0) {
$1 = *v; $1 = *v;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
$1 = std::vector<T>(); $1 = std::vector< T >();
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR) if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
@ -276,8 +276,8 @@ namespace std {
} }
} }
%typemap(in) const vector<T>& (std::vector<T> *v,std::vector<T> w), %typemap(in) const vector< T >& (std::vector< T > *v,std::vector< T > w),
const vector<T>* (std::vector<T> *v,std::vector<T> w) { const vector< T >* (std::vector< T > *v,std::vector< T > w) {
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
int i; int i;
@ -287,11 +287,11 @@ namespace std {
$1_descriptor, 0) == 0) { $1_descriptor, 0) == 0) {
$1 = v; $1 = v;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
w = std::vector<T>(); w = std::vector< T >();
for (i = 0; i < nitems; i++) { for (i = 0; i < nitems; i++) {
if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR) if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
@ -301,25 +301,25 @@ namespace std {
} }
} }
%typemap(out) vector<T> { %typemap(out) vector< T > {
for (unsigned int i=0; i<$1.size(); i++) { for (unsigned int i=0; i<$1.size(); i++) {
Tcl_ListObjAppendElement(interp, $result, \ Tcl_ListObjAppendElement(interp, $result, \
CONVERT_TO((($1_type &)$1)[i])); CONVERT_TO((($1_type &)$1)[i]));
} }
} }
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> { %typecheck(SWIG_TYPECHECK_VECTOR) vector< T > {
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
T temp; T temp;
std::vector<T> *v; std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \ if(SWIG_ConvertPtr($input, (void **) &v, \
$&1_descriptor, 0) == 0){ $&1_descriptor, 0) == 0){
/* wrapped vector */ /* wrapped vector */
$1 = 1; $1 = 1;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
$1 = 0; $1 = 0;
@ -334,19 +334,19 @@ namespace std {
} }
} }
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&, %typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&,
const vector<T>*{ const vector< T >*{
Tcl_Obj **listobjv; Tcl_Obj **listobjv;
int nitems; int nitems;
T temp; T temp;
std::vector<T> *v; std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \ if(SWIG_ConvertPtr($input, (void **) &v, \
$1_descriptor, 0) == 0){ $1_descriptor, 0) == 0){
/* wrapped vector */ /* wrapped vector */
$1 = 1; $1 = 1;
} else { } else {
// It isn't a vector<T> so it should be a list of T's // It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR) &nitems, &listobjv) == TCL_ERROR)
$1 = 0; $1 = 0;
@ -364,7 +364,7 @@ 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, const T& value);
vector(const vector<T> &); vector(const vector< T > &);
unsigned int size() const; unsigned int size() const;
bool empty() const; bool empty() const;