25 #include "dCoreStdafx.h"
28 #include "dContainersAlloc.h"
30 template<
class T,
class allocator = dContainersAlloc<T> >
44 m_prev->m_next =
this;
48 m_next->m_prev =
this;
60 m_prev->m_next =
this;
64 m_next->m_prev =
this;
76 m_prev->m_next = m_next;
80 m_next->m_prev = m_prev;
118 friend class dList<T, allocator>;
127 m_list = (
dList *)&me;
134 operator dInt32()
const
136 return m_ptr !=
nullptr;
139 bool operator== (
const Iterator &target)
const
141 return (m_ptr == target.m_ptr) && (m_list == target.m_list);
146 m_ptr = m_list->GetFirst();
151 m_ptr = m_list->GetLast();
162 m_ptr = m_ptr->m_next();
165 void operator++ (dInt32)
168 m_ptr = m_ptr->GetNext();
174 m_ptr = m_ptr->GetPrev();
177 void operator-- (dInt32)
180 m_ptr = m_ptr->GetPrev();
183 T &operator* ()
const
185 return m_ptr->GetInfo();
205 operator dInt32()
const;
206 const dInt32 GetCount()
const;
216 void RotateToEnd (
dListNode*
const node);
217 void RotateToBegin (
dListNode*
const node);
221 dListNode* Find (
const T &element)
const;
222 dListNode* GetNodeFromInfo (T &m_info)
const;
224 void Remove (
const T &element);
229 bool SanityCheck ()
const;
231 static void FlushFreeList()
233 allocator::FlushFreeList();
244 friend class dListNode;
247 template<
class T,
class allocator = dContainersAlloc<T> >
255 template<
class T,
class allocator = dContainersAlloc<T> >
261 template<
class T,
class allocator = dContainersAlloc<T> >
267 template<
class T,
class allocator = dContainersAlloc<T> >
270 return m_first !=
nullptr;
273 template<
class T,
class allocator = dContainersAlloc<T> >
279 template<
class T,
class allocator = dContainersAlloc<T> >
285 template<
class T,
class allocator = dContainersAlloc<T> >
288 dAssert (node->m_next ==
nullptr);
289 dAssert (node->m_prev ==
nullptr);
291 if (m_first ==
nullptr)
298 m_last->AddLast (node);
301 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
302 dAssert (SanityCheck ());
307 template<
class T,
class allocator = dContainersAlloc<T> >
311 if (m_first ==
nullptr)
313 m_first =
new dListNode(
nullptr,
nullptr);
318 m_last =
new dListNode(m_last,
nullptr);
320 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
321 dAssert (SanityCheck ());
326 template<
class T,
class allocator = dContainersAlloc<T> >
330 if (m_first ==
nullptr)
332 m_first =
new dListNode(element,
nullptr,
nullptr);
337 m_last =
new dListNode(element, m_last,
nullptr);
339 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
340 dAssert (SanityCheck ());
346 template<
class T,
class allocator = dContainersAlloc<T> >
349 dAssert (node->m_next ==
nullptr);
350 dAssert (node->m_prev ==
nullptr);
352 if (m_last ==
nullptr)
359 m_first->AddFirst(node);
362 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
363 dAssert (SanityCheck ());
368 template<
class T,
class allocator = dContainersAlloc<T> >
372 if (m_last ==
nullptr)
374 m_last =
new dListNode(
nullptr,
nullptr);
379 m_first =
new dListNode(
nullptr, m_first);
381 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
382 dAssert (SanityCheck ());
387 template<
class T,
class allocator = dContainersAlloc<T> >
391 if (m_last ==
nullptr)
393 m_last =
new dListNode(element,
nullptr,
nullptr);
398 m_first =
new dListNode(element,
nullptr, m_first);
400 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
401 dAssert (SanityCheck ());
406 template<
class T,
class allocator = dContainersAlloc<T> >
412 if (root->m_next != node)
416 m_first = node->m_next;
420 m_last = node->m_prev;
425 node->m_next = root->m_next;
428 root->m_next->m_prev = node;
432 if (node->m_next ==
nullptr)
438 dAssert (!m_last->m_next);
440 dAssert (!m_first->m_prev);
441 dAssert (SanityCheck ());
446 template<
class T,
class allocator = dContainersAlloc<T> >
452 if (root->m_prev != node)
456 m_last = node->m_prev;
458 if (node == m_first) {
459 m_first = node->m_next;
464 node->m_prev = root->m_prev;
467 root->m_prev->m_next = node;
471 if (node->m_prev ==
nullptr) {
476 dAssert (!m_first->m_prev);
478 dAssert (!m_last->m_next);
479 dAssert (SanityCheck ());
484 template<
class T,
class allocator = dContainersAlloc<T> >
489 if (m_last != m_first)
493 m_first = m_first->GetNext();
496 m_last->AddLast(node);
501 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
502 dAssert (SanityCheck ());
506 template<
class T,
class allocator = dContainersAlloc<T> >
511 if (m_last != m_first)
515 m_last = m_last->GetPrev();
518 m_first->AddFirst(node);
523 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
524 dAssert (SanityCheck ());
528 template<
class T,
class allocator = dContainersAlloc<T> >
532 for (node = m_first; node; node = node->GetNext())
534 if (element == node->m_info)
542 template<
class T,
class allocator = dContainersAlloc<T> >
545 dListNode*
const node = (dListNode *) &info;
546 dInt64 offset = ((
char*) &node->m_info) - ((
char *) node);
547 dListNode*
const retnode = (dListNode *) (((
char *) node) - offset);
549 dAssert (&retnode->GetInfo () == &info);
553 template<
class T,
class allocator = dContainersAlloc<T> >
556 dListNode *
const node = Find (element);
563 template<
class T,
class allocator = dContainersAlloc<T> >
569 dAssert (m_count >= 0);
573 m_first = m_first->GetNext();
577 m_last = m_last->GetPrev();
581 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
582 dAssert (SanityCheck ());
586 template<
class T,
class allocator = dContainersAlloc<T> >
589 m_count += list.m_count;
592 list.m_first->m_prev = m_last;
596 m_last->m_next = list.m_first;
598 m_last = list.m_last;
601 m_first = list.m_first;
605 list.m_last =
nullptr;
606 list.m_first =
nullptr;
607 #ifdef __ENABLE_DG_CONTAINERS_SANITY_CHECK
608 dAssert (SanityCheck ());
612 template<
class T,
class allocator = dContainersAlloc<T> >
619 template<
class T,
class allocator = dContainersAlloc<T> >
622 for (dListNode *node = m_first; node; node = m_first)
625 m_first = node->GetNext();
629 dAssert (m_count == 0);
634 template<
class T,
class allocator = dContainersAlloc<T> >
639 for (dListNode * node = m_first; node; node = node->GetNext())
642 if (node->GetPrev()) {
643 dAssert (node->GetPrev() != node->GetNext());
644 if (node->GetPrev()->GetNext() != node)
652 dAssert (node->GetPrev() != node->GetNext());
653 if (node->GetNext()->GetPrev() != node)
660 if (tCount != m_count)