5#ifndef __IRR_LIST_H_INCLUDED__
6#define __IRR_LIST_H_INCLUDED__
9#include "irrAllocator.h"
27 SKListNode(
const T& e) : Next(0), Prev(0), Element(e) {}
41 Iterator() : Current(0) {}
43 Iterator& operator ++() { Current = Current->Next;
return *
this; }
44 Iterator& operator --() { Current = Current->Prev;
return *
this; }
45 Iterator operator ++(
s32) { Iterator tmp = *
this; Current = Current->Next;
return tmp; }
46 Iterator operator --(
s32) { Iterator tmp = *
this; Current = Current->Prev;
return tmp; }
48 Iterator& operator +=(
s32 num)
52 while (num-- && this->Current != 0) ++(*this);
56 while(num++ && this->Current != 0) --(*this);
61 Iterator operator + (
s32 num)
const { Iterator tmp = *
this;
return tmp += num; }
62 Iterator& operator -=(
s32 num) {
return (*
this)+=(-num); }
63 Iterator operator - (
s32 num)
const {
return (*
this)+ (-num); }
65 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; }
68 bool operator !=(
const ConstIterator& other)
const {
return Current != other.Current; }
70 #if defined (_MSC_VER) && (_MSC_VER < 1300)
71 #pragma warning(disable:4284)
74 T & operator * () {
return Current->Element; }
75 T * operator ->() {
return &Current->Element; }
78 explicit Iterator(SKListNode*
begin) : Current(
begin) {}
83 friend class ConstIterator;
91 ConstIterator() : Current(0) {}
92 ConstIterator(
const Iterator& iter) : Current(iter.Current) {}
94 ConstIterator& operator ++() { Current = Current->Next;
return *
this; }
95 ConstIterator& operator --() { Current = Current->Prev;
return *
this; }
96 ConstIterator operator ++(
s32) { ConstIterator tmp = *
this; Current = Current->Next;
return tmp; }
97 ConstIterator operator --(
s32) { ConstIterator tmp = *
this; Current = Current->Prev;
return tmp; }
99 ConstIterator& operator +=(
s32 num)
103 while(num-- && this->Current != 0) ++(*this);
107 while(num++ && this->Current != 0) --(*this);
112 ConstIterator operator + (
s32 num)
const { ConstIterator tmp = *
this;
return tmp += num; }
113 ConstIterator& operator -=(
s32 num) {
return (*
this)+=(-num); }
114 ConstIterator operator - (
s32 num)
const {
return (*
this)+ (-num); }
116 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; }
119 bool operator !=(
const Iterator& other)
const {
return Current != other.Current; }
121 const T & operator * () {
return Current->Element; }
122 const T * operator ->() {
return &Current->Element; }
124 ConstIterator & operator =(
const Iterator & iterator) { Current = iterator.Current;
return *
this; }
127 explicit ConstIterator(SKListNode*
begin) : Current(
begin) {}
131 friend class Iterator;
132 friend class list<T>;
137 : First(0), Last(0), Size(0) {}
164 SKListNode* node = other.First;
191 SKListNode * next = First->Next;
192 allocator.destruct(First);
193 allocator.deallocate(First);
215 SKListNode* node = allocator.allocate(1);
216 allocator.construct(node, element);
236 SKListNode* node = allocator.allocate(1);
237 allocator.construct(node, element);
259 return Iterator(First);
267 return ConstIterator(First);
283 return ConstIterator(0);
291 return Iterator(Last);
299 return ConstIterator(Last);
310 SKListNode* node = allocator.allocate(1);
311 allocator.construct(node, element);
313 node->Next = it.Current->Next;
315 if (it.Current->Next)
316 it.Current->Next->Prev = node;
318 node->Prev = it.Current;
319 it.Current->Next = node;
322 if (it.Current == Last)
334 SKListNode* node = allocator.allocate(1);
335 allocator.construct(node, element);
337 node->Prev = it.Current->Prev;
339 if (it.Current->Prev)
340 it.Current->Prev->Next = node;
342 node->Next = it.Current;
343 it.Current->Prev = node;
346 if (it.Current == First)
359 Iterator returnIterator(it);
362 if(it.Current == First)
364 First = it.Current->Next;
368 it.Current->Prev->Next = it.Current->Next;
371 if(it.Current == Last)
373 Last = it.Current->Prev;
377 it.Current->Next->Prev = it.Current->Prev;
380 allocator.destruct(it.Current);
381 allocator.deallocate(it.Current);
385 return returnIterator;
Very simple allocator implementation, containers using it can be used across dll boundaries.
Definition irrAllocator.h:26
List iterator for const access.
Definition irrList.h:88
void push_back(const T &element)
Adds an element at the end of the list.
Definition irrList.h:213
list(const list< T > &other)
Copy constructor.
Definition irrList.h:141
void insert_before(const Iterator &it, const T &element)
Inserts an element before an element.
Definition irrList.h:332
u32 size() const
Returns amount of elements in list.
Definition irrList.h:175
Iterator erase(Iterator &it)
Erases an element.
Definition irrList.h:354
void operator=(const list< T > &other)
Assignment operator.
Definition irrList.h:155
~list()
Destructor.
Definition irrList.h:148
ConstIterator end() const
Gets end node.
Definition irrList.h:281
Iterator getLast()
Gets last element.
Definition irrList.h:289
ConstIterator getLast() const
Gets last element.
Definition irrList.h:297
void swap(list< T > &other)
Swap the content of this list container with the content of another list.
Definition irrList.h:393
ConstIterator begin() const
Gets first node.
Definition irrList.h:265
bool empty() const
Checks for empty list.
Definition irrList.h:205
void insert_after(const Iterator &it, const T &element)
Inserts an element after an element.
Definition irrList.h:308
list()
Default constructor for empty list.
Definition irrList.h:136
Iterator end()
Gets end node.
Definition irrList.h:273
void clear()
Clears the list, deletes all elements in the list.
Definition irrList.h:187
Iterator begin()
Gets first node.
Definition irrList.h:257
void push_front(const T &element)
Adds an element at the begin of the list.
Definition irrList.h:234
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
void swap(T1 &a, T2 &b)
swaps the content of the passed parameters
Definition irrMath.h:177
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
signed int s32
32 bit signed variable.
Definition irrTypes.h:66