Intrusive_List.cpp

Go to the documentation of this file.
00001 // Intrusive_List.cpp,v 4.2 2005/10/28 16:14:52 ossama Exp
00002 
00003 #ifndef ACE_INTRUSIVE_LIST_CPP
00004 #define ACE_INTRUSIVE_LIST_CPP
00005 
00006 #include "ace/Intrusive_List.h"
00007 
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif /* ACE_LACKS_PRAGMA_ONCE */
00011 
00012 #if !defined (__ACE_INLINE__)
00013 #include "ace/Intrusive_List.inl"
00014 #endif /* __ACE_INLINE__ */
00015 
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 template <class T>
00019 ACE_Intrusive_List<T>::ACE_Intrusive_List (void)
00020   : head_ (0)
00021   , tail_ (0)
00022 {
00023 }
00024 
00025 template<class T>
00026 ACE_Intrusive_List<T>::~ACE_Intrusive_List (void)
00027 {
00028 }
00029 
00030 template<class T> void
00031 ACE_Intrusive_List<T>::push_back (T *node)
00032 {
00033   if (this->tail_ == 0)
00034     {
00035       this->tail_ = node;
00036       this->head_ = node;
00037       node->next (0);
00038       node->prev (0);
00039       return;
00040     }
00041 
00042   this->tail_->next (node);
00043   node->prev (this->tail_);
00044   node->next (0);
00045   this->tail_ = node;
00046 }
00047 
00048 template<class T> void
00049 ACE_Intrusive_List<T>::push_front (T *node)
00050 {
00051   if (this->head_ == 0)
00052     {
00053       this->tail_ = node;
00054       this->head_ = node;
00055       node->next (0);
00056       node->prev (0);
00057       return;
00058     }
00059 
00060   this->head_->prev (node);
00061   node->next (this->head_);
00062   node->prev (0);
00063   this->head_ = node;
00064 }
00065 
00066 template<class T> T *
00067 ACE_Intrusive_List<T>::pop_front (void)
00068 {
00069   T *node = this->head_;
00070   if (node == 0)
00071     return 0;
00072   this->remove_i (node);
00073   return node;
00074 }
00075 
00076 template<class T> T *
00077 ACE_Intrusive_List<T>::pop_back (void)
00078 {
00079   T *node = this->tail_;
00080   if (node == 0)
00081     return 0;
00082   this->remove_i (node);
00083   return node;
00084 }
00085 
00086 template<class T> void
00087 ACE_Intrusive_List<T>::remove (T *node)
00088 {
00089   for (T *i = this->head_; i != 0; i = i->next ())
00090     {
00091       if (node == i)
00092         {
00093           this->remove_i (node);
00094           return;
00095         }
00096     }
00097 }
00098 
00099 template<class T> void
00100 ACE_Intrusive_List<T>::remove_i (T *node)
00101 {
00102   if (node->prev () != 0)
00103     node->prev ()->next (node->next ());
00104   else
00105     this->head_ = node->next ();
00106 
00107   if (node->next () != 0)
00108     node->next ()->prev (node->prev ());
00109   else
00110     this->tail_ = node->prev ();
00111 
00112   node->next (0);
00113   node->prev (0);
00114 }
00115 
00116 #if 0
00117 template<class T> void
00118 ACE_Intrusive_List_Node<T>::check_invariants (void)
00119 {
00120   ACE_ASSERT ((this->next () == 0) || (this->next ()->prev () == this));
00121   ACE_ASSERT ((this->prev () == 0) || (this->prev ()->next () == this));
00122 }
00123 
00124 template<class T> void
00125 ACE_Intrusive_List<T>::check_invariants (void)
00126 {
00127   ACE_ASSERT ((this->tail_ == 0) || (this->tail_->next () == 0));
00128   ACE_ASSERT ((this->head_ == 0) || (this->head_->prev () == 0));
00129   ACE_ASSERT (!((this->head_ == 0) ^ (this->tail_ == 0)));
00130 
00131   int found_tail = 0;
00132   for (T *i = this->head_; i != 0; i = i->next ())
00133     {
00134       if (i == this->tail_)
00135         found_tail = 1;
00136       i->check_invariants ();
00137     }
00138   ACE_ASSERT (this->tail_ == 0 || found_tail == 1);
00139 
00140   int found_head = 0;
00141   for (T *j = this->tail_; j != 0; j = j->prev ())
00142     {
00143       if (j == this->head_)
00144         found_head = 1;
00145       j->check_invariants ();
00146     }
00147   ACE_ASSERT (this->head_ == 0 || found_head == 1);
00148 }
00149 #endif /* 0 */
00150 
00151 ACE_END_VERSIONED_NAMESPACE_DECL
00152 
00153 #endif /* ACE_INTRUSIVE_LIST_CPP */

Generated on Thu Nov 9 09:41:52 2006 for ACE by doxygen 1.3.6