Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / share / swig / 1.3.26 / ocaml / std_list.i
CommitLineData
920dae64
AT
1// -*- C++ -*-
2// SWIG typemaps for std::list types
3// Art Yerkes
4// Modified from: Jing Cao
5// Aug 1st, 2002
6//
7// Python implementation
8
9%include <std_common.i>
10
11%module std_list
12%{
13#include <list>
14#include <stdexcept>
15%}
16
17
18namespace std{
19 template<class T> class list
20 {
21 public:
22
23 typedef T &reference;
24 typedef const T& const_reference;
25 typedef T &iterator;
26 typedef const T& const_iterator;
27
28 list();
29 list(unsigned int size, const T& value = T());
30 list(const list<T> &);
31
32 ~list();
33 void assign(unsigned int n, const T& value);
34 void swap(list<T> &x);
35
36 const_reference front();
37 const_reference back();
38 const_iterator begin();
39 const_iterator end();
40
41 void resize(unsigned int n, T c = T());
42 bool empty() const;
43
44 void push_front(const T& x);
45 void push_back(const T& x);
46
47
48 void pop_front();
49 void pop_back();
50 void clear();
51 unsigned int size() const;
52 unsigned int max_size() const;
53 void resize(unsigned int n, const T& value);
54
55 void remove(const T& value);
56 void unique();
57 void reverse();
58 void sort();
59
60
61
62 %extend
63 {
64 const_reference __getitem__(int i) throw (std::out_of_range)
65 {
66 std::list<T>::iterator first = self->begin();
67 int size = int(self->size());
68 if (i<0) i += size;
69 if (i>=0 && i<size)
70 {
71 for (int k=0;k<i;k++)
72 {
73 first++;
74 }
75 return *first;
76 }
77 else throw std::out_of_range("list index out of range");
78 }
79 void __setitem__(int i, const T& x) throw (std::out_of_range)
80 {
81 std::list<T>::iterator first = self->begin();
82 int size = int(self->size());
83 if (i<0) i += size;
84 if (i>=0 && i<size)
85 {
86 for (int k=0;k<i;k++)
87 {
88 first++;
89 }
90 *first = x;
91 }
92 else throw std::out_of_range("list index out of range");
93 }
94 void __delitem__(int i) throw (std::out_of_range)
95 {
96 std::list<T>::iterator first = self->begin();
97 int size = int(self->size());
98 if (i<0) i += size;
99 if (i>=0 && i<size)
100 {
101 for (int k=0;k<i;k++)
102 {
103 first++;
104 }
105 self->erase(first);
106 }
107 else throw std::out_of_range("list index out of range");
108 }
109 std::list<T> __getslice__(int i,int j)
110 {
111 std::list<T>::iterator first = self->begin();
112 std::list<T>::iterator end = self->end();
113
114 int size = int(self->size());
115 if (i<0) i += size;
116 if (j<0) j += size;
117 if (i<0) i = 0;
118 if (j>size) j = size;
119 if (i>=j) i=j;
120 if (i>=0 && i<size && j>=0)
121 {
122 for (int k=0;k<i;k++)
123 {
124 first++;
125 }
126 for (int m=0;m<j;m++)
127 {
128 end++;
129 }
130 std::list<T> tmp(j-i);
131 if (j>i) std::copy(first,end,tmp.begin());
132 return tmp;
133 }
134 else throw std::out_of_range("list index out of range");
135 }
136 void __delslice__(int i,int j)
137 {
138 std::list<T>::iterator first = self->begin();
139 std::list<T>::iterator end = self->end();
140
141 int size = int(self->size());
142 if (i<0) i += size;
143 if (j<0) j += size;
144 if (i<0) i = 0;
145 if (j>size) j = size;
146
147 for (int k=0;k<i;k++)
148 {
149 first++;
150 }
151 for (int m=0;m<=j;m++)
152 {
153 end++;
154 }
155 self->erase(first,end);
156 }
157 void __setslice__(int i,int j, const std::list<T>& v)
158 {
159 std::list<T>::iterator first = self->begin();
160 std::list<T>::iterator end = self->end();
161
162 int size = int(self->size());
163 if (i<0) i += size;
164 if (j<0) j += size;
165 if (i<0) i = 0;
166 if (j>size) j = size;
167
168 for (int k=0;k<i;k++)
169 {
170 first++;
171 }
172 for (int m=0;m<=j;m++)
173 {
174 end++;
175 }
176 if (int(v.size()) == j-i)
177 {
178 std::copy(v.begin(),v.end(),first);
179 }
180 else {
181 self->erase(first,end);
182 if (i+1 <= int(self->size()))
183 {
184 first = self->begin();
185 for (int k=0;k<i;k++)
186 {
187 first++;
188 }
189 self->insert(first,v.begin(),v.end());
190 }
191 else self->insert(self->end(),v.begin(),v.end());
192 }
193
194 }
195 unsigned int __len__()
196 {
197 return self->size();
198 }
199 bool __nonzero__()
200 {
201 return !(self->empty());
202 }
203 void append(const T& x)
204 {
205 self->push_back(x);
206 }
207 void pop()
208 {
209 self->pop_back();
210 }
211
212 };
213
214 };
215}
216
217
218
219
220
221