Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Unbounded_Queue.h
blobb6e1c4eea7650324dd945b2768fe45895f37af6f
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Unbounded_Queue.h
7 * $Id: Unbounded_Queue.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
11 //=============================================================================
13 #ifndef ACE_UNBOUNDED_QUEUE_H
14 #define ACE_UNBOUNDED_QUEUE_H
15 #include /**/ "ace/pre.h"
17 #include "ace/Node.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/os_include/os_stddef.h"
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
27 class ACE_Allocator;
29 template <class T>
30 class ACE_Unbounded_Queue;
32 /**
33 * @class ACE_Unbounded_Queue_Iterator
35 * @brief Implement an iterator over an unbounded queue.
37 template <class T>
38 class ACE_Unbounded_Queue_Iterator
40 public:
41 // = Initialization method.
42 ACE_Unbounded_Queue_Iterator (ACE_Unbounded_Queue<T> &q, int end = 0);
44 // = Iteration methods.
46 /// Pass back the @a next_item that hasn't been seen in the queue.
47 /// Returns 0 when all items have been seen, else 1.
48 int next (T *&next_item);
50 /// Move forward by one element in the set. Returns 0 when all the
51 /// items in the queue have been seen, else 1.
52 int advance (void);
54 /// Move to the first element in the queue. Returns 0 if the
55 /// queue is empty, else 1.
56 int first (void);
58 /// Returns 1 when all items have been seen, else 0.
59 int done (void) const;
61 /// Dump the state of an object.
62 void dump (void) const;
64 /// Declare the dynamic allocation hooks.
65 ACE_ALLOC_HOOK_DECLARE;
67 private:
68 /// Pointer to the current node in the iteration.
69 ACE_Node<T> *current_;
71 /// Pointer to the queue we're iterating over.
72 ACE_Unbounded_Queue<T> &queue_;
75 /**
76 * @class ACE_Unbounded_Queue_Const_Iterator
78 * @brief Implement an iterator over an const unbounded queue.
80 template <class T>
81 class ACE_Unbounded_Queue_Const_Iterator
83 public:
84 // = Initialization method.
85 ACE_Unbounded_Queue_Const_Iterator (const ACE_Unbounded_Queue<T> &q, int end = 0);
87 // = Iteration methods.
89 /// Pass back the @a next_item that hasn't been seen in the queue.
90 /// Returns 0 when all items have been seen, else 1.
91 int next (T *&next_item);
93 /// Move forward by one element in the set. Returns 0 when all the
94 /// items in the queue have been seen, else 1.
95 int advance (void);
97 /// Move to the first element in the queue. Returns 0 if the
98 /// queue is empty, else 1.
99 int first (void);
101 /// Returns 1 when all items have been seen, else 0.
102 int done (void) const;
104 /// Dump the state of an object.
105 void dump (void) const;
107 /// Declare the dynamic allocation hooks.
108 ACE_ALLOC_HOOK_DECLARE;
110 private:
111 /// Pointer to the current node in the iteration.
112 ACE_Node<T> *current_;
114 /// Pointer to the queue we're iterating over.
115 const ACE_Unbounded_Queue<T> &queue_;
119 * @class ACE_Unbounded_Queue
121 * @brief A Queue of "infinite" length.
123 * This implementation of an unbounded queue uses a circular
124 * linked list with a dummy node.
126 * <b> Requirements and Performance Characteristics</b>
127 * - Internal Structure
128 * Circular linked list
129 * - Duplicates allowed?
130 * Yes
131 * - Random access allowed?
132 * No
133 * - Search speed
134 * N/A
135 * - Insert/replace speed
136 * N/A
137 * - Iterator still valid after change to container?
138 * Yes
139 * - Frees memory for removed elements?
140 * Yes
141 * - Items inserted by
142 * Value
143 * - Requirements for contained type
144 * -# Default constructor
145 * -# Copy constructor
146 * -# operator=
149 template <class T>
150 class ACE_Unbounded_Queue
152 public:
153 friend class ACE_Unbounded_Queue_Iterator<T>;
154 friend class ACE_Unbounded_Queue_Const_Iterator<T>;
156 // Trait definition.
157 typedef ACE_Unbounded_Queue_Iterator<T> ITERATOR;
158 typedef ACE_Unbounded_Queue_Const_Iterator<T> CONST_ITERATOR;
160 // = Initialization and termination methods.
161 /// Construction. Use user specified allocation strategy
162 /// if specified.
164 * Initialize an empty queue using the strategy provided.
166 ACE_Unbounded_Queue (ACE_Allocator *alloc = 0);
168 /// Copy constructor.
170 * Initialize the queue to be a copy of the provided queue.
172 ACE_Unbounded_Queue (const ACE_Unbounded_Queue<T> &);
174 /// Assignment operator.
176 * Perform a deep copy of rhs.
178 void operator= (const ACE_Unbounded_Queue<T> &);
180 /// Destructor.
182 * Clean up the memory for the queue.
184 ~ACE_Unbounded_Queue (void);
186 // = Check boundary conditions.
188 /// Returns 1 if the container is empty, otherwise returns 0.
190 * Constant time check to see if the queue is empty.
192 int is_empty (void) const;
194 /// Returns 0.
196 * The queue cannot be full, so it always returns 0.
198 int is_full (void) const;
200 // = Classic queue operations.
202 /// Adds @a new_item to the tail of the queue. Returns 0 on success,
203 /// -1 on failure.
205 * Insert an item at the end of the queue.
207 int enqueue_tail (const T &new_item);
209 /// Adds @a new_item to the head of the queue. Returns 0 on success,
210 /// -1 on failure.
212 * Insert an item at the head of the queue.
214 int enqueue_head (const T &new_item);
216 /// Removes and returns the first @a item on the queue. Returns 0 on
217 /// success, -1 if the queue was empty.
219 * Remove an item from the head of the queue.
221 int dequeue_head (T &item);
223 // = Additional utility methods.
225 /// Reset the ACE_Unbounded_Queue to be empty and release all its
226 /// dynamically allocated resources.
228 * Delete the queue nodes.
230 void reset (void);
232 /// Get the @a slot th element in the set. Returns -1 if the element
233 /// isn't in the range {0..#cur_size_ - 1}, else 0.
235 * Find the item in the queue between 0 and the provided index of the
236 * queue.
238 int get (T *&item, size_t slot = 0) const;
240 /// Set the @a slot th element of the queue to @a item.
242 * Set the @a slot th element in the set. Will pad out the set with
243 * empty nodes if @a slot is beyond the range {0..#cur_size_ - 1}.
244 * Returns -1 on failure, 0 if @a slot isn't initially in range, and
245 * 0 otherwise.
247 int set (const T &item, size_t slot);
249 /// The number of items in the queue.
251 * Return the size of the queue.
253 size_t size (void) const;
255 /// Dump the state of an object.
256 void dump (void) const;
258 // = STL-styled unidirectional iterator factory.
259 ACE_Unbounded_Queue_Iterator<T> begin (void);
260 ACE_Unbounded_Queue_Iterator<T> end (void);
262 /// Declare the dynamic allocation hooks.
263 ACE_ALLOC_HOOK_DECLARE;
265 protected:
266 /// Delete all the nodes in the queue.
267 void delete_nodes (void);
269 /// Copy nodes into this queue.
270 void copy_nodes (const ACE_Unbounded_Queue<T> &);
272 /// Pointer to the dummy node in the circular linked Queue.
273 ACE_Node<T> *head_;
275 /// Current size of the queue.
276 size_t cur_size_;
278 /// Allocation Strategy of the queue.
279 ACE_Allocator *allocator_;
282 ACE_END_VERSIONED_NAMESPACE_DECL
284 #if defined (__ACE_INLINE__)
285 #include "ace/Unbounded_Queue.inl"
286 #endif /* __ACE_INLINE__ */
288 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
289 #include "ace/Unbounded_Queue.cpp"
290 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
292 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
293 #pragma implementation ("Unbounded_Queue.cpp")
294 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
296 #include /**/ "ace/post.h"
297 #endif /* ACE_UNBOUNDED_QUEUE_H */