1 karl 1.14 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.4 //
|
3 karl 1.12 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.11 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.12 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.13 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.14 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.4 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 kumpf 1.7 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
18 mike 1.4 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
|
21 kumpf 1.7 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.4 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
24 kumpf 1.7 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
27 mike 1.4 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
|
32 karl 1.6 // Author: Mike Brasher (mbrasher@bmc.com)
|
33 mike 1.4 //
|
34 karl 1.6 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
|
35 mike 1.4 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #ifndef Pegasus_Queue_h
39 #define Pegasus_Queue_h
40
41 #include <Pegasus/Common/Config.h>
|
42 kumpf 1.9 #include <Pegasus/Common/ArrayInternal.h>
|
43 mike 1.4 #include <Pegasus/Common/String.h>
|
44 kumpf 1.8 #include <Pegasus/Common/InternalException.h>
|
45 mike 1.4
46 PEGASUS_NAMESPACE_BEGIN
47
|
48 mike 1.5 // REVIEW: Yet another queue implementation (YAQI).
49
|
50 mike 1.4 /** The Queue class provides a simple FIFO Queue implementation.
51 This class provides a Queue implementation which is based on the Array<>
52 template class. It allows enqueing, dequeing and size determination.
53 */
54 template<class T>
55 class Queue
56 {
57 public:
58
59 /** */
60 Queue() { }
61
62 /** */
63 Queue(const Queue<T>& x) : _rep(x._rep) { }
64
65 /** */
66 ~Queue() { }
67
68 /** */
69 Queue<T>& operator=(const Queue<T>& x) { _rep = x._rep; return *this; }
70
71 mike 1.4 /** */
72 Boolean isEmpty() const { return _rep.size() == 0; }
73
74 /** Enqueue - Adds a new item to the end of the queue*/
75 void enqueue(const T& x) { _rep.append(x); }
76
77 /** dequeue - Removes the first entry from the queue. Note that this does
78 not return the dequeued item to the user.
79 The normal approach to use this is to first look at the first item
80 with the front method and then dequeue with the dequeue
81 */
82 void dequeue();
83
84 /** */
85 T& front();
86
87 /** */
88 const T& front() const { return ((Queue<T>*)this)->front(); }
89
90 /** */
91 T& back();
92 mike 1.4
93 /** */
94 const T& back() const { return ((Queue<T>*)this)->back(); }
95
96
97 /** */
98 Uint32 size() const { return _rep.size(); }
99
100 /** The [] operator allows you to treat the queue as an indexed array
101 and look at individual items on the queue.
102 */
103 T& operator[](Uint32 i) { return _rep[i]; }
104
105 /** The [] operator allows you to treat the queue as an indexed array
106 and look at individual items on the queue.
107 */
108 const T& operator[](Uint32 i) const { return _rep[i]; }
|
109 karl 1.6
110 /* remove - Removes an entry from the queue. Normally the role of
111 queues is to pass information from the back to the front but
112 this function allows removeing any single item from the queue
|
113 kumpf 1.10 @param index - Position in the array containing the item to be removed
114 @exception - Throws the "outOfBounds" exception of index is outside the queue
|
115 karl 1.6 This works because the queue implementation is an array.
116 */
|
117 kumpf 1.10 void remove(Uint32 index) { _rep.remove(index); }
|
118 karl 1.6
119 //void operator
|
120 mike 1.4
121 private:
122
123 Array<T> _rep;
124 };
125
126 template<class T>
127 T& Queue<T>::front()
128 {
129 if (!isEmpty())
130 return _rep[0];
131 else
132 {
133 static T dummy = T();
134 return dummy;
135 }
136 }
137 template<class T>
138 T& Queue<T>::back()
139 {
140 if (!isEmpty())
141 mike 1.4 return _rep[_rep.size() - 1];
142 else
143 {
144 static T dummy = T();
145 return dummy;
146 }
147 }
148
149 template<class T>
150 void Queue<T>::dequeue()
151 {
152 if (_rep.size() == 0)
153 throw QueueUnderflow();
154
155 _rep.remove(0);
156 }
157
158 PEGASUS_NAMESPACE_END
159
160 #endif /* Pegasus_Queue_h */
|