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.
7 * SWIG typemaps for std::list types
8 * ----------------------------------------------------------------------------- */
10 %include <std_common.i>
20 template<class T> class list
25 typedef const T& const_reference;
27 typedef const T& const_iterator;
30 list(unsigned int size, const T& value = T());
31 list(const list<T> &);
34 void assign(unsigned int n, const T& value);
35 void swap(list<T> &x);
37 const_reference front();
38 const_reference back();
39 const_iterator begin();
42 void resize(unsigned int n, T c = T());
45 void push_front(const T& x);
46 void push_back(const T& x);
52 unsigned int size() const;
53 unsigned int max_size() const;
54 void resize(unsigned int n, const T& value);
56 void remove(const T& value);
65 const_reference __getitem__(int i) throw (std::out_of_range)
67 std::list<T>::iterator first = self->begin();
68 int size = int(self->size());
78 else throw std::out_of_range("list index out of range");
80 void __setitem__(int i, const T& x) throw (std::out_of_range)
82 std::list<T>::iterator first = self->begin();
83 int size = int(self->size());
93 else throw std::out_of_range("list index out of range");
95 void __delitem__(int i) throw (std::out_of_range)
97 std::list<T>::iterator first = self->begin();
98 int size = int(self->size());
102 for (int k=0;k<i;k++)
108 else throw std::out_of_range("list index out of range");
110 std::list<T> __getslice__(int i,int j)
112 std::list<T>::iterator first = self->begin();
113 std::list<T>::iterator end = self->end();
115 int size = int(self->size());
119 if (j>size) j = size;
121 if (i>=0 && i<size && j>=0)
123 for (int k=0;k<i;k++)
127 for (int m=0;m<j;m++)
131 std::list<T> tmp(j-i);
132 if (j>i) std::copy(first,end,tmp.begin());
135 else throw std::out_of_range("list index out of range");
137 void __delslice__(int i,int j)
139 std::list<T>::iterator first = self->begin();
140 std::list<T>::iterator end = self->end();
142 int size = int(self->size());
146 if (j>size) j = size;
148 for (int k=0;k<i;k++)
152 for (int m=0;m<=j;m++)
156 self->erase(first,end);
158 void __setslice__(int i,int j, const std::list<T>& v)
160 std::list<T>::iterator first = self->begin();
161 std::list<T>::iterator end = self->end();
163 int size = int(self->size());
167 if (j>size) j = size;
169 for (int k=0;k<i;k++)
173 for (int m=0;m<=j;m++)
177 if (int(v.size()) == j-i)
179 std::copy(v.begin(),v.end(),first);
182 self->erase(first,end);
183 if (i+1 <= int(self->size()))
185 first = self->begin();
186 for (int k=0;k<i;k++)
190 self->insert(first,v.begin(),v.end());
192 else self->insert(self->end(),v.begin(),v.end());
196 unsigned int __len__()
202 return !(self->empty());
204 void append(const T& x)