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