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_list.i 6 * 7 * SWIG typemaps for std::list types 8 * 9 * To use, add: 10 * 11 * %include "std_list.i" 12 * 13 * to your interface file. You will also need to include a template directive 14 * for each instance of the list container you want to use in your application. 15 * e.g. 16 * 17 * %template (intlist) std::list<int>; 18 * %template (floatlist) std::list<float>; 19 * ----------------------------------------------------------------------------- */ 20 21%module std_list 22%warnfilter(468) std::list; 23 24%{ 25#include <list> 26#include <stdexcept> 27%} 28 29 30namespace std{ 31 template<class T> class list 32 { 33 public: 34 35 typedef T &reference; 36 typedef const T& const_reference; 37 typedef T &iterator; 38 typedef const T& const_iterator; 39 40 list(); 41 list(unsigned int size, const T& value = T()); 42 list(const list<T> &); 43 44 ~list(); 45 void assign(unsigned int n, const T& value); 46 void swap(list<T> &x); 47 48 const_reference front(); 49 const_reference back(); 50 const_iterator begin(); 51 const_iterator end(); 52 53 void resize(unsigned int n, T c = T()); 54 bool empty() const; 55 56 void push_front(const T& INPUT); 57 void push_back(const T& INPUT); 58 59 60 void pop_front(); 61 void pop_back(); 62 void clear(); 63 unsigned int size() const; 64 unsigned int max_size() const; 65 void resize(unsigned int n, const T& INPUT); 66 67 void remove(const T& INPUT); 68 void unique(); 69 void reverse(); 70 void sort(); 71 72 %extend 73 { 74 %typemap(lout) T &__getitem__ "(cl::setq ACL_ffresult (ff:fslot-value-typed '$*out_fftype :c $body))"; 75 %typemap(lout) T *__getitem__ "(cl::setq ACL_ffresult (make-instance '$lclass :foreign-address $body))"; 76 77 const_reference __getitem__(int i) throw (std::out_of_range) 78 { 79 std::list<T>::iterator first = self->begin(); 80 int size = int(self->size()); 81 if (i<0) i += size; 82 if (i>=0 && i<size) 83 { 84 for (int k=0;k<i;k++) 85 { 86 first++; 87 } 88 return *first; 89 } 90 else throw std::out_of_range("list index out of range"); 91 } 92 void __setitem__(int i, const T& INPUT) throw (std::out_of_range) 93 { 94 std::list<T>::iterator first = self->begin(); 95 int size = int(self->size()); 96 if (i<0) i += size; 97 if (i>=0 && i<size) 98 { 99 for (int k=0;k<i;k++) 100 { 101 first++; 102 } 103 *first = INPUT; 104 } 105 else throw std::out_of_range("list index out of range"); 106 } 107 void __delitem__(int i) throw (std::out_of_range) 108 { 109 std::list<T>::iterator first = self->begin(); 110 int size = int(self->size()); 111 if (i<0) i += size; 112 if (i>=0 && i<size) 113 { 114 for (int k=0;k<i;k++) 115 { 116 first++; 117 } 118 self->erase(first); 119 } 120 else throw std::out_of_range("list index out of range"); 121 } 122 std::list<T> __getslice__(int i,int j) 123 { 124 std::list<T>::iterator first = self->begin(); 125 std::list<T>::iterator end = self->end(); 126 127 int size = int(self->size()); 128 if (i<0) i += size; 129 if (j<0) j += size; 130 if (i<0) i = 0; 131 if (j>size) j = size; 132 if (i>=j) i=j; 133 if (i>=0 && i<size && j>=0) 134 { 135 for (int k=0;k<i;k++) 136 { 137 first++; 138 } 139 for (int m=0;m<j;m++) 140 { 141 end++; 142 } 143 std::list<T> tmp(j-i); 144 if (j>i) std::copy(first,end,tmp.begin()); 145 return tmp; 146 } 147 else throw std::out_of_range("list index out of range"); 148 } 149 void __delslice__(int i,int j) 150 { 151 std::list<T>::iterator first = self->begin(); 152 std::list<T>::iterator end = self->end(); 153 154 int size = int(self->size()); 155 if (i<0) i += size; 156 if (j<0) j += size; 157 if (i<0) i = 0; 158 if (j>size) j = size; 159 160 for (int k=0;k<i;k++) 161 { 162 first++; 163 } 164 for (int m=0;m<=j;m++) 165 { 166 end++; 167 } 168 self->erase(first,end); 169 } 170 void __setslice__(int i,int j, const std::list<T>& v) 171 { 172 std::list<T>::iterator first = self->begin(); 173 std::list<T>::iterator end = self->end(); 174 175 int size = int(self->size()); 176 if (i<0) i += size; 177 if (j<0) j += size; 178 if (i<0) i = 0; 179 if (j>size) j = size; 180 181 for (int k=0;k<i;k++) 182 { 183 first++; 184 } 185 for (int m=0;m<=j;m++) 186 { 187 end++; 188 } 189 if (int(v.size()) == j-i) 190 { 191 std::copy(v.begin(),v.end(),first); 192 } 193 else { 194 self->erase(first,end); 195 if (i+1 <= int(self->size())) 196 { 197 first = self->begin(); 198 for (int k=0;k<i;k++) 199 { 200 first++; 201 } 202 self->insert(first,v.begin(),v.end()); 203 } 204 else self->insert(self->end(),v.begin(),v.end()); 205 } 206 207 } 208 unsigned int __len__() 209 { 210 return self->size(); 211 } 212 bool __nonzero__() 213 { 214 return !(self->empty()); 215 } 216 void append(const T& INPUT) 217 { 218 self->push_back(INPUT); 219 } 220 void pop() 221 { 222 self->pop_back(); 223 } 224 225 }; 226 }; 227} 228 229 230 231 232 233 234