// SWIG typemaps for std::vector types
// ------------------------------------------------------------------------
// The aim of all that follows would be to integrate std::vector with
// PHP as much as possible, namely, to allow the user to pass and
// be returned PHP lists.
// 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 PHP 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
// -- std::vector<T> f():
// the vector is returned by copy; therefore, a PHP sequence of T:s
// is returned which is most easily used in other PHP 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
// ------------------------------------------------------------------------
template<class T> class vector {
// add generic typemaps here
vector(unsigned int size = 0);
unsigned int size() const;
void push_back(const T& x);
T pop() throw (std::out_of_range) {
throw std::out_of_range("pop from empty vector");
T& get(int i) throw (std::out_of_range) {
int size = int(self->size());
throw std::out_of_range("vector index out of range");
void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size());
throw std::out_of_range("vector index out of range");
// specializations for built-ins
%define specialize_std_vector(T)
template<> class vector<T> {
// add specialized typemaps here
vector(unsigned int size = 0);
unsigned int size() const;
T pop() throw (std::out_of_range) {
throw std::out_of_range("pop from empty vector");
T get(int i) throw (std::out_of_range) {
int size = int(self->size());
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());
throw std::out_of_range("vector index out of range");
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);