diff options
author | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-07-31 16:19:40 +0000 |
---|---|---|
committer | coryan <coryan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-07-31 16:19:40 +0000 |
commit | 3eba0564d07a6db010e9ae89fee059c3ec018c22 (patch) | |
tree | e662d3538e0f5a9bcfe7858df2086ce5b4a818e4 | |
parent | 9e51ba66a9920a9d80696f4aeefb8c01ba32c609 (diff) | |
download | ATCD-3eba0564d07a6db010e9ae89fee059c3ec018c22.tar.gz |
ChangeLogTag:Tue Jul 31 09:17:49 2001 Carlos O'Ryan <coryan@uci.edu>
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 14 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 14 | ||||
-rw-r--r-- | ace/Intrusive_List.cpp | 52 | ||||
-rw-r--r-- | ace/Intrusive_List.h | 16 | ||||
-rw-r--r-- | ace/Intrusive_List.inl | 12 |
6 files changed, 115 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog index 9b6f180caf1..e3859783fe2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Tue Jul 31 09:17:49 2001 Carlos O'Ryan <coryan@uci.edu> + + * ace/Intrusive_List.h: + * ace/Intrusive_List.inl: + Add new methods to access the head and tail of the list. + + * ace/Intrusive_List.cpp: + Fixed the implementation of remove(), if the element to be + removed was the last on the list it wasn't removed at all. + Left some code to check invariants, have to find a way to keep + that code around with some optional compilation flags. + Thu Jul 26 16:50:54 2001 Carlos O'Ryan <coryan@uci.edu> * ace/Makefile: @@ -14,7 +26,7 @@ Thu Jul 26 16:50:54 2001 Carlos O'Ryan <coryan@uci.edu> * ace/Intrusive_List_Node.cpp: Helper class to add the requirements of ACE_Intrusive_List to any other class, simply do: - class Foo : public ACE_Intrusive_List_Node<Foo> + class Foo : public ACE_Intrusive_List_Node<Foo> Wed Jul 25 23:49:43 2001 Krishnakumar B <kitty@cs.wustl.edu> diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 9b6f180caf1..e3859783fe2 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,15 @@ +Tue Jul 31 09:17:49 2001 Carlos O'Ryan <coryan@uci.edu> + + * ace/Intrusive_List.h: + * ace/Intrusive_List.inl: + Add new methods to access the head and tail of the list. + + * ace/Intrusive_List.cpp: + Fixed the implementation of remove(), if the element to be + removed was the last on the list it wasn't removed at all. + Left some code to check invariants, have to find a way to keep + that code around with some optional compilation flags. + Thu Jul 26 16:50:54 2001 Carlos O'Ryan <coryan@uci.edu> * ace/Makefile: @@ -14,7 +26,7 @@ Thu Jul 26 16:50:54 2001 Carlos O'Ryan <coryan@uci.edu> * ace/Intrusive_List_Node.cpp: Helper class to add the requirements of ACE_Intrusive_List to any other class, simply do: - class Foo : public ACE_Intrusive_List_Node<Foo> + class Foo : public ACE_Intrusive_List_Node<Foo> Wed Jul 25 23:49:43 2001 Krishnakumar B <kitty@cs.wustl.edu> diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 9b6f180caf1..e3859783fe2 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,15 @@ +Tue Jul 31 09:17:49 2001 Carlos O'Ryan <coryan@uci.edu> + + * ace/Intrusive_List.h: + * ace/Intrusive_List.inl: + Add new methods to access the head and tail of the list. + + * ace/Intrusive_List.cpp: + Fixed the implementation of remove(), if the element to be + removed was the last on the list it wasn't removed at all. + Left some code to check invariants, have to find a way to keep + that code around with some optional compilation flags. + Thu Jul 26 16:50:54 2001 Carlos O'Ryan <coryan@uci.edu> * ace/Makefile: @@ -14,7 +26,7 @@ Thu Jul 26 16:50:54 2001 Carlos O'Ryan <coryan@uci.edu> * ace/Intrusive_List_Node.cpp: Helper class to add the requirements of ACE_Intrusive_List to any other class, simply do: - class Foo : public ACE_Intrusive_List_Node<Foo> + class Foo : public ACE_Intrusive_List_Node<Foo> Wed Jul 25 23:49:43 2001 Krishnakumar B <kitty@cs.wustl.edu> diff --git a/ace/Intrusive_List.cpp b/ace/Intrusive_List.cpp index bf208d01130..7a23921288b 100644 --- a/ace/Intrusive_List.cpp +++ b/ace/Intrusive_List.cpp @@ -69,7 +69,7 @@ ACE_Intrusive_List<T>::pop_front (void) T *node = this->head_; if (node == 0) return 0; - this->remove (node); + this->remove_i (node); return node; } @@ -79,13 +79,26 @@ ACE_Intrusive_List<T>::pop_back (void) T *node = this->tail_; if (node == 0) return 0; - this->remove (node); + this->remove_i (node); return node; } template<class T> void ACE_Intrusive_List<T>::remove (T *node) { + for (T *i = this->head_; i != 0; i = i->next ()) + { + if (node == i) + { + this->remove_i (node); + return; + } + } +} + +template<class T> void +ACE_Intrusive_List<T>::remove_i (T *node) +{ if (node->prev () != 0) node->prev ()->next (node->next ()); else @@ -100,4 +113,39 @@ ACE_Intrusive_List<T>::remove (T *node) node->prev (0); } +#if 0 +template<class T> void +ACE_Intrusive_List_Node<T>::check_invariants (void) +{ + ACE_ASSERT ((this->next () == 0) || (this->next ()->prev () == this)); + ACE_ASSERT ((this->prev () == 0) || (this->prev ()->next () == this)); +} + +template<class T> void +ACE_Intrusive_List<T>::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 */ diff --git a/ace/Intrusive_List.h b/ace/Intrusive_List.h index 3520eed2f2a..1340c654355 100644 --- a/ace/Intrusive_List.h +++ b/ace/Intrusive_List.h @@ -81,14 +81,26 @@ public: /// Remove the element at the end of the list T *pop_back (void); + /// Get the element at the head of the queue + T *head (void) const; + + /// Get the element at the tail of the queue + T *tail (void) const; + /// Remove a element from the list /** - * No attempts are performed to check if T* really belongs to the - * list. The effects of removing an invalid element are unspecified + * Verify that the element is still in the list before removing it. */ void remove (T *node); private: + /// Remove a element from the list + /** + * No attempts are performed to check if T* really belongs to the + * list. The effects of removing an invalid element are unspecified + */ + void remove_i (T *node); + /** @name Disallow copying * */ diff --git a/ace/Intrusive_List.inl b/ace/Intrusive_List.inl index 57fc91662d0..2c513b4584f 100644 --- a/ace/Intrusive_List.inl +++ b/ace/Intrusive_List.inl @@ -5,3 +5,15 @@ ACE_Intrusive_List<T>::empty (void) const { return this->head_ == 0; } + +template<class T> ACE_INLINE T * +ACE_Intrusive_List<T>::head (void) const +{ + return this->head_; +} + +template<class T> ACE_INLINE T * +ACE_Intrusive_List<T>::tail (void) const +{ + return this->tail_; +} |