aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/include/irrList.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/include/irrList.h')
-rw-r--r--libraries/irrlicht-1.8/include/irrList.h832
1 files changed, 416 insertions, 416 deletions
diff --git a/libraries/irrlicht-1.8/include/irrList.h b/libraries/irrlicht-1.8/include/irrList.h
index 54eed83..a84afd5 100644
--- a/libraries/irrlicht-1.8/include/irrList.h
+++ b/libraries/irrlicht-1.8/include/irrList.h
@@ -1,416 +1,416 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#ifndef __IRR_LIST_H_INCLUDED__ 5#ifndef __IRR_LIST_H_INCLUDED__
6#define __IRR_LIST_H_INCLUDED__ 6#define __IRR_LIST_H_INCLUDED__
7 7
8#include "irrTypes.h" 8#include "irrTypes.h"
9#include "irrAllocator.h" 9#include "irrAllocator.h"
10#include "irrMath.h" 10#include "irrMath.h"
11 11
12namespace irr 12namespace irr
13{ 13{
14namespace core 14namespace core
15{ 15{
16 16
17 17
18//! Doubly linked list template. 18//! Doubly linked list template.
19template <class T> 19template <class T>
20class list 20class list
21{ 21{
22private: 22private:
23 23
24 //! List element node with pointer to previous and next element in the list. 24 //! List element node with pointer to previous and next element in the list.
25 struct SKListNode 25 struct SKListNode
26 { 26 {
27 SKListNode(const T& e) : Next(0), Prev(0), Element(e) {} 27 SKListNode(const T& e) : Next(0), Prev(0), Element(e) {}
28 28
29 SKListNode* Next; 29 SKListNode* Next;
30 SKListNode* Prev; 30 SKListNode* Prev;
31 T Element; 31 T Element;
32 }; 32 };
33 33
34public: 34public:
35 class ConstIterator; 35 class ConstIterator;
36 36
37 //! List iterator. 37 //! List iterator.
38 class Iterator 38 class Iterator
39 { 39 {
40 public: 40 public:
41 Iterator() : Current(0) {} 41 Iterator() : Current(0) {}
42 42
43 Iterator& operator ++() { Current = Current->Next; return *this; } 43 Iterator& operator ++() { Current = Current->Next; return *this; }
44 Iterator& operator --() { Current = Current->Prev; return *this; } 44 Iterator& operator --() { Current = Current->Prev; return *this; }
45 Iterator operator ++(s32) { Iterator tmp = *this; Current = Current->Next; return tmp; } 45 Iterator operator ++(s32) { Iterator tmp = *this; Current = Current->Next; return tmp; }
46 Iterator operator --(s32) { Iterator tmp = *this; Current = Current->Prev; return tmp; } 46 Iterator operator --(s32) { Iterator tmp = *this; Current = Current->Prev; return tmp; }
47 47
48 Iterator& operator +=(s32 num) 48 Iterator& operator +=(s32 num)
49 { 49 {
50 if(num > 0) 50 if(num > 0)
51 { 51 {
52 while (num-- && this->Current != 0) ++(*this); 52 while (num-- && this->Current != 0) ++(*this);
53 } 53 }
54 else 54 else
55 { 55 {
56 while(num++ && this->Current != 0) --(*this); 56 while(num++ && this->Current != 0) --(*this);
57 } 57 }
58 return *this; 58 return *this;
59 } 59 }
60 60
61 Iterator operator + (s32 num) const { Iterator tmp = *this; return tmp += num; } 61 Iterator operator + (s32 num) const { Iterator tmp = *this; return tmp += num; }
62 Iterator& operator -=(s32 num) { return (*this)+=(-num); } 62 Iterator& operator -=(s32 num) { return (*this)+=(-num); }
63 Iterator operator - (s32 num) const { return (*this)+ (-num); } 63 Iterator operator - (s32 num) const { return (*this)+ (-num); }
64 64
65 bool operator ==(const Iterator& other) const { return Current == other.Current; } 65 bool operator ==(const Iterator& other) const { return Current == other.Current; }
66 bool operator !=(const Iterator& other) const { return Current != other.Current; } 66 bool operator !=(const Iterator& other) const { return Current != other.Current; }
67 bool operator ==(const ConstIterator& other) const { return Current == other.Current; } 67 bool operator ==(const ConstIterator& other) const { return Current == other.Current; }
68 bool operator !=(const ConstIterator& other) const { return Current != other.Current; } 68 bool operator !=(const ConstIterator& other) const { return Current != other.Current; }
69 69
70 #if defined (_MSC_VER) && (_MSC_VER < 1300) 70 #if defined (_MSC_VER) && (_MSC_VER < 1300)
71 #pragma warning(disable:4284) // infix notation problem when using iterator operator -> 71 #pragma warning(disable:4284) // infix notation problem when using iterator operator ->
72 #endif 72 #endif
73 73
74 T & operator * () { return Current->Element; } 74 T & operator * () { return Current->Element; }
75 T * operator ->() { return &Current->Element; } 75 T * operator ->() { return &Current->Element; }
76 76
77 private: 77 private:
78 explicit Iterator(SKListNode* begin) : Current(begin) {} 78 explicit Iterator(SKListNode* begin) : Current(begin) {}
79 79
80 SKListNode* Current; 80 SKListNode* Current;
81 81
82 friend class list<T>; 82 friend class list<T>;
83 friend class ConstIterator; 83 friend class ConstIterator;
84 }; 84 };
85 85
86 //! List iterator for const access. 86 //! List iterator for const access.
87 class ConstIterator 87 class ConstIterator
88 { 88 {
89 public: 89 public:
90 90
91 ConstIterator() : Current(0) {} 91 ConstIterator() : Current(0) {}
92 ConstIterator(const Iterator& iter) : Current(iter.Current) {} 92 ConstIterator(const Iterator& iter) : Current(iter.Current) {}
93 93
94 ConstIterator& operator ++() { Current = Current->Next; return *this; } 94 ConstIterator& operator ++() { Current = Current->Next; return *this; }
95 ConstIterator& operator --() { Current = Current->Prev; return *this; } 95 ConstIterator& operator --() { Current = Current->Prev; return *this; }
96 ConstIterator operator ++(s32) { ConstIterator tmp = *this; Current = Current->Next; return tmp; } 96 ConstIterator operator ++(s32) { ConstIterator tmp = *this; Current = Current->Next; return tmp; }
97 ConstIterator operator --(s32) { ConstIterator tmp = *this; Current = Current->Prev; return tmp; } 97 ConstIterator operator --(s32) { ConstIterator tmp = *this; Current = Current->Prev; return tmp; }
98 98
99 ConstIterator& operator +=(s32 num) 99 ConstIterator& operator +=(s32 num)
100 { 100 {
101 if(num > 0) 101 if(num > 0)
102 { 102 {
103 while(num-- && this->Current != 0) ++(*this); 103 while(num-- && this->Current != 0) ++(*this);
104 } 104 }
105 else 105 else
106 { 106 {
107 while(num++ && this->Current != 0) --(*this); 107 while(num++ && this->Current != 0) --(*this);
108 } 108 }
109 return *this; 109 return *this;
110 } 110 }
111 111
112 ConstIterator operator + (s32 num) const { ConstIterator tmp = *this; return tmp += num; } 112 ConstIterator operator + (s32 num) const { ConstIterator tmp = *this; return tmp += num; }
113 ConstIterator& operator -=(s32 num) { return (*this)+=(-num); } 113 ConstIterator& operator -=(s32 num) { return (*this)+=(-num); }
114 ConstIterator operator - (s32 num) const { return (*this)+ (-num); } 114 ConstIterator operator - (s32 num) const { return (*this)+ (-num); }
115 115
116 bool operator ==(const ConstIterator& other) const { return Current == other.Current; } 116 bool operator ==(const ConstIterator& other) const { return Current == other.Current; }
117 bool operator !=(const ConstIterator& other) const { return Current != other.Current; } 117 bool operator !=(const ConstIterator& other) const { return Current != other.Current; }
118 bool operator ==(const Iterator& other) const { return Current == other.Current; } 118 bool operator ==(const Iterator& other) const { return Current == other.Current; }
119 bool operator !=(const Iterator& other) const { return Current != other.Current; } 119 bool operator !=(const Iterator& other) const { return Current != other.Current; }
120 120
121 const T & operator * () { return Current->Element; } 121 const T & operator * () { return Current->Element; }
122 const T * operator ->() { return &Current->Element; } 122 const T * operator ->() { return &Current->Element; }
123 123
124 ConstIterator & operator =(const Iterator & iterator) { Current = iterator.Current; return *this; } 124 ConstIterator & operator =(const Iterator & iterator) { Current = iterator.Current; return *this; }
125 125
126 private: 126 private:
127 explicit ConstIterator(SKListNode* begin) : Current(begin) {} 127 explicit ConstIterator(SKListNode* begin) : Current(begin) {}
128 128
129 SKListNode* Current; 129 SKListNode* Current;
130 130
131 friend class Iterator; 131 friend class Iterator;
132 friend class list<T>; 132 friend class list<T>;
133 }; 133 };
134 134
135 //! Default constructor for empty list. 135 //! Default constructor for empty list.
136 list() 136 list()
137 : First(0), Last(0), Size(0) {} 137 : First(0), Last(0), Size(0) {}
138 138
139 139
140 //! Copy constructor. 140 //! Copy constructor.
141 list(const list<T>& other) : First(0), Last(0), Size(0) 141 list(const list<T>& other) : First(0), Last(0), Size(0)
142 { 142 {
143 *this = other; 143 *this = other;
144 } 144 }
145 145
146 146
147 //! Destructor 147 //! Destructor
148 ~list() 148 ~list()
149 { 149 {
150 clear(); 150 clear();
151 } 151 }
152 152
153 153
154 //! Assignment operator 154 //! Assignment operator
155 void operator=(const list<T>& other) 155 void operator=(const list<T>& other)
156 { 156 {
157 if(&other == this) 157 if(&other == this)
158 { 158 {
159 return; 159 return;
160 } 160 }
161 161
162 clear(); 162 clear();
163 163
164 SKListNode* node = other.First; 164 SKListNode* node = other.First;
165 while(node) 165 while(node)
166 { 166 {
167 push_back(node->Element); 167 push_back(node->Element);
168 node = node->Next; 168 node = node->Next;
169 } 169 }
170 } 170 }
171 171
172 172
173 //! Returns amount of elements in list. 173 //! Returns amount of elements in list.
174 /** \return Amount of elements in the list. */ 174 /** \return Amount of elements in the list. */
175 u32 size() const 175 u32 size() const
176 { 176 {
177 return Size; 177 return Size;
178 } 178 }
179 u32 getSize() const 179 u32 getSize() const
180 { 180 {
181 return Size; 181 return Size;
182 } 182 }
183 183
184 184
185 //! Clears the list, deletes all elements in the list. 185 //! Clears the list, deletes all elements in the list.
186 /** All existing iterators of this list will be invalid. */ 186 /** All existing iterators of this list will be invalid. */
187 void clear() 187 void clear()
188 { 188 {
189 while(First) 189 while(First)
190 { 190 {
191 SKListNode * next = First->Next; 191 SKListNode * next = First->Next;
192 allocator.destruct(First); 192 allocator.destruct(First);
193 allocator.deallocate(First); 193 allocator.deallocate(First);
194 First = next; 194 First = next;
195 } 195 }
196 196
197 //First = 0; handled by loop 197 //First = 0; handled by loop
198 Last = 0; 198 Last = 0;
199 Size = 0; 199 Size = 0;
200 } 200 }
201 201
202 202
203 //! Checks for empty list. 203 //! Checks for empty list.
204 /** \return True if the list is empty and false if not. */ 204 /** \return True if the list is empty and false if not. */
205 bool empty() const 205 bool empty() const
206 { 206 {
207 return (First == 0); 207 return (First == 0);
208 } 208 }
209 209
210 210
211 //! Adds an element at the end of the list. 211 //! Adds an element at the end of the list.
212 /** \param element Element to add to the list. */ 212 /** \param element Element to add to the list. */
213 void push_back(const T& element) 213 void push_back(const T& element)
214 { 214 {
215 SKListNode* node = allocator.allocate(1); 215 SKListNode* node = allocator.allocate(1);
216 allocator.construct(node, element); 216 allocator.construct(node, element);
217 217
218 ++Size; 218 ++Size;
219 219
220 if (First == 0) 220 if (First == 0)
221 First = node; 221 First = node;
222 222
223 node->Prev = Last; 223 node->Prev = Last;
224 224
225 if (Last != 0) 225 if (Last != 0)
226 Last->Next = node; 226 Last->Next = node;
227 227
228 Last = node; 228 Last = node;
229 } 229 }
230 230
231 231
232 //! Adds an element at the begin of the list. 232 //! Adds an element at the begin of the list.
233 /** \param element: Element to add to the list. */ 233 /** \param element: Element to add to the list. */
234 void push_front(const T& element) 234 void push_front(const T& element)
235 { 235 {
236 SKListNode* node = allocator.allocate(1); 236 SKListNode* node = allocator.allocate(1);
237 allocator.construct(node, element); 237 allocator.construct(node, element);
238 238
239 ++Size; 239 ++Size;
240 240
241 if (First == 0) 241 if (First == 0)
242 { 242 {
243 Last = node; 243 Last = node;
244 First = node; 244 First = node;
245 } 245 }
246 else 246 else
247 { 247 {
248 node->Next = First; 248 node->Next = First;
249 First->Prev = node; 249 First->Prev = node;
250 First = node; 250 First = node;
251 } 251 }
252 } 252 }
253 253
254 254
255 //! Gets first node. 255 //! Gets first node.
256 /** \return A list iterator pointing to the beginning of the list. */ 256 /** \return A list iterator pointing to the beginning of the list. */
257 Iterator begin() 257 Iterator begin()
258 { 258 {
259 return Iterator(First); 259 return Iterator(First);
260 } 260 }
261 261
262 262
263 //! Gets first node. 263 //! Gets first node.
264 /** \return A const list iterator pointing to the beginning of the list. */ 264 /** \return A const list iterator pointing to the beginning of the list. */
265 ConstIterator begin() const 265 ConstIterator begin() const
266 { 266 {
267 return ConstIterator(First); 267 return ConstIterator(First);
268 } 268 }
269 269
270 270
271 //! Gets end node. 271 //! Gets end node.
272 /** \return List iterator pointing to null. */ 272 /** \return List iterator pointing to null. */
273 Iterator end() 273 Iterator end()
274 { 274 {
275 return Iterator(0); 275 return Iterator(0);
276 } 276 }
277 277
278 278
279 //! Gets end node. 279 //! Gets end node.
280 /** \return Const list iterator pointing to null. */ 280 /** \return Const list iterator pointing to null. */
281 ConstIterator end() const 281 ConstIterator end() const
282 { 282 {
283 return ConstIterator(0); 283 return ConstIterator(0);
284 } 284 }
285 285
286 286
287 //! Gets last element. 287 //! Gets last element.
288 /** \return List iterator pointing to the last element of the list. */ 288 /** \return List iterator pointing to the last element of the list. */
289 Iterator getLast() 289 Iterator getLast()
290 { 290 {
291 return Iterator(Last); 291 return Iterator(Last);
292 } 292 }
293 293
294 294
295 //! Gets last element. 295 //! Gets last element.
296 /** \return Const list iterator pointing to the last element of the list. */ 296 /** \return Const list iterator pointing to the last element of the list. */
297 ConstIterator getLast() const 297 ConstIterator getLast() const
298 { 298 {
299 return ConstIterator(Last); 299 return ConstIterator(Last);
300 } 300 }
301 301
302 302
303 //! Inserts an element after an element. 303 //! Inserts an element after an element.
304 /** \param it Iterator pointing to element after which the new element 304 /** \param it Iterator pointing to element after which the new element
305 should be inserted. 305 should be inserted.
306 \param element The new element to be inserted into the list. 306 \param element The new element to be inserted into the list.
307 */ 307 */
308 void insert_after(const Iterator& it, const T& element) 308 void insert_after(const Iterator& it, const T& element)
309 { 309 {
310 SKListNode* node = allocator.allocate(1); 310 SKListNode* node = allocator.allocate(1);
311 allocator.construct(node, element); 311 allocator.construct(node, element);
312 312
313 node->Next = it.Current->Next; 313 node->Next = it.Current->Next;
314 314
315 if (it.Current->Next) 315 if (it.Current->Next)
316 it.Current->Next->Prev = node; 316 it.Current->Next->Prev = node;
317 317
318 node->Prev = it.Current; 318 node->Prev = it.Current;
319 it.Current->Next = node; 319 it.Current->Next = node;
320 ++Size; 320 ++Size;
321 321
322 if (it.Current == Last) 322 if (it.Current == Last)
323 Last = node; 323 Last = node;
324 } 324 }
325 325
326 326
327 //! Inserts an element before an element. 327 //! Inserts an element before an element.
328 /** \param it Iterator pointing to element before which the new element 328 /** \param it Iterator pointing to element before which the new element
329 should be inserted. 329 should be inserted.
330 \param element The new element to be inserted into the list. 330 \param element The new element to be inserted into the list.
331 */ 331 */
332 void insert_before(const Iterator& it, const T& element) 332 void insert_before(const Iterator& it, const T& element)
333 { 333 {
334 SKListNode* node = allocator.allocate(1); 334 SKListNode* node = allocator.allocate(1);
335 allocator.construct(node, element); 335 allocator.construct(node, element);
336 336
337 node->Prev = it.Current->Prev; 337 node->Prev = it.Current->Prev;
338 338
339 if (it.Current->Prev) 339 if (it.Current->Prev)
340 it.Current->Prev->Next = node; 340 it.Current->Prev->Next = node;
341 341
342 node->Next = it.Current; 342 node->Next = it.Current;
343 it.Current->Prev = node; 343 it.Current->Prev = node;
344 ++Size; 344 ++Size;
345 345
346 if (it.Current == First) 346 if (it.Current == First)
347 First = node; 347 First = node;
348 } 348 }
349 349
350 350
351 //! Erases an element. 351 //! Erases an element.
352 /** \param it Iterator pointing to the element which shall be erased. 352 /** \param it Iterator pointing to the element which shall be erased.
353 \return Iterator pointing to next element. */ 353 \return Iterator pointing to next element. */
354 Iterator erase(Iterator& it) 354 Iterator erase(Iterator& it)
355 { 355 {
356 // suggest changing this to a const Iterator& and 356 // suggest changing this to a const Iterator& and
357 // working around line: it.Current = 0 (possibly with a mutable, or just let it be garbage?) 357 // working around line: it.Current = 0 (possibly with a mutable, or just let it be garbage?)
358 358
359 Iterator returnIterator(it); 359 Iterator returnIterator(it);
360 ++returnIterator; 360 ++returnIterator;
361 361
362 if(it.Current == First) 362 if(it.Current == First)
363 { 363 {
364 First = it.Current->Next; 364 First = it.Current->Next;
365 } 365 }
366 else 366 else
367 { 367 {
368 it.Current->Prev->Next = it.Current->Next; 368 it.Current->Prev->Next = it.Current->Next;
369 } 369 }
370 370
371 if(it.Current == Last) 371 if(it.Current == Last)
372 { 372 {
373 Last = it.Current->Prev; 373 Last = it.Current->Prev;
374 } 374 }
375 else 375 else
376 { 376 {
377 it.Current->Next->Prev = it.Current->Prev; 377 it.Current->Next->Prev = it.Current->Prev;
378 } 378 }
379 379
380 allocator.destruct(it.Current); 380 allocator.destruct(it.Current);
381 allocator.deallocate(it.Current); 381 allocator.deallocate(it.Current);
382 it.Current = 0; 382 it.Current = 0;
383 --Size; 383 --Size;
384 384
385 return returnIterator; 385 return returnIterator;
386 } 386 }
387 387
388 //! Swap the content of this list container with the content of another list 388 //! Swap the content of this list container with the content of another list
389 /** Afterwards this object will contain the content of the other object and the other 389 /** Afterwards this object will contain the content of the other object and the other
390 object will contain the content of this object. Iterators will afterwards be valid for 390 object will contain the content of this object. Iterators will afterwards be valid for
391 the swapped object. 391 the swapped object.
392 \param other Swap content with this object */ 392 \param other Swap content with this object */
393 void swap(list<T>& other) 393 void swap(list<T>& other)
394 { 394 {
395 core::swap(First, other.First); 395 core::swap(First, other.First);
396 core::swap(Last, other.Last); 396 core::swap(Last, other.Last);
397 core::swap(Size, other.Size); 397 core::swap(Size, other.Size);
398 core::swap(allocator, other.allocator); // memory is still released by the same allocator used for allocation 398 core::swap(allocator, other.allocator); // memory is still released by the same allocator used for allocation
399 } 399 }
400 400
401 401
402private: 402private:
403 403
404 SKListNode* First; 404 SKListNode* First;
405 SKListNode* Last; 405 SKListNode* Last;
406 u32 Size; 406 u32 Size;
407 irrAllocator<SKListNode> allocator; 407 irrAllocator<SKListNode> allocator;
408 408
409}; 409};
410 410
411 411
412} // end namespace core 412} // end namespace core
413}// end namespace irr 413}// end namespace irr
414 414
415#endif 415#endif
416 416