arsa  2.7
Classes | Public Types | Public Member Functions | List of all members
irr::core::list< T > Class Template Reference

Doubly linked list template. More...

#include <irrList.h>

Classes

class  ConstIterator
 List iterator for const access. More...
 
class  Iterator
 List iterator. More...
 

Public Types

typedef T value_type
 
typedef u32 size_type
 

Public Member Functions

 list ()
 Default constructor for empty list. More...
 
 list (const list< T > &other)
 Copy constructor. More...
 
 ~list ()
 Destructor. More...
 
void operator= (const list< T > &other)
 Assignment operator. More...
 
u32 size () const
 Returns amount of elements in list. More...
 
u32 getSize () const
 
void clear ()
 Clears the list, deletes all elements in the list. More...
 
bool empty () const
 Checks for empty list. More...
 
void push_back (const T &element)
 Adds an element at the end of the list. More...
 
void push_front (const T &element)
 Adds an element at the begin of the list. More...
 
Iterator begin ()
 Gets first node. More...
 
ConstIterator begin () const
 Gets first node. More...
 
Iterator end ()
 Gets end node. More...
 
ConstIterator end () const
 Gets end node. More...
 
Iterator getLast ()
 Gets last element. More...
 
ConstIterator getLast () const
 Gets last element. More...
 
void insert_after (const Iterator &it, const T &element)
 Inserts an element after an element. More...
 
void insert_before (const Iterator &it, const T &element)
 Inserts an element before an element. More...
 
Iterator erase (Iterator &it)
 Erases an element. More...
 
void swap (list< T > &other)
 Swap the content of this list container with the content of another list. More...
 

Detailed Description

template<class T>
class irr::core::list< T >

Doubly linked list template.

Definition at line 20 of file irrList.h.

Member Typedef Documentation

◆ size_type

template<class T>
typedef u32 irr::core::list< T >::size_type

Definition at line 398 of file irrList.h.

◆ value_type

template<class T>
typedef T irr::core::list< T >::value_type

Definition at line 397 of file irrList.h.

Constructor & Destructor Documentation

◆ list() [1/2]

template<class T>
irr::core::list< T >::list ( )
inline

Default constructor for empty list.

Definition at line 132 of file irrList.h.

133  : First(0), Last(0), Size(0) {}

◆ list() [2/2]

template<class T>
irr::core::list< T >::list ( const list< T > &  other)
inline

Copy constructor.

Definition at line 137 of file irrList.h.

137  : First(0), Last(0), Size(0)
138  {
139  *this = other;
140  }

◆ ~list()

template<class T>
irr::core::list< T >::~list ( )
inline

Destructor.

Definition at line 144 of file irrList.h.

145  {
146  clear();
147  }
void clear()
Clears the list, deletes all elements in the list.
Definition: irrList.h:183

Member Function Documentation

◆ begin() [1/2]

template<class T>
Iterator irr::core::list< T >::begin ( )
inline

Gets first node.

Returns
A list iterator pointing to the beginning of the list.

Definition at line 253 of file irrList.h.

254  {
255  return Iterator(First);
256  }

◆ begin() [2/2]

template<class T>
ConstIterator irr::core::list< T >::begin ( ) const
inline

Gets first node.

Returns
A const list iterator pointing to the beginning of the list.

Definition at line 261 of file irrList.h.

262  {
263  return ConstIterator(First);
264  }

◆ clear()

template<class T>
void irr::core::list< T >::clear ( void  )
inline

Clears the list, deletes all elements in the list.

All existing iterators of this list will be invalid.

Definition at line 183 of file irrList.h.

184  {
185  while(First)
186  {
187  SKListNode * next = First->Next;
188  allocator.destruct(First);
189  allocator.deallocate(First);
190  First = next;
191  }
192 
193  //First = 0; handled by loop
194  Last = 0;
195  Size = 0;
196  }
const struct SDL_AssertData * next
Definition: SDL_assert.h:119
void destruct(T *ptr)
Destruct an element.
Definition: irrAllocator.h:51
void deallocate(T *ptr)
Deallocate memory for an array of objects.
Definition: irrAllocator.h:39

◆ empty()

template<class T>
bool irr::core::list< T >::empty ( ) const
inline

Checks for empty list.

Returns
True if the list is empty and false if not.

Definition at line 201 of file irrList.h.

202  {
203  return (First == 0);
204  }

◆ end() [1/2]

template<class T>
Iterator irr::core::list< T >::end ( )
inline

Gets end node.

Returns
List iterator pointing to null.

Definition at line 269 of file irrList.h.

270  {
271  return Iterator(0);
272  }

◆ end() [2/2]

template<class T>
ConstIterator irr::core::list< T >::end ( ) const
inline

Gets end node.

Returns
Const list iterator pointing to null.

Definition at line 277 of file irrList.h.

278  {
279  return ConstIterator(0);
280  }

◆ erase()

template<class T>
Iterator irr::core::list< T >::erase ( Iterator it)
inline

Erases an element.

Parameters
itIterator pointing to the element which shall be erased.
Returns
Iterator pointing to next element.

Definition at line 350 of file irrList.h.

351  {
352  // suggest changing this to a const Iterator& and
353  // working around line: it.Current = 0 (possibly with a mutable, or just let it be garbage?)
354 
355  Iterator returnIterator(it);
356  ++returnIterator;
357 
358  if(it.Current == First)
359  {
360  First = it.Current->Next;
361  }
362  else
363  {
364  it.Current->Prev->Next = it.Current->Next;
365  }
366 
367  if(it.Current == Last)
368  {
369  Last = it.Current->Prev;
370  }
371  else
372  {
373  it.Current->Next->Prev = it.Current->Prev;
374  }
375 
376  allocator.destruct(it.Current);
377  allocator.deallocate(it.Current);
378  it.Current = 0;
379  --Size;
380 
381  return returnIterator;
382  }
void destruct(T *ptr)
Destruct an element.
Definition: irrAllocator.h:51
void deallocate(T *ptr)
Deallocate memory for an array of objects.
Definition: irrAllocator.h:39

