1/* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
4 *
5 * std_vector.i
6 * ----------------------------------------------------------------------------- */
7
8%include <std_common.i>
9
10%{
11#include <vector>
12#include <stdexcept>
13%}
14
15namespace std {
16
17  template<class T> class vector {
18  public:
19    typedef size_t size_type;
20    typedef T value_type;
21    typedef const value_type& const_reference;
22    vector();
23    vector(size_type n);
24    size_type size() const;
25    size_type capacity() const;
26    void reserve(size_type n);
27    void clear();
28    %rename(push) push_back;
29    void push_back(const value_type& x);
30    %extend {
31      bool is_empty() const {
32        return $self->empty();
33      }
34      T pop() throw (std::out_of_range) {
35        if (self->size() == 0)
36          throw std::out_of_range("pop from empty vector");
37        T x = self->back();
38        self->pop_back();
39        return x;
40      }
41      const_reference get(int i) throw (std::out_of_range) {
42        int size = int(self->size());
43        if (i>=0 && i<size)
44          return (*self)[i];
45        else
46          throw std::out_of_range("vector index out of range");
47      }
48      void set(int i, const value_type& val) throw (std::out_of_range) {
49        int size = int(self->size());
50        if (i>=0 && i<size)
51          (*self)[i] = val;
52        else
53          throw std::out_of_range("vector index out of range");
54      }
55    }
56  };
57
58  // bool specialization
59  template<> class vector<bool> {
60  public:
61    typedef size_t size_type;
62    typedef bool value_type;
63    typedef bool const_reference;
64    vector();
65    vector(size_type n);
66    size_type size() const;
67    size_type capacity() const;
68    void reserve(size_type n);
69    void clear();
70    %rename(push) push_back;
71    void push_back(const value_type& x);
72    %extend {
73      bool is_empty() const {
74        return $self->empty();
75      }
76      bool pop() throw (std::out_of_range) {
77        if (self->size() == 0)
78          throw std::out_of_range("pop from empty vector");
79        bool x = self->back();
80        self->pop_back();
81        return x;
82      }
83      const_reference get(int i) throw (std::out_of_range) {
84        int size = int(self->size());
85        if (i>=0 && i<size)
86          return (*self)[i];
87        else
88          throw std::out_of_range("vector index out of range");
89      }
90      void set(int i, const value_type& val) throw (std::out_of_range) {
91        int size = int(self->size());
92        if (i>=0 && i<size)
93          (*self)[i] = val;
94        else
95          throw std::out_of_range("vector index out of range");
96      }
97    }
98  };
99}
100
101%define specialize_std_vector(T)
102#warning "specialize_std_vector - specialization for type T no longer needed"
103%enddef
104
105
106