1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at qt-info@nokia.com.
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \class Q3PtrQueue
|
---|
30 | \brief The Q3PtrQueue class is a template class that provides a queue.
|
---|
31 | \compat
|
---|
32 |
|
---|
33 | Q3ValueVector can be used as an STL-compatible alternative to this
|
---|
34 | class.
|
---|
35 |
|
---|
36 | A template instance Q3PtrQueue\<X\> is a queue that operates on
|
---|
37 | pointers to X (X*).
|
---|
38 |
|
---|
39 | A queue is a first in, first out structure. Items are added to the
|
---|
40 | tail of the queue with enqueue() and retrieved from the head with
|
---|
41 | dequeue(). You can peek at the head item without dequeing it using
|
---|
42 | head().
|
---|
43 |
|
---|
44 | You can control the queue's deletion policy with setAutoDelete().
|
---|
45 |
|
---|
46 | For compatibility with the Q3PtrCollection classes, current() and
|
---|
47 | remove() are provided; both operate on the head().
|
---|
48 |
|
---|
49 | \sa Q3PtrList Q3PtrStack
|
---|
50 | */
|
---|
51 |
|
---|
52 | /*!
|
---|
53 | \fn Q3PtrQueue::Q3PtrQueue ()
|
---|
54 |
|
---|
55 | Creates an empty queue with autoDelete() set to FALSE.
|
---|
56 | */
|
---|
57 |
|
---|
58 | /*!
|
---|
59 | \fn Q3PtrQueue::Q3PtrQueue( const Q3PtrQueue<type>& queue )
|
---|
60 |
|
---|
61 | Creates a queue from \a queue.
|
---|
62 |
|
---|
63 | Only the pointers are copied; the items are not. The autoDelete()
|
---|
64 | flag is set to FALSE.
|
---|
65 | */
|
---|
66 |
|
---|
67 | /*!
|
---|
68 | \fn Q3PtrQueue::~Q3PtrQueue()
|
---|
69 |
|
---|
70 | Destroys the queue. Items in the queue are deleted if autoDelete()
|
---|
71 | is TRUE.
|
---|
72 | */
|
---|
73 |
|
---|
74 | /*!
|
---|
75 | \fn Q3PtrQueue<type>& Q3PtrQueue::operator= (const Q3PtrQueue<type>& queue)
|
---|
76 |
|
---|
77 | Assigns \a queue to this queue and returns a reference to this
|
---|
78 | queue.
|
---|
79 |
|
---|
80 | This queue is first cleared and then each item in \a queue is
|
---|
81 | enqueued to this queue. Only the pointers are copied.
|
---|
82 |
|
---|
83 | \warning The autoDelete() flag is not modified. If it is TRUE for
|
---|
84 | both \a queue and this queue, deleting the two lists will cause \e
|
---|
85 | double-deletion of the items.
|
---|
86 | */
|
---|
87 |
|
---|
88 | /*!
|
---|
89 | \fn bool Q3PtrQueue::isEmpty() const
|
---|
90 |
|
---|
91 | Returns TRUE if the queue is empty; otherwise returns FALSE.
|
---|
92 |
|
---|
93 | \sa count() dequeue() head()
|
---|
94 | */
|
---|
95 |
|
---|
96 | /*!
|
---|
97 | \fn void Q3PtrQueue::enqueue (const type* d)
|
---|
98 |
|
---|
99 | Adds item \a d to the tail of the queue.
|
---|
100 |
|
---|
101 | \sa count() dequeue()
|
---|
102 | */
|
---|
103 |
|
---|
104 | /*!
|
---|
105 | \fn type* Q3PtrQueue::dequeue ()
|
---|
106 |
|
---|
107 | Takes the head item from the queue and returns a pointer to it.
|
---|
108 | Returns 0 if the queue is empty.
|
---|
109 |
|
---|
110 | \sa enqueue() count()
|
---|
111 | */
|
---|
112 |
|
---|
113 | /*!
|
---|
114 | \fn bool Q3PtrQueue::remove()
|
---|
115 |
|
---|
116 | Removes the head item from the queue, and returns TRUE if there
|
---|
117 | was an item, i.e. the queue wasn't empty; otherwise returns FALSE.
|
---|
118 |
|
---|
119 | The item is deleted if autoDelete() is TRUE.
|
---|
120 |
|
---|
121 | \sa head() isEmpty() dequeue()
|
---|
122 | */
|
---|
123 |
|
---|
124 | /*!
|
---|
125 | \fn void Q3PtrQueue::clear()
|
---|
126 |
|
---|
127 | Removes all items from the queue, and deletes them if autoDelete()
|
---|
128 | is TRUE.
|
---|
129 |
|
---|
130 | \sa remove()
|
---|
131 | */
|
---|
132 |
|
---|
133 | /*!
|
---|
134 | \fn uint Q3PtrQueue::count() const
|
---|
135 |
|
---|
136 | Returns the number of items in the queue.
|
---|
137 |
|
---|
138 | \sa isEmpty()
|
---|
139 | */
|
---|
140 |
|
---|
141 | /*!
|
---|
142 | \fn type* Q3PtrQueue::head() const
|
---|
143 |
|
---|
144 | Returns a pointer to the head item in the queue. The queue is not
|
---|
145 | changed. Returns 0 if the queue is empty.
|
---|
146 |
|
---|
147 | \sa dequeue() isEmpty()
|
---|
148 | */
|
---|
149 |
|
---|
150 | /*!
|
---|
151 | \fn Q3PtrQueue::operator type*() const
|
---|
152 |
|
---|
153 | Returns a pointer to the head item in the queue. The queue is not
|
---|
154 | changed. Returns 0 if the queue is empty.
|
---|
155 |
|
---|
156 | \sa dequeue() isEmpty()
|
---|
157 | */
|
---|
158 |
|
---|
159 | /*!
|
---|
160 | \fn type* Q3PtrQueue::current() const
|
---|
161 |
|
---|
162 | Returns a pointer to the head item in the queue. The queue is not
|
---|
163 | changed. Returns 0 if the queue is empty.
|
---|
164 |
|
---|
165 | \sa dequeue() isEmpty()
|
---|
166 | */
|
---|
167 |
|
---|
168 | /*!
|
---|
169 | \fn bool Q3PtrQueue::autoDelete() const
|
---|
170 |
|
---|
171 | Returns the setting of the auto-delete option. The default is
|
---|
172 | FALSE.
|
---|
173 |
|
---|
174 | \sa setAutoDelete()
|
---|
175 | */
|
---|
176 |
|
---|
177 | /*!
|
---|
178 | \fn void Q3PtrQueue::setAutoDelete( bool enable )
|
---|
179 |
|
---|
180 | Sets the queue to auto-delete its contents if \a enable is TRUE
|
---|
181 | and not to delete them if \a enable is FALSE.
|
---|
182 |
|
---|
183 | If auto-deleting is turned on, all the items in a queue are
|
---|
184 | deleted when the queue itself is deleted. This can be quite
|
---|
185 | convenient if the queue has the only pointer to the items.
|
---|
186 |
|
---|
187 | The default setting is FALSE, for safety. If you turn it on, be
|
---|
188 | careful about copying the queue: you might find yourself with two
|
---|
189 | queues deleting the same items.
|
---|
190 |
|
---|
191 | \sa autoDelete()
|
---|
192 | */
|
---|
193 |
|
---|
194 | /*!
|
---|
195 | \fn QDataStream& Q3PtrQueue::read( QDataStream& s,
|
---|
196 | Q3PtrCollection::Item& item )
|
---|
197 |
|
---|
198 | Reads a queue item, \a item, from the stream \a s and returns a
|
---|
199 | reference to the stream.
|
---|
200 |
|
---|
201 | The default implementation sets \a item to 0.
|
---|
202 |
|
---|
203 | \sa write()
|
---|
204 | */
|
---|
205 |
|
---|
206 | /*!
|
---|
207 | \fn QDataStream& Q3PtrQueue::write( QDataStream& s,
|
---|
208 | Q3PtrCollection::Item item ) const
|
---|
209 |
|
---|
210 | Writes a queue item, \a item, to the stream \a s and returns a
|
---|
211 | reference to the stream.
|
---|
212 |
|
---|
213 | The default implementation does nothing.
|
---|
214 |
|
---|
215 | \sa read()
|
---|
216 | */
|
---|