summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/qptrvector.3qt
blob: 8d77130699de40d0581517a1ed717c01794ebdfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
'\" t
.TH QPtrVector 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QPtrVector \- Template collection class that provides a vector (array)
.SH SYNOPSIS
\fC#include <qptrvector.h>\fR
.PP
Inherits QPtrCollection.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQPtrVector\fR ()"
.br
.ti -1c
.BI "\fBQPtrVector\fR ( uint size )"
.br
.ti -1c
.BI "\fBQPtrVector\fR ( const QPtrVector<type> & v )"
.br
.ti -1c
.BI "\fB~QPtrVector\fR ()"
.br
.ti -1c
.BI "QPtrVector<type> & \fBoperator=\fR ( const QPtrVector<type> & v )"
.br
.ti -1c
.BI "bool \fBoperator==\fR ( const QPtrVector<type> & v ) const"
.br
.ti -1c
.BI "type ** \fBdata\fR () const"
.br
.ti -1c
.BI "uint \fBsize\fR () const"
.br
.ti -1c
.BI "virtual uint \fBcount\fR () const"
.br
.ti -1c
.BI "bool \fBisEmpty\fR () const"
.br
.ti -1c
.BI "bool \fBisNull\fR () const"
.br
.ti -1c
.BI "bool \fBresize\fR ( uint size )"
.br
.ti -1c
.BI "bool \fBinsert\fR ( uint i, const type * d )"
.br
.ti -1c
.BI "bool \fBremove\fR ( uint i )"
.br
.ti -1c
.BI "type * \fBtake\fR ( uint i )"
.br
.ti -1c
.BI "virtual void \fBclear\fR ()"
.br
.ti -1c
.BI "bool \fBfill\fR ( const type * d, int size = -1 )"
.br
.ti -1c
.BI "void \fBsort\fR ()"
.br
.ti -1c
.BI "int \fBbsearch\fR ( const type * d ) const"
.br
.ti -1c
.BI "int \fBfindRef\fR ( const type * d, uint i = 0 ) const"
.br
.ti -1c
.BI "int \fBfind\fR ( const type * d, uint i = 0 ) const"
.br
.ti -1c
.BI "uint \fBcontainsRef\fR ( const type * d ) const"
.br
.ti -1c
.BI "uint \fBcontains\fR ( const type * d ) const"
.br
.ti -1c
.BI "type * \fBoperator[]\fR ( int i ) const"
.br
.ti -1c
.BI "type * \fBat\fR ( uint i ) const"
.br
.in -1c
.SS "Important Inherited Members"
.in +1c
.ti -1c
.BI "bool \fBautoDelete\fR () const"
.br
.ti -1c
.BI "void \fBsetAutoDelete\fR ( bool enable )"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "virtual int \fBcompareItems\fR ( QPtrCollection::Item d1, QPtrCollection::Item d2 )"
.br
.ti -1c
.BI "virtual QDataStream & \fBread\fR ( QDataStream & s, QPtrCollection::Item & item )"
.br
.ti -1c
.BI "virtual QDataStream & \fBwrite\fR ( QDataStream & s, QPtrCollection::Item item ) const"
.br
.in -1c
.SH DESCRIPTION
The QPtrVector class is a template collection class that provides a vector (array).
.PP
QValueVector is an STL-compatible alternative to this class.
.PP
QPtrVector is implemented as a template class. Defines a template instance QPtrVector<X> to create a vector that contains pointers to X (X*).
.PP
A vector is the same as an array. The main difference between QPtrVector and QMemArray is that QPtrVector stores pointers to the elements, whereas QMemArray stores the elements themselves (i.e. QMemArray is value-based and QPtrVector is pointer-based).
.PP
Items are added to the vector using insert() or fill(). Items are removed with remove(). You can get a pointer to an item at a particular index position using at().
.PP
Unless otherwise stated, all functions that remove items from the vector will also delete the element pointed to if auto-deletion is enabled. By default, auto-deletion is disabled; see setAutoDelete(). This behaviour can be changed in a subclass by reimplementing the virtual function deleteItem().
.PP
Functions that compare items (find() and sort() for example) will do so using the virtual function compareItems(). The default implementation of this function only compares the pointer values. Reimplement compareItems() in a subclass to get searching and sorting based on the item contents. You can perform a linear search for a pointer in the vector using findRef(), or a binary search (of a sorted vector) using bsearch(). You can count the number of times an item appears in the vector with contains() or containsRef().
.PP
See also QMemArray and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QPtrVector::QPtrVector ()"
Constructs a null vector.
.PP
See also isNull().
.SH "QPtrVector::QPtrVector ( uint size )"
Constructs an vector with room for \fIsize\fR items. Makes a null vector if \fIsize\fR == 0.
.PP
All \fIsize\fR positions in the vector are initialized to 0.
.PP
See also size(), resize(), and isNull().
.SH "QPtrVector::QPtrVector ( const QPtrVector<type> & v )"
Constructs a copy of \fIv\fR. Only the pointers are copied (i.e. shallow copy).
.SH "QPtrVector::~QPtrVector ()"
Removes all items from the vector, and destroys the vector itself.
.PP
See also clear().
.SH "type * QPtrVector::at ( uint i ) const"
Returns the item at position \fIi\fR, or 0 if there is no item at that position. \fIi\fR must be less than size().
.SH "bool QPtrCollection::autoDelete () const"
Returns the setting of the auto-delete option. The default is FALSE.
.PP
See also setAutoDelete().
.SH "int QPtrVector::bsearch ( const type * d ) const"
In a sorted array, finds the first occurrence of \fId\fR using a binary search. For a sorted array, this is generally much faster than find(), which performs a linear search.
.PP
Returns the position of \fId\fR, or -1 if \fId\fR could not be found. \fId\fR must not be 0.
.PP
Compares items using the virtual function compareItems().
.PP
See also sort() and find().
.SH "void QPtrVector::clear ()\fC [virtual]\fR"
Removes all items from the vector, and destroys the vector itself.
.PP
The vector becomes a null vector.
.PP
See also isNull().
.PP
Reimplemented from QPtrCollection.
.SH "int QPtrVector::compareItems ( QPtrCollection::Item d1, QPtrCollection::Item d2 )\fC [virtual protected]\fR"
This virtual function compares two list items.
.PP
Returns:
.TP
zero if \fId1\fR == \fId2\fR
.TP
nonzero if \fId1\fR != \fId2\fR
.PP
This function returns \fIint\fR rather than \fIbool\fR so that reimplementations can return one of three values and use it to sort by:
.TP
0 if \fId1\fR == \fId2\fR
.TP
> 0 (positive integer) if \fId1\fR > \fId2\fR
.TP
< 0 (negative integer) if \fId1\fR < \fId2\fR
.PP
The sort() and bsearch() functions retquire compareItems() to be implemented as described here.
.PP
This function should not modify the vector because some const functions call compareItems().
.SH "uint QPtrVector::contains ( const type * d ) const"
Returns the number of occurrences of item \fId\fR in the vector.
.PP
Compares items using the virtual function compareItems().
.PP
See also containsRef().
.SH "uint QPtrVector::containsRef ( const type * d ) const"
Returns the number of occurrences of the item pointer \fId\fR in the vector.
.PP
This function does \fInot\fR use compareItems() to compare items.
.PP
See also findRef().
.SH "uint QPtrVector::count () const\fC [virtual]\fR"
Returns the number of items in the vector. The vector is empty if count() == 0.
.PP
See also isEmpty(), size(), and isNull().
.PP
Reimplemented from QPtrCollection.
.SH "type ** QPtrVector::data () const"
Returns a pointer to the actual vector data, which is an array of type*.
.PP
The vector is a null vector if data() == 0 (null pointer).
.PP
See also isNull().
.SH "bool QPtrVector::fill ( const type * d, int size = -1 )"
Inserts item \fId\fR in all positions in the vector. Any existing items are removed. If \fId\fR is 0, the vector becomes empty.
.PP
If \fIsize\fR >= 0, the vector is first resized to \fIsize\fR. By default, \fIsize\fR is -1.
.PP
Returns TRUE if successful, i.e. \fIsize\fR is the same as the current size, or \fIsize\fR is larger and the memory has successfully been allocated; otherwise returns FALSE.
.PP
See also resize(), insert(), and isEmpty().
.SH "int QPtrVector::find ( const type * d, uint i = 0 ) const"
Finds the first occurrence of item \fId\fR in the vector using a linear search. The search starts at position \fIi\fR, which must be less than size(). \fIi\fR is by default 0; i.e. the search starts at the start of the vector.
.PP
Returns the position of \fId\fR, or -1 if \fId\fR could not be found.
.PP
Compares items using the virtual function compareItems().
.PP
Use the much faster bsearch() to search a sorted vector.
.PP
See also findRef() and bsearch().
.SH "int QPtrVector::findRef ( const type * d, uint i = 0 ) const"
Finds the first occurrence of the item pointer \fId\fR in the vector using a linear search. The search starts at position \fIi\fR, which must be less than size(). \fIi\fR is by default 0; i.e. the search starts at the start of the vector.
.PP
Returns the position of \fId\fR, or -1 if \fId\fR could not be found.
.PP
This function does \fInot\fR use compareItems() to compare items.
.PP
Use the much faster bsearch() to search a sorted vector.
.PP
See also find() and bsearch().
.SH "bool QPtrVector::insert ( uint i, const type * d )"
Sets position \fIi\fR in the vector to contain the item \fId\fR. \fIi\fR must be less than size(). Any previous element in position \fIi\fR is removed.
.PP
See also at().
.SH "bool QPtrVector::isEmpty () const"
Returns TRUE if the vector is empty; otherwise returns FALSE.
.PP
See also count().
.SH "bool QPtrVector::isNull () const"
Returns TRUE if the vector is null; otherwise returns FALSE.
.PP
A null vector has size() == 0 and data() == 0.
.PP
See also size().
.SH "QPtrVector<type> & QPtrVector::operator= ( const QPtrVector<type> & v )"
Assigns \fIv\fR to this vector and returns a reference to this vector.
.PP
This vector is first cleared and then all the items from \fIv\fR are copied into the vector. Only the pointers are copied (i.e. shallow copy).
.PP
See also clear().
.SH "bool QPtrVector::operator== ( const QPtrVector<type> & v ) const"
Returns TRUE if this vector and \fIv\fR are equal; otherwise returns FALSE.
.SH "type * QPtrVector::operator[] ( int i ) const"
Returns the item at position \fIi\fR, or 0 if there is no item at that position. \fIi\fR must be less than size().
.PP
Equivalent to at( \fIi\fR ).
.PP
See also at().
.SH "QDataStream & QPtrVector::read ( QDataStream & s, QPtrCollection::Item & item )\fC [virtual protected]\fR"
Reads a vector item, \fIitem\fR, from the stream \fIs\fR and returns a reference to the stream.
.PP
The default implementation sets \fIitem\fR to 0.
.PP
See also write().
.SH "bool QPtrVector::remove ( uint i )"
Removes the item at position \fIi\fR in the vector, if there is one. \fIi\fR must be less than size().
.PP
Returns TRUE if \fIi\fR is within range; otherwise returns FALSE.
.PP
See also take() and at().
.SH "bool QPtrVector::resize ( uint size )"
Resizes (expands or shrinks) the vector to \fIsize\fR elements. The vector becomes a null vector if \fIsize\fR == 0.
.PP
Any items at position \fIsize\fR or beyond in the vector are removed. New positions are initialized to 0.
.PP
Returns TRUE if successful, i.e. if the memory was successfully allocated; otherwise returns FALSE.
.PP
See also size() and isNull().
.SH "void QPtrCollection::setAutoDelete ( bool enable )"
Sets the collection to auto-delete its contents if \fIenable\fR is TRUE and to never delete them if \fIenable\fR is FALSE.
.PP
If auto-deleting is turned on, all the items in a collection are deleted when the collection itself is deleted. This is convenient if the collection has the only pointer to the items.
.PP
The default setting is FALSE, for safety. If you turn it on, be careful about copying the collection - you might find yourself with two collections deleting the same items.
.PP
Note that the auto-delete setting may also affect other functions in subclasses. For example, a subclass that has a remove() function will remove the item from its data structure, and if auto-delete is enabled, will also delete the item.
.PP
See also autoDelete().
.PP
Examples:
.)l grapher/grapher.cpp, scribble/scribble.cpp, and table/bigtable/main.cpp.
.SH "uint QPtrVector::size () const"
Returns the size of the vector, i.e. the number of vector positions. This is also the maximum number of items the vector can hold.
.PP
The vector is a null vector if size() == 0.
.PP
See also isNull(), resize(), and count().
.SH "void QPtrVector::sort ()"
Sorts the items in ascending order. Any empty positions will be put last.
.PP
Compares items using the virtual function compareItems().
.PP
See also bsearch().
.SH "type * QPtrVector::take ( uint i )"
Returns the item at position \fIi\fR in the vector, and removes that item from the vector. \fIi\fR must be less than size(). If there is no item at position \fIi\fR, 0 is returned.
.PP
Unlike remove(), this function does \fInot\fR call deleteItem() for the removed item.
.PP
See also remove() and at().
.SH "QDataStream & QPtrVector::write ( QDataStream & s, QPtrCollection::Item item ) const\fC [virtual protected]\fR"
Writes a vector item, \fIitem\fR, to the stream \fIs\fR and returns a reference to the stream.
.PP
The default implementation does nothing.
.PP
See also read().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/qptrvector.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qptrvector.3qt) and the Qt
version (3.3.8).