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_deque.i
6 *
7 * This file contains a generic definition of std::deque along with
8 * some helper functions.  Specific language modules should include
9 * this file to generate wrappers.
10 * ----------------------------------------------------------------------------- */
11
12%include <std_except.i>
13
14%{
15#include <deque>
16#include <stdexcept>
17%}
18
19
20/* This macro defines all of the standard methods for a deque.  This
21   is defined as a macro to simplify the task of specialization.  For
22   example,
23
24         template<> class deque<int> {
25         public:
26             %std_deque_methods(int);
27         };
28*/
29
30%define %std_deque_methods(T)
31       typedef T &reference;
32       typedef const T& const_reference;
33
34       deque();
35       deque(unsigned int size, const T& value=T());
36       deque(const deque<T> &);
37      ~deque();
38
39       void assign(unsigned int n, const T& value);
40       void swap(deque<T> &x);
41       unsigned int size() const;
42       unsigned int max_size() const;
43       void resize(unsigned int n, T c = T());
44       bool empty() const;
45       const_reference front();
46       const_reference back();
47       void push_front(const T& x);
48       void push_back(const T& x);
49       void pop_front();
50       void pop_back();
51       void clear();
52
53       /* Some useful extensions */
54       %extend {
55           const_reference getitem(int i) throw (std::out_of_range) {
56                int size = int(self->size());
57                if (i<0) i += size;
58                if (i>=0 && i<size)
59                    return (*self)[i];
60                else
61                    throw std::out_of_range("deque index out of range");
62           }
63           void setitem(int i, const T& x) throw (std::out_of_range) {
64                int size = int(self->size());
65                if (i<0) i+= size;
66                if (i>=0 && i<size)
67                    (*self)[i] = x;
68                else
69                    throw std::out_of_range("deque index out of range");
70           }
71           void delitem(int i) throw (std::out_of_range) {
72            	int size = int(self->size());
73                if (i<0) i+= size;
74                if (i>=0 && i<size) {
75                    self->erase(self->begin()+i);
76                } else {
77                    throw std::out_of_range("deque index out of range");
78                }
79           }
80	   std::deque<T> getslice(int i, int j) {
81                int size = int(self->size());
82                if (i<0) i = size+i;
83                if (j<0) j = size+j;
84                if (i<0) i = 0;
85                if (j>size) j = size;
86                std::deque<T > tmp(j-i);
87                std::copy(self->begin()+i,self->begin()+j,tmp.begin());
88                return tmp;
89            }
90            void setslice(int i, int j, const std::deque<T>& v) {
91                int size = int(self->size());
92                if (i<0) i = size+i;
93                if (j<0) j = size+j;
94                if (i<0) i = 0;
95                if (j>size) j = size;
96                if (int(v.size()) == j-i) {
97                    std::copy(v.begin(),v.end(),self->begin()+i);
98                } else {
99                    self->erase(self->begin()+i,self->begin()+j);
100                    if (i+1 <= size)
101                        self->insert(self->begin()+i+1,v.begin(),v.end());
102                    else
103                        self->insert(self->end(),v.begin(),v.end());
104                }
105            }
106            void delslice(int i, int j) {
107                int size = int(self->size());
108                if (i<0) i = size+i;
109                if (j<0) j = size+j;
110                if (i<0) i = 0;
111                if (j>size) j = size;
112                self->erase(self->begin()+i,self->begin()+j);
113            }
114       };
115
116%enddef
117
118namespace std {
119    template<class T> class deque {
120    public:
121       %std_deque_methods(T);
122    };
123}
124
125
126
127