3#include <Foundation/Math/Math.h>
24 : m_End(reinterpret_cast<ListElement*>(&m_Last))
26 , m_Elements(pAllocator)
27 , m_pFreeElementStack(nullptr)
29 m_First.m_pNext =
reinterpret_cast<ListElement*
>(&m_Last);
30 m_Last.m_pPrev =
reinterpret_cast<ListElement*
>(&m_First);
35 : m_End(reinterpret_cast<ListElement*>(&m_Last))
37 , m_Elements(pAllocator)
38 , m_pFreeElementStack(nullptr)
40 m_First.m_pNext =
reinterpret_cast<ListElement*
>(&m_Last);
41 m_Last.m_pPrev =
reinterpret_cast<ListElement*
>(&m_First);
64 if (m_pFreeElementStack ==
nullptr)
67 pNode = &m_Elements.PeekBack();
71 pNode = m_pFreeElementStack;
72 m_pFreeElementStack = m_pFreeElementStack->m_pNext;
84 if (pNode == &m_Elements.PeekBack())
88 else if (pNode == &m_Elements.PeekFront())
90 m_Elements.PopFront();
94 pNode->m_pNext = m_pFreeElementStack;
95 m_pFreeElementStack = pNode;
117 return ConstIterator(m_First.m_pNext);
135 return (m_uiCount == 0);
142 Remove(GetIterator(), GetEndIterator());
144 m_pFreeElementStack =
nullptr;
151 m_Elements.Compact();
157 PL_ASSERT_DEBUG(!IsEmpty(),
"The container is empty.");
159 return m_First.m_pNext->m_Data;
165 PL_ASSERT_DEBUG(!IsEmpty(),
"The container is empty.");
167 return m_Last.m_pPrev->m_Data;
173 PL_ASSERT_DEBUG(!IsEmpty(),
"The container is empty.");
175 return m_First.m_pNext->m_Data;
181 PL_ASSERT_DEBUG(!IsEmpty(),
"The container is empty.");
183 return m_Last.m_pPrev->m_Data;
190 return *Insert(GetEndIterator());
196 Insert(GetEndIterator(), element);
202 return *Insert(GetIterator());
208 Insert(GetIterator(), element);
214 PL_ASSERT_DEBUG(!IsEmpty(),
"The container is empty.");
222 PL_ASSERT_DEBUG(!IsEmpty(),
"The container is empty.");
230 PL_ASSERT_DEV(pos.m_pElement !=
nullptr,
"The iterator (pos) is invalid.");
233 ListElement* elem = AcquireNode();
235 elem->m_pNext = pos.m_pElement;
236 elem->m_pPrev = pos.m_pElement->m_pPrev;
238 pos.m_pElement->m_pPrev->m_pNext = elem;
239 pos.m_pElement->m_pPrev = elem;
247 PL_ASSERT_DEV(pos.m_pElement !=
nullptr,
"The iterator (pos) is invalid.");
250 ListElement* elem = AcquireNode();
253 elem->m_pNext = pos.m_pElement;
254 elem->m_pPrev = pos.m_pElement->m_pPrev;
256 pos.m_pElement->m_pPrev->m_pNext = elem;
257 pos.m_pElement->m_pPrev = elem;
265 PL_ASSERT_DEV(pos.m_pElement !=
nullptr && first.m_pElement !=
nullptr && last.m_pElement !=
nullptr,
"One of the iterators is invalid.");
267 while (first != last)
277 PL_ASSERT_DEV(!IsEmpty(),
"The container is empty.");
278 PL_ASSERT_DEV(pos.m_pElement !=
nullptr,
"The iterator (pos) is invalid.");
280 ListElement* pPrev = pos.m_pElement->m_pPrev;
281 ListElement* pNext = pos.m_pElement->m_pNext;
283 pPrev->m_pNext = pNext;
284 pNext->m_pPrev = pPrev;
286 ReleaseNode(pos.m_pElement);
294 PL_ASSERT_DEV(!IsEmpty(),
"The container is empty.");
295 PL_ASSERT_DEV(first.m_pElement !=
nullptr && last.m_pElement !=
nullptr,
"An iterator is invalid.");
297 while (first != last)
298 first = Remove(first);
309 while (m_uiCount > uiNewSize)
312 while (m_uiCount < uiNewSize)
322 auto itLhs = GetIterator();
325 while (itLhs.IsValid())
327 if (*itLhs != *itRhs)
337template <
typename T,
typename A>
343template <
typename T,
typename A>
349template <
typename T,
typename A>
355template <
typename T,
typename A>
361template <
typename T,
typename A>
367template <
typename T,
typename A>
Base class for all memory allocators.
Definition Allocator.h:23
A List-class, similar to STL::list.
Definition List.h:12
plUInt32 GetCount() const
Returns the number of elements in the list. O(1) operation.
Definition List_inl.h:127
~plListBase()
Destroys the list and all its content.
Definition List_inl.h:47
void SetCount(plUInt32 uiNewSize)
Sets the number of elements that are in the list.
Definition List_inl.h:307
Iterator Remove(const Iterator &pos)
Erases the element pointed to by the iterator.
Definition List_inl.h:275
plListBase(plAllocator *pAllocator)
Initializes the list to be empty.
Definition List_inl.h:23
void PopFront()
Removes the very first element from the list.
Definition List_inl.h:220
T & PushFront()
Appends a default-constructed element to the front of the list and returns a reference to it.
Definition List_inl.h:200
void PopBack()
Removes the very last element from the list.
Definition List_inl.h:212
const T & PeekBack() const
Returns the very last element in the list.
Definition List_inl.h:179
void Compact()
See plDeque::Compact()
Definition List_inl.h:149
T & PushBack()
Appends a default-constructed element to the list and returns a reference to it.
Definition List_inl.h:188
void operator=(const plListBase< T > &cc)
Copies the list cc into this list.
Definition List_inl.h:53
const T & PeekFront() const
Returns the very first element in the list.
Definition List_inl.h:171
void Clear()
Clears the list, afterwards it is empty.
Definition List_inl.h:139
Iterator Insert(const Iterator &pos, const T &data)
Inserts one element before the position defined by the iterator.
Definition List_inl.h:245
bool IsEmpty() const
Returns whether size == 0. O(1) operation.
Definition List_inl.h:133
Iterator GetEndIterator()
Returns an iterator pointing behind the last element. Necessary if one wants to insert elements at th...
Definition List_inl.h:109
Iterator GetIterator()
Returns an iterator to the first list-element.
Definition List_inl.h:103
bool operator==(const plListBase< T > &rhs) const
Comparison operator.
Definition List_inl.h:317
static void Construct(T *pDestination, size_t uiCount=1)
Constructs uiCount objects of type T in a raw buffer at pDestination.
static void Destruct(T *pDestination, size_t uiCount=1)
Destructs uiCount objects of type T at pDestination.
A forward-iterator. Allows sequential access from front-to-back.
Definition List.h:86