◆ getLast() [1/2]

template<class T>
Iterator irr::core::list< T >::getLast ( )
inline

Gets last element.

Returns
List iterator pointing to the last element of the list.

Definition at line 285 of file irrList.h.

286  {
287  return Iterator(Last);
288  }

◆ getLast() [2/2]

template<class T>
ConstIterator irr::core::list< T >::getLast ( ) const
inline

Gets last element.

Returns
Const list iterator pointing to the last element of the list.

Definition at line 293 of file irrList.h.

294  {
295  return ConstIterator(Last);
296  }

◆ getSize()

template<class T>
u32 irr::core::list< T >::getSize ( ) const
inline

Definition at line 175 of file irrList.h.

176  {
177  return Size;
178  }

◆ insert_after()

template<class T>
void irr::core::list< T >::insert_after ( const Iterator it,
const T &  element 
)
inline

Inserts an element after an element.

Parameters
itIterator pointing to element after which the new element should be inserted.
elementThe new element to be inserted into the list.

Definition at line 304 of file irrList.h.

305  {
306  SKListNode* node = allocator.allocate(1);
307  allocator.construct(node, element);
308 
309  node->Next = it.Current->Next;
310 
311  if (it.Current->Next)
312  it.Current->Next->Prev = node;
313 
314  node->Prev = it.Current;
315  it.Current->Next = node;
316  ++Size;
317 
318  if (it.Current == Last)
319  Last = node;
320  }
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition: irrAllocator.h:33
void construct(T *ptr, const T &e)
Construct an element.
Definition: irrAllocator.h:45

◆ insert_before()

template<class T>
void irr::core::list< T >::insert_before ( const Iterator it,
const T &  element 
)
inline

Inserts an element before an element.

Parameters
itIterator pointing to element before which the new element should be inserted.
elementThe new element to be inserted into the list.

Definition at line 328 of file irrList.h.

329  {
330  SKListNode* node = allocator.allocate(1);
331  allocator.construct(node, element);
332 
333  node->Prev = it.Current->Prev;
334 
335  if (it.Current->Prev)
336  it.Current->Prev->Next = node;
337 
338  node->Next = it.Current;
339  it.Current->Prev = node;
340  ++Size;
341 
342  if (it.Current == First)
343  First = node;
344  }
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition: irrAllocator.h:33
void construct(T *ptr, const T &e)
Construct an element.
Definition: irrAllocator.h:45

◆ operator=()

template<class T>
void irr::core::list< T >::operator= ( const list< T > &  other)
inline

Assignment operator.

Definition at line 151 of file irrList.h.

152  {
153  if(&other == this)
154  {
155  return;
156  }
157 
158  clear();
159 
160  SKListNode* node = other.First;
161  while(node)
162  {
163  push_back(node->Element);
164  node = node->Next;
165  }
166  }
void push_back(const T &element)
Adds an element at the end of the list.
Definition: irrList.h:209
void clear()
Clears the list, deletes all elements in the list.
Definition: irrList.h:183

◆ push_back()

template<class T>
void irr::core::list< T >::push_back ( const T &  element)
inline

Adds an element at the end of the list.

Parameters
elementElement to add to the list.

Definition at line 209 of file irrList.h.

210  {
211  SKListNode* node = allocator.allocate(1);
212  allocator.construct(node, element);
213 
214  ++Size;
215 
216  if (First == 0)
217  First = node;
218 
219  node->Prev = Last;
220 
221  if (Last != 0)
222  Last->Next = node;
223 
224  Last = node;
225  }
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition: irrAllocator.h:33
void construct(T *ptr, const T &e)
Construct an element.
Definition: irrAllocator.h:45

◆ push_front()

template<class T>
void irr::core::list< T >::push_front ( const T &  element)
inline

Adds an element at the begin of the list.

Parameters
elementElement to add to the list.

Definition at line 230 of file irrList.h.

231  {
232  SKListNode* node = allocator.allocate(1);
233  allocator.construct(node, element);
234 
235  ++Size;
236 
237  if (First == 0)
238  {
239  Last = node;
240  First = node;
241  }
242  else
243  {
244  node->Next = First;
245  First->Prev = node;
246  First = node;
247  }
248  }
T * allocate(size_t cnt)
Allocate memory for an array of objects.
Definition: irrAllocator.h:33
void construct(T *ptr, const T &e)
Construct an element.
Definition: irrAllocator.h:45

◆ size()

template<class T>
u32 irr::core::list< T >::size ( ) const
inline

Returns amount of elements in list.

Returns
Amount of elements in the list.

Definition at line 171 of file irrList.h.

172  {
173  return Size;
174  }

◆ swap()

template<class T>
void irr::core::list< T >::swap ( list< T > &  other)
inline

Swap the content of this list container with the content of another list.

Afterward this object will contain the content of the other object and the other object will contain the content of this object. Iterators will afterward be valid for the swapped object.

Parameters
otherSwap content with this object

Definition at line 389 of file irrList.h.

390  {
391  core::swap(First, other.First);
392  core::swap(Last, other.Last);
393  core::swap(Size, other.Size);
394  core::swap(allocator, other.allocator); // memory is still released by the same allocator used for allocation
395  }
void swap(T1 &a, T2 &b)
swaps the content of the passed parameters
Definition: irrMath.h:178

The documentation for this class was generated from the following file: