// $Id$ #ifndef ACE_INTRUSIVE_LIST_C #define ACE_INTRUSIVE_LIST_C #include "ace/Intrusive_List.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ #if !defined (__ACE_INLINE__) #include "ace/Intrusive_List.inl" #endif /* __ACE_INLINE__ */ ACE_RCSID(ace, Intrusive_List, "$Id$") template ACE_Intrusive_List::ACE_Intrusive_List (void) : head_ (0) , tail_ (0) { } template ACE_Intrusive_List::~ACE_Intrusive_List (void) { } template void ACE_Intrusive_List::push_back (T *node) { if (this->tail_ == 0) { this->tail_ = node; this->head_ = node; node->next (0); node->prev (0); return; } this->tail_->next (node); node->prev (this->tail_); node->next (0); this->tail_ = node; } template void ACE_Intrusive_List::push_front (T *node) { if (this->head_ == 0) { this->tail_ = node; this->head_ = node; node->next (0); node->prev (0); return; } this->head_->prev (node); node->next (this->head_); node->prev (0); this->head_ = node; } template T * ACE_Intrusive_List::pop_front (void) { T *node = this->head_; if (node == 0) return 0; this->remove_i (node); return node; } template T * ACE_Intrusive_List::pop_back (void) { T *node = this->tail_; if (node == 0) return 0; this->remove_i (node); return node; } template void ACE_Intrusive_List::remove (T *node) { for (T *i = this->head_; i != 0; i = i->next ()) { if (node == i) { this->remove_i (node); return; } } } template void ACE_Intrusive_List::remove_i (T *node) { if (node->prev () != 0) node->prev ()->next (node->next ()); else this->head_ = node->next (); if (node->next () != 0) node->next ()->prev (node->prev ()); else this->tail_ = node->prev (); node->next (0); node->prev (0); } #if 0 template void ACE_Intrusive_List_Node::check_invariants (void) { ACE_ASSERT ((this->next () == 0) || (this->next ()->prev () == this)); ACE_ASSERT ((this->prev () == 0) || (this->prev ()->next () == this)); } template void ACE_Intrusive_List::check_invariants (void) { ACE_ASSERT ((this->tail_ == 0) || (this->tail_->next () == 0)); ACE_ASSERT ((this->head_ == 0) || (this->head_->prev () == 0)); ACE_ASSERT (!((this->head_ == 0) ^ (this->tail_ == 0))); int found_tail = 0; for (T *i = this->head_; i != 0; i = i->next ()) { if (i == this->tail_) found_tail = 1; i->check_invariants (); } ACE_ASSERT (this->tail_ == 0 || found_tail == 1); int found_head = 0; for (T *j = this->tail_; j != 0; j = j->prev ()) { if (j == this->head_) found_head = 1; j->check_invariants (); } ACE_ASSERT (this->head_ == 0 || found_head == 1); } #endif /* 0 */ #endif /* ACE_INTRUSIVE_LIST_C */