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