summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-01-08 23:21:14 +0000
committernw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-01-08 23:21:14 +0000
commit41b1505092eccf73212d778a5f76d674de6e579b (patch)
tree27d9867a6ff59f9106b19a355b8195bda78485f4
parent0f273b0b1bc84a00710c268c19ff69ee860ced00 (diff)
downloadATCD-41b1505092eccf73212d778a5f76d674de6e579b.tar.gz
Added STL-styled iterator functions.
-rw-r--r--ace/Hash_Map_Manager.cpp386
-rw-r--r--ace/Hash_Map_Manager.h129
2 files changed, 449 insertions, 66 deletions
diff --git a/ace/Hash_Map_Manager.cpp b/ace/Hash_Map_Manager.cpp
index ba1ad76feab..75a399b8707 100644
--- a/ace/Hash_Map_Manager.cpp
+++ b/ace/Hash_Map_Manager.cpp
@@ -531,6 +531,322 @@ ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind (const EXT_ID &ext_id,
return this->rebind_i (ext_id, int_id, old_ext_id, old_int_id, entry);
}
+// ------------------------------------------------------------
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::begin (void)
+{
+ return ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::end (void)
+{
+ return ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rbegin (void)
+{
+ return ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rend (void)
+{
+ return ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
+}
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Map_Iterator_Base)
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump_i (void) const
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump");
+
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, "index_ = %d ", this->index_));
+ ACE_DEBUG ((LM_DEBUG, "next_ = %x", this->next_));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Iterator_Base (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int head)
+ : map_man_ (&mm),
+ index_ (head != 0 ? -1 : mm.total_size_),
+ next_ (0)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Iterator_Base");
+ if (mm.table_ != 0)
+ this->next_ = &mm.table_[ (head != 0 ? 0 : mm.total_size_ - 1 ) ];
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *& entry)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next");
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
+
+ if (this->map_man_->table_ != 0
+ && this->index_ < ACE_static_cast (ssize_t, this->map_man_->total_size_)
+ && this->index_ >= 0
+ && this->next_ != &this->map_man_->table_[this->index_])
+ {
+ entry = this->next_;
+ return 1;
+ }
+ else
+ return 0;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done");
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
+
+ return this->map_man_->table_ == 0
+ || this->index_ >= this->map_man_->total_size_
+ || this->index_ <= -1;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i");
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
+
+ if (this->map_man_->table_ == 0)
+ return -1;
+
+ // Guard against error condition first.
+ if (this->index_ < 0)
+ {
+ this->index_++;
+ return this->forward_i ();
+ }
+ else if (this->index_ >= ACE_static_cast(ssize_t, this->map_man_->total_size_))
+ return 0;
+
+ this->next_ = this->next_->next_;
+ if (this->next_ == &this->map_man_->table_[this->index_])
+ {
+ while (++this->index_ < ACE_static_cast (ssize_t, this->map_man_->total_size_))
+ {
+ this->next_ = &this->map_man_->table_[this->index_];
+ if (this->next_->next_ != &this->map_man_->table_[this->index_])
+ {
+ this->next_ = this->map_man_->table_[this->index_].next_;
+ return 1;
+ }
+ }
+ return 0;
+ }
+ return 1;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i");
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
+
+ if (this->map_man_->table_ == 0)
+ return -1;
+
+ if (this->index_ >= ACE_static_cast (ssize_t, this->map_man_->total_size_))
+ {
+ this->index_--;
+ return this->reverse_i ();
+ }
+ else if (this->index_ < 0)
+ return 0;
+
+ this->next_ = this->next_->prev_;
+ if (this->next_ == &this->map_man_->table_[this->index_])
+ {
+ while (--this->index_ >= 0)
+ {
+ this->next_ = &this->map_man_->table_[this->index_];
+ if (this->next_->prev_ != &this->map_man_->table_[this->index_])
+ {
+ this->next_ = this->map_man_->table_[this->index_].prev_;
+ return 1;
+ }
+ }
+ return 0;
+ }
+
+ return 1;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Entry<EXT_ID, INT_ID>&
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator* (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator*");
+ ACE_Hash_Map_Entry<EXT_ID, INT_ID> *retv;
+
+ ACE_ASSERT (this->next (retv) != 0);
+ return *retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator== (const ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator==");
+ return this->map_man_ == rhs.map_man_
+ && this->index_ == rhs.index_
+ && this->next_ == rhs.next_;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!= (const ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!=");
+ return this->next_ != rhs.next_
+ || this->index_ != rhs.index_
+ || this->map_man_ != rhs.map_man_;
+}
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Map_Iterator)
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump");
+
+ this->dump_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int tail)
+ : ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm, (tail == 0 ? 1 : 0))
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Iterator");
+ if (tail == 0)
+ this->forward_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance");
+ return this->forward_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)");
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+
+ this->forward_i ();
+ return retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)");
+ this->forward_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)");
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+
+ this->reverse_i ();
+ return retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
+ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
+{
+ ACE_TRACE ("ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)");
+ this->reverse_i ();
+ return *this;
+}
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Map_Reverse_Iterator)
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
+{
+ ACE_TRACE ("ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump");
+
+ this->dump_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Reverse_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int head)
+ : ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm, head)
+{
+ ACE_TRACE ("ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Reverse_Iterator");
+ if (head == 0)
+ this->reverse_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance");
+ return this->reverse_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)");
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+
+ this->reverse_i ();
+ return retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
+{
+ ACE_TRACE ("ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)");
+ this->reverse_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
+{
+ ACE_TRACE ("ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)");
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+
+ this->forward_i ();
+ return retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
+ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
+{
+ ACE_TRACE ("ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)");
+ this->forward_i ();
+ return *this;
+}
+
+// ------------------------------------------------------------
+
+#if 0
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
@@ -546,9 +862,9 @@ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Iterator (ACE_Hash
index_ (0),
next_ (0)
{
- if (this->map_man_.table_ != 0)
+ if (this->map_man_->table_ != 0)
{
- this->next_ = &this->map_man_.table_[this->index_];
+ this->next_ = &this->map_man_->table_[this->index_];
this->advance ();
}
}
@@ -556,11 +872,11 @@ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Iterator (ACE_Hash
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry)
{
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_.lock_, -1);
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
- if (this->map_man_.table_ != 0
- && this->index_ < this->map_man_.total_size_
- && this->next_ != &this->map_man_.table_[this->index_])
+ if (this->map_man_->table_ != 0
+ && this->index_ < this->map_man_->total_size_
+ && this->next_ != &this->map_man_->table_[this->index_])
{
entry = this->next_;
return 1;
@@ -572,11 +888,11 @@ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Hash_Map_Entry<EXT_ID
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
{
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_.lock_, -1);
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
- if (this->map_man_.table_ != 0
- && this->index_ < this->map_man_.total_size_
- && this->next_ != &this->map_man_.table_[this->index_])
+ if (this->map_man_->table_ != 0
+ && this->index_ < this->map_man_->total_size_
+ && this->next_ != &this->map_man_->table_[this->index_])
return 0;
else
return 1;
@@ -585,26 +901,26 @@ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
{
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_.lock_, -1);
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
- if (this->map_man_.table_ == 0)
+ if (this->map_man_->table_ == 0)
return -1;
- if (this->next_->next_ != &this->map_man_.table_[this->index_])
+ if (this->next_->next_ != &this->map_man_->table_[this->index_])
this->next_ = this->next_->next_;
else
- while (++this->index_ < this->map_man_.total_size_)
+ while (++this->index_ < this->map_man_->total_size_)
{
- this->next_ = &this->map_man_.table_[this->index_];
- if (this->next_->next_ != &this->map_man_.table_[this->index_])
+ this->next_ = &this->map_man_->table_[this->index_];
+ if (this->next_->next_ != &this->map_man_->table_[this->index_])
{
- this->next_ = this->map_man_.table_[this->index_].next_;
+ this->next_ = this->map_man_->table_[this->index_].next_;
break;
}
}
- return this->index_ < this->map_man_.total_size_
- && this->next_ != &this->map_man_.table_[this->index_];
+ return this->index_ < this->map_man_->total_size_
+ && this->next_ != &this->map_man_->table_[this->index_];
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
@@ -622,9 +938,9 @@ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Reverse_It
index_ (mm.total_size_ - 1),
next_ (0)
{
- if (this->map_man_.table_ != 0)
+ if (this->map_man_->table_ != 0)
{
- this->next_ = &this->map_man_.table_[this->index_];
+ this->next_ = &this->map_man_->table_[this->index_];
this->advance ();
}
}
@@ -632,11 +948,11 @@ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Hash_Map_Reverse_It
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry)
{
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_.lock_, -1);
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
- if (this->map_man_.table_ != 0
+ if (this->map_man_->table_ != 0
&& this->index_ >= 0
- && this->next_ != &this->map_man_.table_[this->index_])
+ && this->next_ != &this->map_man_->table_[this->index_])
{
entry = this->next_;
return 1;
@@ -648,11 +964,11 @@ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Hash_Map_Entr
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
{
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_.lock_, -1);
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
- if (this->map_man_.table_ != 0
+ if (this->map_man_->table_ != 0
&& this->index_ >= 0
- && this->next_ != &this->map_man_.table_[this->index_])
+ && this->next_ != &this->map_man_->table_[this->index_])
return 0;
else
return 1;
@@ -661,26 +977,26 @@ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
{
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_.lock_, -1);
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
- if (this->map_man_.table_ == 0)
+ if (this->map_man_->table_ == 0)
return -1;
- if (this->next_->prev_ != &this->map_man_.table_[this->index_])
+ if (this->next_->prev_ != &this->map_man_->table_[this->index_])
this->next_ = this->next_->prev_;
else
while (--this->index_ >= 0)
{
- this->next_ = &this->map_man_.table_[this->index_];
- if (this->next_->prev_ != &this->map_man_.table_[this->index_])
+ this->next_ = &this->map_man_->table_[this->index_];
+ if (this->next_->prev_ != &this->map_man_->table_[this->index_])
{
- this->next_ = this->map_man_.table_[this->index_].prev_;
+ this->next_ = this->map_man_->table_[this->index_].prev_;
break;
}
}
return this->index_ >= 0
- && this->next_ != &this->map_man_.table_[this->index_];
+ && this->next_ != &this->map_man_->table_[this->index_];
}
-
+#endif /* 0 */
#endif /* ACE_HASH_MAP_MANAGER_C */
diff --git a/ace/Hash_Map_Manager.h b/ace/Hash_Map_Manager.h
index 44493eba795..4c9be246eb5 100644
--- a/ace/Hash_Map_Manager.h
+++ b/ace/Hash_Map_Manager.h
@@ -59,6 +59,10 @@ public:
// Forward decl.
template <class EXT_ID, class INT_ID, class ACE_LOCK>
+class ACE_Hash_Map_Iterator_Base;
+
+// Forward decl.
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
class ACE_Hash_Map_Iterator;
// Forward decl.
@@ -81,6 +85,7 @@ class ACE_Hash_Map_Manager
// allocate memory The user can make this a persistant class by
// providing an ACE_Allocator with a persistable memory pool
public:
+ friend class ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>;
friend class ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
friend class ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
@@ -89,6 +94,8 @@ public:
typedef ACE_Hash_Map_Entry<EXT_ID, INT_ID> ENTRY;
typedef ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> ITERATOR;
typedef ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> REVERSE_ITERATOR;
+ typedef ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> iterator;
+ typedef ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> reverse_iterator;
// = Initialization and termination methods.
@@ -196,6 +203,16 @@ public:
void dump (void) const;
// Dump the state of an object.
+ // = STL styled iterator factory functions.
+
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> begin (void);
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> end (void);
+ // Return forward iterator.
+
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> rbegin (void);
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> rend (void);
+ // Return reverse iterator.
+
protected:
// = The following methods do the actual work.
@@ -277,7 +294,7 @@ protected:
// Pointer to a memory allocator.
ACE_LOCK lock_;
- // Synchronization variable for the MT_SAFE <ACE_Map_Manager>.
+ // Synchronization variable for the MT_SAFE <ACE_Hash_Map_Manager>.
private:
int shared_find (const EXT_ID &ext_id,
@@ -297,17 +314,18 @@ private:
};
template <class EXT_ID, class INT_ID, class ACE_LOCK>
-class ACE_Hash_Map_Iterator
+class ACE_Hash_Map_Iterator_Base
{
// = TITLE
// Iterator for the ACE_Hash_Map_Manager.
- //
- // = DESCRIPTION
public:
// = Initialization method.
- ACE_Hash_Map_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm);
+ ACE_Hash_Map_Iterator_Base (ACE_Hash_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
+ int head);
+ // Contructor. If head != 0, the iterator constructed is positioned
+ // at the head of the map, it is positioned at the end otherwise.
- // = Iteration methods.
+ // = ITERATION methods.
int next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&next_entry);
// Pass back the next <entry> that hasn't been seen in the Set.
@@ -316,21 +334,32 @@ public:
int done (void) const;
// Returns 1 when all items have been seen, else 0.
- int advance (void);
- // Move forward by one element in the set. Returns 0 when all the
- // items in the set have been seen, else 1.
+ ACE_Hash_Map_Entry<EXT_ID, INT_ID>& operator* (void);
+ // Returns a reference to the interal element <this> is pointing to.
- void dump (void) const;
- // Dump the state of an object.
+ int operator== (const ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
+ int operator!= (const ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
+ // Check if two iterators point to the same position
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
-private:
- ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &map_man_;
+protected:
+ int forward_i (void);
+ // Move forward by one element in the set. Returns 0 when there's
+ // no more item in the set after the current items, else 1.
+
+ int reverse_i (void);
+ // Move backware by one element in the set. Returns 0 when there's
+ // no more item in the set before the current item, else 1.
+
+ void dump_i (void) const;
+ // Dump the state of an object.
+
+ ACE_Hash_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> *map_man_;
// Map we are iterating over.
- size_t index_;
+ ssize_t index_;
// Keeps track of how far we've advanced in the table.
ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
@@ -339,7 +368,8 @@ private:
};
template <class EXT_ID, class INT_ID, class ACE_LOCK>
-class ACE_Hash_Map_Reverse_Iterator
+class ACE_Hash_Map_Iterator
+ : public ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>
{
// = TITLE
// Iterator for the ACE_Hash_Map_Manager.
@@ -347,17 +377,11 @@ class ACE_Hash_Map_Reverse_Iterator
// = DESCRIPTION
public:
// = Initialization method.
- ACE_Hash_Map_Reverse_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm);
+ ACE_Hash_Map_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
+ int tail = 0);
// = Iteration methods.
- int next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&next_entry);
- // Pass back the next <entry> that hasn't been seen in the Set.
- // Returns 0 when all items have been seen, else 1.
-
- int done (void) const;
- // Returns 1 when all items have been seen, else 0.
-
int advance (void);
// Move forward by one element in the set. Returns 0 when all the
// items in the set have been seen, else 1.
@@ -365,19 +389,62 @@ public:
void dump (void) const;
// Dump the state of an object.
+ // = STL styled iteration, compare, and reference functions.
+
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator++ (void);
+ // Postfix advance.
+
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>& operator++ (int);
+ // Prefix advance.
+
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator-- (void);
+ // Postfix advance.
+
+ ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>& operator-- (int);
+ // Prefix advance.
+
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
+};
-private:
- ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &map_man_;
- // Map we are iterating over.
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+class ACE_Hash_Map_Reverse_Iterator
+ : public ACE_Hash_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>
+{
+ // = TITLE
+ // Iterator for the ACE_Hash_Map_Manager.
+ //
+ // = DESCRIPTION
+public:
+ // = Initialization method.
+ ACE_Hash_Map_Reverse_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
+ int head = 0);
- ssize_t index_;
- // Keeps track of how far we've advanced in the table.
+ // = Iteration methods.
- ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
- // Keeps track of how far we've advanced in a linked list in each
- // table slot.
+ int advance (void);
+ // Move forward by one element in the set. Returns 0 when all the
+ // items in the set have been seen, else 1.
+
+ void dump (void) const;
+ // Dump the state of an object.
+
+ // = STL styled iteration, compare, and reference functions.
+
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator++ (void);
+ // Postfix advance.
+
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>& operator++ (int);
+ // Prefix advance.
+
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator-- (void);
+ // Postfix advance.
+
+ ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>& operator-- (int);
+ // Prefix advance.
+
+ ACE_ALLOC_HOOK_DECLARE;
+ // Declare the dynamic allocation hooks.
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)