summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordoccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-08-21 08:44:18 +0000
committerdoccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-08-21 08:44:18 +0000
commitff079741cddc3c38d22a3c02eee5fc9de9ab445e (patch)
treefc0409ab83c208df6ce825b11ae1f75c4cf170a9
parent5d9f467373e62c6f49e69995157880d0b96f767b (diff)
downloadATCD-ff079741cddc3c38d22a3c02eee5fc9de9ab445e.tar.gz
ChangeLogTag: Tue Aug 21 10:36:08 2001 Johnny Willemsen <jwillemsen@remedy.nl>
-rw-r--r--ChangeLog8
-rw-r--r--ChangeLogs/ChangeLog-02a8
-rw-r--r--ChangeLogs/ChangeLog-03a8
-rw-r--r--ace/Map_Manager.cpp34
-rw-r--r--ace/Map_Manager.h118
-rw-r--r--ace/Map_Manager.i185
-rw-r--r--ace/Map_T.h2
-rw-r--r--ace/Map_T.i2
8 files changed, 363 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 8c66a49afbb..2d4df727f07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue Aug 21 10:40:12 2001 Johnny Willemsen <jwillemsen@remedy.nl>
+
+ * ace/Map.i: Made the return value of ACE_Incremental_Key_Generator
+ getCurrentValue() const
+
+ * ace/Map_Manager.*: Added a const iterator for the
+ ACE_Map_Manager
+
Mon Aug 20 18:20:51 2001 Steve Huston <shuston@riverace.com>
* ace/Process.cpp (pass_handle): Only try to compile the
diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a
index 8c66a49afbb..2d4df727f07 100644
--- a/ChangeLogs/ChangeLog-02a
+++ b/ChangeLogs/ChangeLog-02a
@@ -1,3 +1,11 @@
+Tue Aug 21 10:40:12 2001 Johnny Willemsen <jwillemsen@remedy.nl>
+
+ * ace/Map.i: Made the return value of ACE_Incremental_Key_Generator
+ getCurrentValue() const
+
+ * ace/Map_Manager.*: Added a const iterator for the
+ ACE_Map_Manager
+
Mon Aug 20 18:20:51 2001 Steve Huston <shuston@riverace.com>
* ace/Process.cpp (pass_handle): Only try to compile the
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index 8c66a49afbb..2d4df727f07 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,3 +1,11 @@
+Tue Aug 21 10:40:12 2001 Johnny Willemsen <jwillemsen@remedy.nl>
+
+ * ace/Map.i: Made the return value of ACE_Incremental_Key_Generator
+ getCurrentValue() const
+
+ * ace/Map_Manager.*: Added a const iterator for the
+ ACE_Map_Manager
+
Mon Aug 20 18:20:51 2001 Steve Huston <shuston@riverace.com>
* ace/Process.cpp (pass_handle): Only try to compile the
diff --git a/ace/Map_Manager.cpp b/ace/Map_Manager.cpp
index 95a55eaf9c5..79c7acfc39b 100644
--- a/ace/Map_Manager.cpp
+++ b/ace/Map_Manager.cpp
@@ -22,8 +22,12 @@ ACE_ALLOC_HOOK_DEFINE(ACE_Map_Entry)
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Manager)
+ACE_ALLOC_HOOK_DEFINE(ACE_Map_Const_Iterator_Base)
+
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator_Base)
+ACE_ALLOC_HOOK_DEFINE(ACE_Map_Const_Iterator)
+
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator)
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Reverse_Iterator)
@@ -627,6 +631,14 @@ ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump_i (void) const
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump_i (void) const
+{
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("next_ = %d"), this->next_));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
+}
+
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Entry<EXT_ID, INT_ID>&
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator* (void) const
@@ -643,6 +655,22 @@ ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator* (void) const
return *retv;
}
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+ACE_Map_Entry<EXT_ID, INT_ID>&
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator* (void) const
+{
+ // @@ This function should be inlined. We moved it here to avoid a
+ // compiler bug in SunCC 4.2. Once we know the correct patch to fix
+ // the compiler problem, it should be moved back to .i file again.
+ ACE_Map_Entry<EXT_ID, INT_ID> *retv = 0;
+
+ int result = this->next (retv);
+ ACE_ASSERT (result != 0);
+ ACE_UNUSED_ARG (result);
+
+ return *retv;
+}
+
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
@@ -650,6 +678,12 @@ ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
+{
+ this->dump_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
this->dump_i ();
diff --git a/ace/Map_Manager.h b/ace/Map_Manager.h
index fc8814cb72c..b8fec073098 100644
--- a/ace/Map_Manager.h
+++ b/ace/Map_Manager.h
@@ -86,10 +86,18 @@ class ACE_Map_Iterator_Base;
// Forward decl.
template <class EXT_ID, class INT_ID, class ACE_LOCK>
+class ACE_Map_Const_Iterator_Base;
+
+// Forward decl.
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
class ACE_Map_Iterator;
// Forward decl.
template <class EXT_ID, class INT_ID, class ACE_LOCK>
+class ACE_Map_Const_Iterator;
+
+// Forward decl.
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
class ACE_Map_Reverse_Iterator;
/**
@@ -113,7 +121,9 @@ class ACE_Map_Manager
{
public:
friend class ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>;
+ friend class ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>;
friend class ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
+ friend class ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
friend class ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>;
// = Traits.
@@ -121,9 +131,11 @@ public:
typedef INT_ID VALUE;
typedef ACE_Map_Entry<EXT_ID, INT_ID> ENTRY;
typedef ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> ITERATOR;
+ typedef ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> CONST_ITERATOR;
typedef ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> REVERSE_ITERATOR;
typedef ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> iterator;
+ typedef ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> const_iterator;
typedef ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> reverse_iterator;
// = Initialization and termination methods.
@@ -475,6 +487,65 @@ protected:
};
/**
+ * @class ACE_Map_Const_Iterator_Base
+ *
+ * @brief Const iterator for the <ACE_Map_Manager>.
+ *
+ * This class factors out common code from its templatized
+ * subclasses.
+ */
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+class ACE_Map_Const_Iterator_Base
+{
+public:
+ // = Initialization method.
+ /// Contructor. If head != 0, the iterator constructed is positioned
+ /// at the head of the map, it is positioned at the end otherwise.
+ ACE_Map_Const_Iterator_Base (const ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm);
+
+ // = Iteration methods.
+
+ /// Pass back the next <entry> that hasn't been seen in the Set.
+ /// Returns 0 when all items have been seen, else 1.
+ int next (ACE_Map_Entry<EXT_ID, INT_ID> *&next_entry) const;
+
+ /// Returns 1 when all items have been seen, else 0.
+ int done (void) const;
+
+ /// Returns a reference to the interal element <this> is pointing to.
+ ACE_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
+
+ /// Returns reference the Map_Manager that is being iterated
+ /// over.
+ const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>& map (void) const;
+
+ /// Check if two iterators point to the same position
+ int operator== (const ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
+ int operator!= (const ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &) const;
+
+ /// Declare the dynamic allocation hooks.
+ ACE_ALLOC_HOOK_DECLARE;
+
+protected:
+ /// 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 forward_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.
+ int reverse_i (void);
+
+ /// Dump the state of an object.
+ void dump_i (void) const;
+
+ /// Map we are iterating over.
+ const ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> *map_man_;
+
+ /// Keeps track of how far we've advanced...
+ ACE_UINT32 next_;
+};
+
+/**
* @class ACE_Map_Iterator
*
* @brief Forward iterator for the <ACE_Map_Manager>.
@@ -522,6 +593,53 @@ public:
};
/**
+ * @class ACE_Map_Const_Iterator
+ *
+ * @brief Forward const iterator for the <ACE_Map_Manager>.
+ *
+ * This class does not perform any internal locking of the
+ * <ACE_Map_Manager> it is iterating upon since locking is
+ * inherently inefficient and/or error-prone within an STL-style
+ * iterator. If you require locking, you can explicitly use an
+ * <ACE_Guard> or <ACE_Read_Guard> on the <ACE_Map_Manager>'s
+ * internal lock, which is accessible via its <mutex> method.
+ */
+template <class EXT_ID, class INT_ID, class ACE_LOCK>
+class ACE_Map_Const_Iterator : public ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>
+{
+public:
+ // = Initialization method.
+ ACE_Map_Const_Iterator (const ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
+ int pass_end = 0);
+
+ // = Iteration methods.
+
+ /// Move forward by one element in the set. Returns 0 when all the
+ /// items in the set have been seen, else 1.
+ int advance (void);
+
+ /// Dump the state of an object.
+ void dump (void) const;
+
+ // = STL styled iteration, compare, and reference functions.
+
+ /// Prefix advance.
+ ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator++ (void);
+
+ /// Postfix advance.
+ ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator++ (int);
+
+ /// Prefix reverse.
+ ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &operator-- (void);
+
+ /// Postfix reverse.
+ ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> operator-- (int);
+
+ /// Declare the dynamic allocation hooks.
+ ACE_ALLOC_HOOK_DECLARE;
+};
+
+/**
* @class ACE_Map_Reverse_Iterator
*
* @brief Reverse Iterator for the <ACE_Map_Manager>.
diff --git a/ace/Map_Manager.i b/ace/Map_Manager.i
index 9b2d9517342..0efe209c8eb 100644
--- a/ace/Map_Manager.i
+++ b/ace/Map_Manager.i
@@ -372,6 +372,113 @@ ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!= (const ACE_Map_Itera
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Const_Iterator_Base (const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm)
+ : map_man_ (&mm),
+ next_ (this->map_man_->occupied_list_id ())
+{
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Map_Entry<EXT_ID, INT_ID> *&mm) const
+{
+ if (this->next_ != this->map_man_->occupied_list_id ())
+ {
+ mm = &this->map_man_->search_structure_[this->next_];
+ return 1;
+ }
+ else
+ return 0;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
+{
+ return this->next_ == this->map_man_->occupied_list_id ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i (void)
+{
+
+#if defined (ACE_HAS_LAZY_MAP_MANAGER)
+
+ while (1)
+ {
+ // Go to the next item in the list.
+ this->next_ = this->map_man_->search_structure_[this->next_].next ();
+
+ // Stop if we reach the end.
+ if (this->done ())
+ break;
+
+ // Break if we find a non-free slot.
+ if (!this->map_man_->search_structure_[this->next_].free_)
+ {
+ break;
+ }
+ }
+
+#else
+
+ this->next_ = this->map_man_->search_structure_[this->next_].next ();
+
+#endif /* ACE_HAS_LAZY_MAP_MANAGER */
+
+ return this->next_ != this->map_man_->occupied_list_id ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i (void)
+{
+
+#if defined (ACE_HAS_LAZY_MAP_MANAGER)
+
+ while (1)
+ {
+ // Go to the prev item in the list.
+ this->next_ = this->map_man_->search_structure_[this->next_].prev ();
+
+ // Stop if we reach the end.
+ if (this->done ())
+ break;
+
+ // Break if we find a non-free slot.
+ if (!this->map_man_->search_structure_[this->next_].free_)
+ {
+ break;
+ }
+ }
+
+#else
+
+ this->next_ = this->map_man_->search_structure_[this->next_].prev ();
+
+#endif /* ACE_HAS_LAZY_MAP_MANAGER */
+
+ return this->next_ != this->map_man_->occupied_list_id ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::map (void) const
+{
+ return *this->map_man_;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator== (const ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+{
+ return (this->map_man_ == rhs.map_man_ &&
+ this->next_ == rhs.next_);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!= (const ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+{
+ return !this->operator== (rhs);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
int pass_end)
: ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm)
@@ -450,6 +557,84 @@ ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Const_Iterator (const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
+ int pass_end)
+ : ACE_Map_Const_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm)
+{
+ if (!pass_end)
+ {
+
+#if defined (ACE_HAS_LAZY_MAP_MANAGER)
+
+ // Start here.
+ this->next_ = this->map_man_->occupied_list_.next ();
+
+ while (1)
+ {
+ // Stop if we reach the end.
+ if (this->done ())
+ break;
+
+ // Break if we find a non-free slot.
+ if (!this->map_man_->search_structure_[this->next_].free_)
+ {
+ break;
+ }
+
+ // Go to the next item in the list.
+ this->next_ = this->map_man_->search_structure_[this->next_].next ();
+ }
+
+#else
+
+ this->next_ = this->map_man_->occupied_list_.next ();
+
+#endif /* ACE_HAS_LAZY_MAP_MANAGER */
+
+ }
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
+{
+ return this->forward_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
+{
+ this->forward_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
+{
+ ACE_Map_Const_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_INLINE
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
+{
+ this->reverse_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
+{
+ ACE_Map_Const_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_INLINE
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Reverse_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
int pass_end)
: ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm)
diff --git a/ace/Map_T.h b/ace/Map_T.h
index 396d2ae0e6e..a1790439015 100644
--- a/ace/Map_T.h
+++ b/ace/Map_T.h
@@ -64,7 +64,7 @@ public:
int operator () (T &t);
/// Returns the current value.
- T& current_value (void) const;
+ const T& current_value (void) const;
protected:
diff --git a/ace/Map_T.i b/ace/Map_T.i
index 62a028b55dd..602fa5220ab 100644
--- a/ace/Map_T.i
+++ b/ace/Map_T.i
@@ -19,7 +19,7 @@ ACE_Incremental_Key_Generator<T>::operator() (T &t)
return 0;
}
-template <class T> ACE_INLINE T &
+template <class T> ACE_INLINE const T &
ACE_Incremental_Key_Generator<T>::current_value (void) const
{
return this->t_;