Fix for vector of bool
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8076 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a9afd37cbf
commit
3db5c253df
2 changed files with 16 additions and 89 deletions
|
|
@ -170,6 +170,7 @@
|
||||||
public:
|
public:
|
||||||
typedef size_t size_type;
|
typedef size_t size_type;
|
||||||
typedef CTYPE value_type;
|
typedef CTYPE value_type;
|
||||||
|
typedef const value_type& const_reference;
|
||||||
%rename(Clear) clear;
|
%rename(Clear) clear;
|
||||||
void clear();
|
void clear();
|
||||||
%rename(Add) push_back;
|
%rename(Add) push_back;
|
||||||
|
|
@ -197,7 +198,7 @@
|
||||||
else
|
else
|
||||||
throw std::out_of_range("index");
|
throw std::out_of_range("index");
|
||||||
}
|
}
|
||||||
const value_type& getitem(int index) throw (std::out_of_range) {
|
const_reference getitem(int index) throw (std::out_of_range) {
|
||||||
if (index>=0 && index<(int)self->size())
|
if (index>=0 && index<(int)self->size())
|
||||||
return (*self)[index];
|
return (*self)[index];
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,66 +1,36 @@
|
||||||
//
|
|
||||||
// SWIG typemaps for std::vector
|
|
||||||
// Luigi Ballabio
|
|
||||||
// May 7, 2002
|
|
||||||
//
|
|
||||||
// Java implementation
|
|
||||||
|
|
||||||
%include <std_common.i>
|
%include <std_common.i>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
// std::vector
|
|
||||||
//
|
|
||||||
// The aim of all that follows would be to integrate std::vector with
|
|
||||||
// Java as much as possible, namely, to allow the user to pass and
|
|
||||||
// be returned Java (arrays? containers?)
|
|
||||||
// const declarations are used to guess the intent of the function being
|
|
||||||
// exported; therefore, the following rationale is applied:
|
|
||||||
//
|
|
||||||
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
|
|
||||||
// the parameter being read-only, either a Java sequence or a
|
|
||||||
// previously wrapped std::vector<T> can be passed.
|
|
||||||
// -- f(std::vector<T>&), f(std::vector<T>*):
|
|
||||||
// the parameter must be modified; therefore, only a wrapped std::vector
|
|
||||||
// can be passed.
|
|
||||||
// -- std::vector<T> f():
|
|
||||||
// the vector is returned by copy; therefore, a Java sequence of T:s
|
|
||||||
// is returned which is most easily used in other Java functions
|
|
||||||
// -- std::vector<T>& f(), 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
|
|
||||||
// is returned
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
// exported class
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
template<class T> class vector {
|
template<class T> class vector {
|
||||||
// add generic typemaps here
|
|
||||||
public:
|
public:
|
||||||
|
typedef size_t size_type;
|
||||||
|
typedef T value_type;
|
||||||
|
typedef const value_type& const_reference;
|
||||||
vector();
|
vector();
|
||||||
vector(unsigned int);
|
vector(size_type n);
|
||||||
unsigned int size() const;
|
size_type size() const;
|
||||||
|
size_type capacity() const;
|
||||||
|
void reserve(size_type n);
|
||||||
%rename(isEmpty) empty;
|
%rename(isEmpty) empty;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void clear();
|
void clear();
|
||||||
%rename(add) push_back;
|
%rename(add) push_back;
|
||||||
void push_back(const T& x);
|
void push_back(const value_type& x);
|
||||||
%extend {
|
%extend {
|
||||||
T& get(int i) throw (std::out_of_range) {
|
const_reference get(int i) throw (std::out_of_range) {
|
||||||
int size = int(self->size());
|
int size = int(self->size());
|
||||||
if (i>=0 && i<size)
|
if (i>=0 && i<size)
|
||||||
return (*self)[i];
|
return (*self)[i];
|
||||||
else
|
else
|
||||||
throw std::out_of_range("vector index out of range");
|
throw std::out_of_range("vector index out of range");
|
||||||
}
|
}
|
||||||
void set(int i, const T& x) throw (std::out_of_range) {
|
void set(int i, const_reference x) throw (std::out_of_range) {
|
||||||
int size = int(self->size());
|
int size = int(self->size());
|
||||||
if (i>=0 && i<size)
|
if (i>=0 && i<size)
|
||||||
(*self)[i] = x;
|
(*self)[i] = x;
|
||||||
|
|
@ -69,53 +39,9 @@ namespace std {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// specializations for built-ins
|
|
||||||
|
|
||||||
%define specialize_std_vector(T)
|
|
||||||
template<> class vector<T> {
|
|
||||||
// add specialized typemaps here
|
|
||||||
public:
|
|
||||||
vector();
|
|
||||||
vector(unsigned int);
|
|
||||||
unsigned int size() const;
|
|
||||||
%rename(isEmpty) empty;
|
|
||||||
bool empty() const;
|
|
||||||
void clear();
|
|
||||||
%rename(add) push_back;
|
|
||||||
void push_back(T x);
|
|
||||||
%extend {
|
|
||||||
T get(int i) throw (std::out_of_range) {
|
|
||||||
int size = int(self->size());
|
|
||||||
if (i>=0 && i<size)
|
|
||||||
return (*self)[i];
|
|
||||||
else
|
|
||||||
throw std::out_of_range("vector index out of range");
|
|
||||||
}
|
|
||||||
void set(int i, T x) throw (std::out_of_range) {
|
|
||||||
int size = int(self->size());
|
|
||||||
if (i>=0 && i<size)
|
|
||||||
(*self)[i] = x;
|
|
||||||
else
|
|
||||||
throw std::out_of_range("vector index out of range");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
%enddef
|
|
||||||
|
|
||||||
specialize_std_vector(bool);
|
|
||||||
specialize_std_vector(char);
|
|
||||||
specialize_std_vector(int);
|
|
||||||
specialize_std_vector(short);
|
|
||||||
specialize_std_vector(long);
|
|
||||||
specialize_std_vector(unsigned char);
|
|
||||||
specialize_std_vector(unsigned int);
|
|
||||||
specialize_std_vector(unsigned short);
|
|
||||||
specialize_std_vector(unsigned long);
|
|
||||||
specialize_std_vector(float);
|
|
||||||
specialize_std_vector(double);
|
|
||||||
specialize_std_vector(std::string);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%define specialize_std_vector(T)
|
||||||
|
#warning "specialize_std_vector - specialization for type T no longer needed"
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue