diff options
author | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-01-06 23:24:29 +0000 |
---|---|---|
committer | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-01-06 23:24:29 +0000 |
commit | d9a72db466fe52b8c33d9d4d7df8158bcf8cc5da (patch) | |
tree | 4b31ed03aaf46615caa6f5aa1beaafb06c7175dd /ace | |
parent | e03c3c4067fa40d01e65216f66db71c9947fa6e7 (diff) | |
download | ATCD-d9a72db466fe52b8c33d9d4d7df8158bcf8cc5da.tar.gz |
Added STL-styled iterator functions.
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Containers.cpp | 69 | ||||
-rw-r--r-- | ace/Containers.h | 24 |
2 files changed, 86 insertions, 7 deletions
diff --git a/ace/Containers.cpp b/ace/Containers.cpp index 89971faa51d..0f356dffd5a 100644 --- a/ace/Containers.cpp +++ b/ace/Containers.cpp @@ -1584,6 +1584,21 @@ ACE_Unbounded_Set<T>::remove (const T &item) } } +template <class T> ACE_Unbounded_Set_Iterator<T> +ACE_Unbounded_Set<T>::begin (void) +{ + // ACE_TRACE ("ACE_Unbounded_Set<T>::begin"); + return ACE_Unbounded_Set_Iterator<T> (*this); +} + +template <class T> ACE_Unbounded_Set_Iterator<T> +ACE_Unbounded_Set<T>::end (void) +{ + // ACE_TRACE ("ACE_Unbounded_Set<T>::end"); + return ACE_Unbounded_Set_Iterator<T> (*this, 1); +} + + ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set_Iterator) template <class T> void @@ -1593,11 +1608,13 @@ ACE_Unbounded_Set_Iterator<T>::dump (void) const } template <class T> -ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set<T> &s) +ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set<T> &s, int end) : current_ (s.head_->next_), - set_ (s) + set_ (&s) { // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::ACE_Unbounded_Set_Iterator"); + if (end != 0) + this->current_ = s.head_; } template <class T> int @@ -1605,7 +1622,7 @@ ACE_Unbounded_Set_Iterator<T>::advance (void) { // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::advance"); this->current_ = this->current_->next_; - return this->current_ != this->set_.head_; + return this->current_ != this->set_->head_; } template <class T> int @@ -1613,14 +1630,14 @@ ACE_Unbounded_Set_Iterator<T>::done (void) const { ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::done"); - return this->current_ == this->set_.head_; + return this->current_ == this->set_->head_; } template <class T> int ACE_Unbounded_Set_Iterator<T>::next (T *&item) { // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::next"); - if (this->current_ == this->set_.head_) + if (this->current_ == this->set_->head_) return 0; else { @@ -1629,6 +1646,48 @@ ACE_Unbounded_Set_Iterator<T>::next (T *&item) } } +template <class T> ACE_Unbounded_Set_Iterator<T> +ACE_Unbounded_Set_Iterator<T>::operator++ (void) +{ + //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator++ ()"); + ACE_Unbounded_Set_Iterator<T> retv (*this); + + this->advance (); + return retv; +} + +template <class T> ACE_Unbounded_Set_Iterator<T>& +ACE_Unbounded_Set_Iterator<T>::operator++ (int) +{ + // ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator++ (int)"); + this->advance (); + return *this; +} + +template <class T> T& +ACE_Unbounded_Set_Iterator<T>::operator* (void) +{ + //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator*"); + T *retv; + + ACE_ASSERT (this->next (retv) != 0); + return *retv; +} + +template <class T> int +ACE_Unbounded_Set_Iterator<T>::operator== (const ACE_Unbounded_Set_Iterator<T> &rhs) const +{ + //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator=="); + return (this->set_ == rhs.set_ && this->current_ == rhs.current_); +} + +template <class T> int +ACE_Unbounded_Set_Iterator<T>::operator!= (const ACE_Unbounded_Set_Iterator<T> &rhs) const +{ + //ACE_TRACE ("ACE_Unbounded_Set_Iterator<T>::operator!="); + return (this->set_ != rhs.set_ || this->current_ != rhs.current_); +} + template <class T> void ACE_Unbounded_Stack_Iterator<T>::dump (void) const { diff --git a/ace/Containers.h b/ace/Containers.h index 022d6b6679f..9057bf6f53a 100644 --- a/ace/Containers.h +++ b/ace/Containers.h @@ -638,7 +638,7 @@ class ACE_Unbounded_Set_Iterator // Implement an iterator over an unbounded set. public: // = Initialization method. - ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set<T> &s); + ACE_Unbounded_Set_Iterator (ACE_Unbounded_Set<T> &s, int end = 0); // = Iteration methods. @@ -656,6 +656,21 @@ public: void dump (void) const; // Dump the state of an object. + // = STL styled iteration, compare, and reference functions. + + ACE_Unbounded_Set_Iterator<T> operator++ (void); + // Postfix advance. + + ACE_Unbounded_Set_Iterator<T>& operator++ (int); + // Prefix advance. + + T& operator* (void); + // Returns a reference to the interal element <this> is pointing to. + + int operator== (const ACE_Unbounded_Set_Iterator<T> &) const; + int operator!= (const ACE_Unbounded_Set_Iterator<T> &) const; + // Check if two iterators point to the same position + ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. @@ -663,7 +678,7 @@ private: ACE_Node<T> *current_; // Pointer to the current node in the iteration. - ACE_Unbounded_Set<T> &set_; + ACE_Unbounded_Set<T> *set_; // Pointer to the set we're iterating over. }; @@ -682,6 +697,7 @@ public: // Trait definition. typedef ACE_Unbounded_Set_Iterator<T> ITERATOR; + typedef ACE_Unbounded_Set_Iterator<T> iterator; // = Initialization and termination methods. ACE_Unbounded_Set (ACE_Allocator *alloc = 0); @@ -730,6 +746,10 @@ public: void reset (void); // Reset the <ACE_Unbounded_Set> to be empty. + // = STL-styled unidirectional iterator factory. + ACE_Unbounded_Set_Iterator<T> begin (void); + ACE_Unbounded_Set_Iterator<T> end (void); + ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. |