36 DG_CLASS_ALLOCATOR(allocator)
44 m_prev->m_next =
this;
47 m_next->m_prev =
this;
57 m_prev->m_next =
this;
60 m_next->m_prev =
this;
70 m_prev->m_next = m_next;
74 m_next->m_prev = m_prev;
131 operator dgInt32()
const {
132 return m_ptr != NULL;
135 bool operator== (
const Iterator &target)
const {
136 return (m_ptr == target.m_ptr) && (m_list == target.m_list);
140 m_ptr = m_list->GetFirst();
144 m_ptr = m_list->GetLast();
152 NEWTON_ASSERT(m_ptr);
153 m_ptr = m_ptr->m_next();
156 void operator++ (
int) {
157 NEWTON_ASSERT(m_ptr);
158 m_ptr = m_ptr->GetNext();
162 NEWTON_ASSERT(m_ptr);
163 m_ptr = m_ptr->GetPrev();
166 void operator-- (
int) {
167 NEWTON_ASSERT(m_ptr);
168 m_ptr = m_ptr->GetPrev();
171 T &operator* ()
const {
172 return m_ptr->GetInfo();
188 DG_CLASS_ALLOCATOR(allocator)
197 operator dgInt32()
const;
198 dgInt32 GetCount()
const;
217 void Remove(
const T &element);
222 bool SanityCheck()
const;
256 m_allocator = allocator;
267 if ((m_count == 0) && (m_allocator == NULL)) {
268 m_allocator = allocator;
285 return m_first != NULL;
300 NEWTON_ASSERT(node->m_next == NULL);
301 NEWTON_ASSERT(node->m_prev == NULL);
303 if (m_first == NULL) {
307 m_last->AddLast(node);
310 #ifdef __ENABLE_SANITY_CHECK 311 NEWTON_ASSERT(SanityCheck());
319 if (m_first == NULL) {
320 m_first =
new (m_allocator)
dgListNode(NULL, NULL);
323 m_last =
new (m_allocator)
dgListNode(m_last, NULL);
325 #ifdef __ENABLE_SANITY_CHECK 326 NEWTON_ASSERT(SanityCheck());
334 if (m_first == NULL) {
335 m_first =
new (m_allocator)
dgListNode(element, NULL, NULL);
338 m_last =
new (m_allocator)
dgListNode(element, m_last, NULL);
340 #ifdef __ENABLE_SANITY_CHECK 341 NEWTON_ASSERT(SanityCheck());
349 NEWTON_ASSERT(node->m_next == NULL);
350 NEWTON_ASSERT(node->m_prev == NULL);
352 if (m_last == NULL) {
356 m_first->AddFirst(node);
359 #ifdef __ENABLE_SANITY_CHECK 360 NEWTON_ASSERT(SanityCheck());
369 if (m_last == NULL) {
370 m_last =
new (m_allocator)
dgListNode(NULL, NULL);
373 m_first =
new (m_allocator)
dgListNode(NULL, m_first);
375 #ifdef __ENABLE_SANITY_CHECK 376 NEWTON_ASSERT(SanityCheck());
385 if (m_last == NULL) {
386 m_last =
new (m_allocator)
dgListNode(element, NULL, NULL);
389 m_first =
new (m_allocator)
dgListNode(element, NULL, m_first);
391 #ifdef __ENABLE_SANITY_CHECK 392 NEWTON_ASSERT(SanityCheck());
400 NEWTON_ASSERT(node != root);
402 if (root->m_next != node) {
403 if (node == m_first) {
404 m_first = node->m_next;
406 if (node == m_last) {
407 m_last = node->m_prev;
412 node->m_next = root->m_next;
414 root->m_next->m_prev = node;
418 if (node->m_next == NULL) {
422 NEWTON_ASSERT(m_last);
423 NEWTON_ASSERT(!m_last->m_next);
424 NEWTON_ASSERT(m_first);
425 NEWTON_ASSERT(!m_first->m_prev);
426 NEWTON_ASSERT(SanityCheck());
434 NEWTON_ASSERT(node != root);
436 if (root->m_prev != node) {
437 if (node == m_last) {
438 m_last = node->m_prev;
440 if (node == m_first) {
441 m_first = node->m_next;
446 node->m_prev = root->m_prev;
448 root->m_prev->m_next = node;
452 if (node->m_prev == NULL) {
456 NEWTON_ASSERT(m_first);
457 NEWTON_ASSERT(!m_first->m_prev);
458 NEWTON_ASSERT(m_last);
459 NEWTON_ASSERT(!m_last->m_next);
460 NEWTON_ASSERT(SanityCheck());
467 if (node != m_last) {
468 if (m_last != m_first) {
469 if (node == m_first) {
470 m_first = m_first->GetNext();
473 m_last->AddLast(node);
478 #ifdef __ENABLE_SANITY_CHECK 479 NEWTON_ASSERT(SanityCheck());
485 if (node != m_first) {
486 if (m_last != m_first) {
487 if (node == m_last) {
488 m_last = m_last->GetPrev();
491 m_first->AddFirst(node);
496 #ifdef __ENABLE_SANITY_CHECK 497 NEWTON_ASSERT(SanityCheck());
505 for (node = m_first; node; node = node->GetNext()) {
506 if (element == node->m_info) {
519 dgInt64 offset = ((
char *) &node->m_info) - ((
char *) node);
522 NEWTON_ASSERT(&retnode->GetInfo() == &info);
540 NEWTON_ASSERT(m_count >= 0);
542 if (node == m_first) {
543 m_first = m_first->GetNext();
545 if (node == m_last) {
546 m_last = m_last->GetPrev();
551 #ifdef __ENABLE_SANITY_CHECK 552 NEWTON_ASSERT(SanityCheck());
558 m_count += list.m_count;
560 list.m_first->m_prev = m_last;
563 m_last->m_next = list.m_first;
565 m_last = list.m_last;
567 m_first = list.m_first;
573 #ifdef __ENABLE_SANITY_CHECK 574 NEWTON_ASSERT(SanityCheck());
588 for (
dgListNode *node = m_first; node; node = m_first) {
590 m_first = node->GetNext();
595 NEWTON_ASSERT(m_count == 0);
604 for (
dgListNode *node = m_first; node; node = node->GetNext()) {
606 if (node->GetPrev()) {
607 NEWTON_ASSERT(node->GetPrev() != node->GetNext());
608 if (node->GetPrev()->GetNext() != node) {
613 if (node->GetNext()) {
614 NEWTON_ASSERT(node->GetPrev() != node->GetNext());
615 if (node->GetNext()->GetPrev() != node) {
621 if (tCount != m_count) {
Definition: dgMemory.h:80