Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Unbounded_Queue.h
blob6d20557c0b5aa5619e28529009ed9aff0c068d2b
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Unbounded_Queue.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_UNBOUNDED_QUEUE_H
12 #define ACE_UNBOUNDED_QUEUE_H
13 #include /**/ "ace/pre.h"
15 #include "ace/Node.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ace/os_include/os_stddef.h"
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
25 class ACE_Allocator;
27 template <class T>
28 class ACE_Unbounded_Queue;
30 /**
31 * @class ACE_Unbounded_Queue_Iterator
33 * @brief Implement an iterator over an unbounded queue.
35 template <class T>
36 class ACE_Unbounded_Queue_Iterator
38 public:
39 ACE_Unbounded_Queue_Iterator (ACE_Unbounded_Queue<T> &q, int end = 0);
41 // = Iteration methods.
43 /// Pass back the @a next_item that hasn't been seen in the queue.
44 /// Returns 0 when all items have been seen, else 1.
45 int next (T *&next_item);
47 /// Move forward by one element in the set. Returns 0 when all the
48 /// items in the queue have been seen, else 1.
49 int advance ();
51 /// Move to the first element in the queue. Returns 0 if the
52 /// queue is empty, else 1.
53 int first ();
55 /// Returns 1 when all items have been seen, else 0.
56 int done () const;
58 /// Dump the state of an object.
59 void dump () const;
61 /// Declare the dynamic allocation hooks.
62 ACE_ALLOC_HOOK_DECLARE;
64 private:
65 /// Pointer to the current node in the iteration.
66 ACE_Node<T> *current_;
68 /// Pointer to the queue we're iterating over.
69 ACE_Unbounded_Queue<T> &queue_;
72 /**
73 * @class ACE_Unbounded_Queue_Const_Iterator
75 * @brief Implement an iterator over an const unbounded queue.
77 template <class T>
78 class ACE_Unbounded_Queue_Const_Iterator
80 public:
81 ACE_Unbounded_Queue_Const_Iterator (const ACE_Unbounded_Queue<T> &q, int end = 0);
83 // = Iteration methods.
85 /// Pass back the @a next_item that hasn't been seen in the queue.
86 /// Returns 0 when all items have been seen, else 1.
87 int next (T *&next_item);
89 /// Move forward by one element in the set. Returns 0 when all the
90 /// items in the queue have been seen, else 1.
91 int advance ();
93 /// Move to the first element in the queue. Returns 0 if the
94 /// queue is empty, else 1.
95 int first ();
97 /// Returns 1 when all items have been seen, else 0.
98 int done () const;
100 /// Dump the state of an object.
101 void dump () const;
103 /// Declare the dynamic allocation hooks.
104 ACE_ALLOC_HOOK_DECLARE;
106 private:
107 /// Pointer to the current node in the iteration.
108 ACE_Node<T> *current_;
110 /// Pointer to the queue we're iterating over.
111 const ACE_Unbounded_Queue<T> &queue_;
115 * @class ACE_Unbounded_Queue
117 * @brief A Queue of "infinite" length.
119 * This implementation of an unbounded queue uses a circular
120 * linked list with a dummy node.
122 * <b> Requirements and Performance Characteristics</b>
123 * - Internal Structure
124 * Circular linked list
125 * - Duplicates allowed?
126 * Yes
127 * - Random access allowed?
128 * No
129 * - Search speed
130 * N/A
131 * - Insert/replace speed
132 * N/A
133 * - Iterator still valid after change to container?
134 * Yes
135 * - Frees memory for removed elements?
136 * Yes
137 * - Items inserted by
138 * Value
139 * - Requirements for contained type
140 * -# Default constructor
141 * -# Copy constructor
142 * -# operator=
144 template <class T>
145 class ACE_Unbounded_Queue
147 public:
148 friend class ACE_Unbounded_Queue_Iterator<T>;
149 friend class ACE_Unbounded_Queue_Const_Iterator<T>;
151 // Trait definition.
152 typedef ACE_Unbounded_Queue_Iterator<T> ITERATOR;
153 typedef ACE_Unbounded_Queue_Const_Iterator<T> CONST_ITERATOR;
155 /// Construction. Use user specified allocation strategy
156 /// if specified.
158 * Initialize an empty queue using the strategy provided.
160 ACE_Unbounded_Queue (ACE_Allocator *alloc = nullptr);
162 /// Copy constructor.
164 * Initialize the queue to be a copy of the provided queue.
166 ACE_Unbounded_Queue (const ACE_Unbounded_Queue<T> &);
168 /// Assignment operator.
170 * Perform a deep copy of rhs.
172 void operator= (const ACE_Unbounded_Queue<T> &);
174 /// Destructor.
176 * Clean up the memory for the queue.
178 ~ACE_Unbounded_Queue ();
180 // = Check boundary conditions.
182 /// Returns true if the container is empty, otherwise returns false.
184 * Constant time check to see if the queue is empty.
186 bool is_empty () const;
188 /// Returns 0.
190 * The queue cannot be full, so it always returns 0.
192 bool is_full () const;
194 // = Classic queue operations.
196 /// Adds @a new_item to the tail of the queue. Returns 0 on success,
197 /// -1 on failure.
199 * Insert an item at the end of the queue.
201 int enqueue_tail (const T &new_item);
203 /// Adds @a new_item to the head of the queue. Returns 0 on success,
204 /// -1 on failure.
206 * Insert an item at the head of the queue.
208 int enqueue_head (const T &new_item);
210 /// Removes and returns the first @a item on the queue. Returns 0 on
211 /// success, -1 if the queue was empty.
213 * Remove an item from the head of the queue.
215 int dequeue_head (T &item);
217 // = Additional utility methods.
219 /// Reset the ACE_Unbounded_Queue to be empty and release all its
220 /// dynamically allocated resources.
222 * Delete the queue nodes.
224 void reset ();
226 /// Get the @a slot th element in the set. Returns -1 if the element
227 /// isn't in the range {0..#cur_size_ - 1}, else 0.
229 * Find the item in the queue between 0 and the provided index of the
230 * queue.
232 int get (T *&item, size_t slot = 0) const;
234 /// Set the @a slot th element of the queue to @a item.
236 * Set the @a slot th element in the set. Will pad out the set with
237 * empty nodes if @a slot is beyond the range {0..#cur_size_ - 1}.
238 * Returns -1 on failure, 0 if @a slot isn't initially in range, and
239 * 0 otherwise.
241 int set (const T &item, size_t slot);
243 /// The number of items in the queue.
245 * Return the size of the queue.
247 size_t size () const;
249 /// Dump the state of an object.
250 void dump () const;
252 // = STL-styled unidirectional iterator factory.
253 ACE_Unbounded_Queue_Iterator<T> begin ();
254 ACE_Unbounded_Queue_Iterator<T> end ();
256 /// Declare the dynamic allocation hooks.
257 ACE_ALLOC_HOOK_DECLARE;
259 protected:
260 /// Delete all the nodes in the queue.
261 void delete_nodes ();
263 /// Copy nodes into this queue.
264 void copy_nodes (const ACE_Unbounded_Queue<T> &);
266 /// Pointer to the dummy node in the circular linked Queue.
267 ACE_Node<T> *head_;
269 /// Current size of the queue.
270 size_t cur_size_;
272 /// Allocation Strategy of the queue.
273 ACE_Allocator *allocator_;
276 ACE_END_VERSIONED_NAMESPACE_DECL
278 #if defined (__ACE_INLINE__)
279 #include "ace/Unbounded_Queue.inl"
280 #endif /* __ACE_INLINE__ */
282 #include "ace/Unbounded_Queue.cpp"
284 #include /**/ "ace/post.h"
285 #endif /* ACE_UNBOUNDED_QUEUE_H */