|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 /*! |
|
43 \class Q3PtrStack |
|
44 \brief The Q3PtrStack class is a template class that provides a stack. |
|
45 \compat |
|
46 |
|
47 Q3ValueStack is an STL-compatible alternative to this class. |
|
48 |
|
49 Define a template instance Q3PtrStack\<X\> to create a stack that |
|
50 operates on pointers to X, (X*). |
|
51 |
|
52 A stack is a last in, first out (LIFO) structure. Items are added |
|
53 to the top of the stack with push() and retrieved from the top |
|
54 with pop(). Use top() to get a reference to the top element |
|
55 without changing the stack. |
|
56 |
|
57 You can control the stack's deletion policy with setAutoDelete(). |
|
58 |
|
59 For compatibility with the Q3PtrCollection classes current() and |
|
60 remove() are provided; they both operate on the top(). |
|
61 |
|
62 \sa Q3PtrList Q3PtrQueue |
|
63 */ |
|
64 |
|
65 /*! |
|
66 \fn Q3PtrStack::Q3PtrStack () |
|
67 |
|
68 Creates an empty stack. |
|
69 */ |
|
70 |
|
71 /*! |
|
72 \fn Q3PtrStack::Q3PtrStack (const Q3PtrStack<type>& s) |
|
73 |
|
74 Creates a stack by making a shallow copy of another stack \a s. |
|
75 */ |
|
76 |
|
77 /*! |
|
78 \fn Q3PtrStack::~Q3PtrStack () |
|
79 |
|
80 Destroys the stack. All items will be deleted if autoDelete() is |
|
81 true. |
|
82 */ |
|
83 |
|
84 /*! |
|
85 \fn Q3PtrStack<type>& Q3PtrStack::operator= (const Q3PtrStack<type>& s) |
|
86 |
|
87 Sets the contents of this stack by making a shallow copy of |
|
88 another stack \a s. Elements currently in this stack will be |
|
89 deleted if autoDelete() is true. |
|
90 */ |
|
91 |
|
92 /*! |
|
93 \fn bool Q3PtrStack::isEmpty () const |
|
94 |
|
95 Returns true if the stack contains no elements; otherwise returns |
|
96 false. |
|
97 */ |
|
98 |
|
99 /*! |
|
100 \fn void Q3PtrStack::push (const type* d) |
|
101 |
|
102 Adds an element \a d to the top of the stack. Last in, first out. |
|
103 */ |
|
104 |
|
105 /*! |
|
106 \fn type* Q3PtrStack::pop () |
|
107 |
|
108 Removes the top item from the stack and returns it. The stack must |
|
109 not be empty. |
|
110 */ |
|
111 |
|
112 /*! |
|
113 \fn bool Q3PtrStack::remove () |
|
114 |
|
115 Removes the top item from the stack and deletes it if autoDelete() |
|
116 is true. Returns true if there was an item to pop; otherwise |
|
117 returns false. |
|
118 |
|
119 \sa clear() |
|
120 */ |
|
121 |
|
122 /*! |
|
123 \fn void Q3PtrStack::clear() |
|
124 |
|
125 Removes all items from the stack, deleting them if autoDelete() is |
|
126 true. |
|
127 |
|
128 \sa remove() |
|
129 */ |
|
130 |
|
131 /*! |
|
132 \fn uint Q3PtrStack::count() const |
|
133 |
|
134 Returns the number of items in the stack. |
|
135 |
|
136 \sa isEmpty() |
|
137 */ |
|
138 |
|
139 /*! |
|
140 \fn type* Q3PtrStack::top () const |
|
141 |
|
142 Returns a pointer to the top item on the stack (most recently |
|
143 pushed). The stack is not changed. Returns 0 if the stack is |
|
144 empty. |
|
145 */ |
|
146 |
|
147 /*! |
|
148 \fn Q3PtrStack::operator type* ()const |
|
149 |
|
150 Returns a pointer to the top item on the stack (most recently |
|
151 pushed). The stack is not changed. Returns 0 if the stack is |
|
152 empty. |
|
153 */ |
|
154 |
|
155 /*! |
|
156 \fn type* Q3PtrStack::current () const |
|
157 |
|
158 Returns a pointer to the top item on the stack (most recently |
|
159 pushed). The stack is not changed. Returns 0 if the stack is |
|
160 empty. |
|
161 */ |
|
162 |
|
163 /*! |
|
164 \fn bool Q3PtrStack::autoDelete() const |
|
165 |
|
166 The same as Q3PtrCollection::autoDelete(). Returns true if |
|
167 the auto-delete option is set. If the option is set, the |
|
168 stack auto-deletes its contents. |
|
169 |
|
170 \sa setAutoDelete() |
|
171 */ |
|
172 |
|
173 /*! |
|
174 \fn void Q3PtrStack::setAutoDelete(bool enable) |
|
175 |
|
176 Defines whether this stack auto-deletes its contents. The same as |
|
177 Q3PtrCollection::setAutoDelete(). If \a enable is true, auto-delete |
|
178 is turned on. |
|
179 |
|
180 If auto-deleting is turned on, all the items in the stack are |
|
181 deleted when the stack itself is deleted. This is convenient if |
|
182 the stack has the only pointers to the items. |
|
183 |
|
184 The default setting is false, for safety. If you turn it on, be |
|
185 careful about copying the stack, or you might find yourself with |
|
186 two stacks deleting the same items. |
|
187 |
|
188 Note that the auto-delete setting may also affect other functions in |
|
189 subclasses. For example, a subclass that has a remove() function |
|
190 will remove the item from its data structure, and if auto-delete is |
|
191 enabled, will also delete the item. |
|
192 |
|
193 \sa autoDelete() |
|
194 */ |
|
195 |
|
196 /*! |
|
197 \fn QDataStream& Q3PtrStack::read(QDataStream& s, Q3PtrCollection::Item& item) |
|
198 |
|
199 Reads a stack item, \a item, from the stream \a s and returns a |
|
200 reference to the stream. |
|
201 |
|
202 The default implementation sets \a item to 0. |
|
203 |
|
204 \sa write() |
|
205 */ |
|
206 |
|
207 /*! |
|
208 \fn QDataStream& Q3PtrStack::write(QDataStream& s, |
|
209 Q3PtrCollection::Item item) const |
|
210 |
|
211 Writes a stack item, \a item, to the stream \a s and returns a |
|
212 reference to the stream. |
|
213 |
|
214 The default implementation does nothing. |
|
215 |
|
216 \sa read() |
|
217 */ |