1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/qvaluevector.doc:40 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QValueVector Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QValueVector Class Reference</h1>
|
---|
33 |
|
---|
34 | <p>The QValueVector class is a value-based template class that provides a dynamic array.
|
---|
35 | <a href="#details">More...</a>
|
---|
36 | <p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
|
---|
37 | <p><tt>#include <<a href="qvaluevector-h.html">qvaluevector.h</a>></tt>
|
---|
38 | <p><a href="qvaluevector-members.html">List of all member functions.</a>
|
---|
39 | <h2>Public Members</h2>
|
---|
40 | <ul>
|
---|
41 | <li class=fn>typedef T <a href="#value_type"><b>value_type</b></a></li>
|
---|
42 | <li class=fn>typedef value_type * <a href="#pointer"><b>pointer</b></a></li>
|
---|
43 | <li class=fn>typedef const value_type * <a href="#const_pointer"><b>const_pointer</b></a></li>
|
---|
44 | <li class=fn>typedef value_type * <a href="#iterator"><b>iterator</b></a></li>
|
---|
45 | <li class=fn>typedef const value_type * <a href="#const_iterator"><b>const_iterator</b></a></li>
|
---|
46 | <li class=fn>typedef value_type & <a href="#reference"><b>reference</b></a></li>
|
---|
47 | <li class=fn>typedef const value_type & <a href="#const_reference"><b>const_reference</b></a></li>
|
---|
48 | <li class=fn>typedef size_t <a href="#size_type"><b>size_type</b></a></li>
|
---|
49 | <li class=fn>typedef ptrdiff_t <a href="#difference_type"><b>difference_type</b></a></li>
|
---|
50 | <li class=fn><a href="#QValueVector"><b>QValueVector</b></a> ()</li>
|
---|
51 | <li class=fn><a href="#QValueVector-2"><b>QValueVector</b></a> ( const QValueVector<T> & v )</li>
|
---|
52 | <li class=fn><a href="#QValueVector-3"><b>QValueVector</b></a> ( size_type n, const T & val = T ( ) )</li>
|
---|
53 | <li class=fn><a href="#QValueVector-4"><b>QValueVector</b></a> ( std::vector<T> & v )</li>
|
---|
54 | <li class=fn><a href="#QValueVector-5"><b>QValueVector</b></a> ( const std::vector<T> & v )</li>
|
---|
55 | <li class=fn><a href="#~QValueVector"><b>~QValueVector</b></a> ()</li>
|
---|
56 | <li class=fn>QValueVector<T> & <a href="#operator-eq"><b>operator=</b></a> ( const QValueVector<T> & v )</li>
|
---|
57 | <li class=fn>QValueVector<T> & <a href="#operator-eq-2"><b>operator=</b></a> ( const std::vector<T> & v )</li>
|
---|
58 | <li class=fn>size_type <a href="#size"><b>size</b></a> () const</li>
|
---|
59 | <li class=fn>bool <a href="#empty"><b>empty</b></a> () const</li>
|
---|
60 | <li class=fn>size_type <a href="#capacity"><b>capacity</b></a> () const</li>
|
---|
61 | <li class=fn>iterator <a href="#begin"><b>begin</b></a> ()</li>
|
---|
62 | <li class=fn>const_iterator <a href="#begin-2"><b>begin</b></a> () const</li>
|
---|
63 | <li class=fn>const_iterator <a href="#constBegin"><b>constBegin</b></a> () const</li>
|
---|
64 | <li class=fn>iterator <a href="#end"><b>end</b></a> ()</li>
|
---|
65 | <li class=fn>const_iterator <a href="#end-2"><b>end</b></a> () const</li>
|
---|
66 | <li class=fn>const_iterator <a href="#constEnd"><b>constEnd</b></a> () const</li>
|
---|
67 | <li class=fn>reference <a href="#at"><b>at</b></a> ( size_type i, bool * ok = 0 )</li>
|
---|
68 | <li class=fn>const_reference <a href="#at-2"><b>at</b></a> ( size_type i, bool * ok = 0 ) const</li>
|
---|
69 | <li class=fn>reference <a href="#operator[]"><b>operator[]</b></a> ( size_type i )</li>
|
---|
70 | <li class=fn>const_reference <a href="#operator[]-2"><b>operator[]</b></a> ( size_type i ) const</li>
|
---|
71 | <li class=fn>reference <a href="#front"><b>front</b></a> ()</li>
|
---|
72 | <li class=fn>const_reference <a href="#front-2"><b>front</b></a> () const</li>
|
---|
73 | <li class=fn>reference <a href="#back"><b>back</b></a> ()</li>
|
---|
74 | <li class=fn>const_reference <a href="#back-2"><b>back</b></a> () const</li>
|
---|
75 | <li class=fn>void <a href="#push_back"><b>push_back</b></a> ( const T & x )</li>
|
---|
76 | <li class=fn>void <a href="#pop_back"><b>pop_back</b></a> ()</li>
|
---|
77 | <li class=fn>iterator <a href="#insert"><b>insert</b></a> ( iterator pos, const T & x )</li>
|
---|
78 | <li class=fn>iterator <a href="#insert-2"><b>insert</b></a> ( iterator pos, size_type n, const T & x )</li>
|
---|
79 | <li class=fn>void <a href="#reserve"><b>reserve</b></a> ( size_type n )</li>
|
---|
80 | <li class=fn>void <a href="#resize"><b>resize</b></a> ( size_type n, const T & val = T ( ) )</li>
|
---|
81 | <li class=fn>void <a href="#clear"><b>clear</b></a> ()</li>
|
---|
82 | <li class=fn>iterator <a href="#erase"><b>erase</b></a> ( iterator pos )</li>
|
---|
83 | <li class=fn>iterator <a href="#erase-2"><b>erase</b></a> ( iterator first, iterator last )</li>
|
---|
84 | <li class=fn>bool <a href="#operator-eq-eq-2"><b>operator==</b></a> ( const QValueVector<T> & x )</li>
|
---|
85 | <li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QValueVector<T> & x ) const</li>
|
---|
86 | <li class=fn>typedef T <a href="#ValueType"><b>ValueType</b></a></li>
|
---|
87 | <li class=fn>typedef ValueType * <a href="#Iterator"><b>Iterator</b></a></li>
|
---|
88 | <li class=fn>typedef const ValueType * <a href="#ConstIterator"><b>ConstIterator</b></a></li>
|
---|
89 | <li class=fn>size_type <a href="#count"><b>count</b></a> () const</li>
|
---|
90 | <li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
|
---|
91 | <li class=fn>reference <a href="#first"><b>first</b></a> ()</li>
|
---|
92 | <li class=fn>const_reference <a href="#first-2"><b>first</b></a> () const</li>
|
---|
93 | <li class=fn>reference <a href="#last"><b>last</b></a> ()</li>
|
---|
94 | <li class=fn>const_reference <a href="#last-2"><b>last</b></a> () const</li>
|
---|
95 | <li class=fn>void <a href="#append"><b>append</b></a> ( const T & x )</li>
|
---|
96 | </ul>
|
---|
97 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
98 |
|
---|
99 |
|
---|
100 | The QValueVector class is a value-based template class that provides a dynamic array.
|
---|
101 | <p>
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|
106 | <p> QValueVector is a Qt implementation of an STL-like vector
|
---|
107 | container. It can be used in your application if the standard <tt>vector</tt> is not available for your target platforms. QValueVector is
|
---|
108 | part of the <a href="qtl.html">Qt Template Library</a>.
|
---|
109 | <p> QValueVector<T> defines a template instance to create a vector
|
---|
110 | of values that all have the class T. QValueVector does not store
|
---|
111 | pointers to the members of the vector; it holds a copy of every
|
---|
112 | member. QValueVector is said to be value based; in contrast,
|
---|
113 | <a href="qptrlist.html">QPtrList</a> and <a href="qdict.html">QDict</a> are pointer based.
|
---|
114 | <p> QValueVector contains and manages a collection of objects of type
|
---|
115 | T and provides random access iterators that allow the contained
|
---|
116 | objects to be addressed. QValueVector owns the contained
|
---|
117 | elements. For more relaxed ownership semantics, see <a href="qptrcollection.html">QPtrCollection</a>
|
---|
118 | and friends, which are pointer-based containers.
|
---|
119 | <p> QValueVector provides good performance if you append or remove
|
---|
120 | elements from the end of the vector. If you insert or remove
|
---|
121 | elements from anywhere but the end, performance is very bad. The
|
---|
122 | reason for this is that elements must to be copied into new
|
---|
123 | positions.
|
---|
124 | <p> Some classes cannot be used within a QValueVector: for example,
|
---|
125 | all classes derived from <a href="qobject.html">QObject</a> and thus all classes that
|
---|
126 | implement widgets. Only values can be used in a QValueVector. To
|
---|
127 | qualify as a value the class must provide:
|
---|
128 | <ul>
|
---|
129 | <li> a copy constructor;
|
---|
130 | <li> an assignment operator;
|
---|
131 | <li> a default constructor, i.e., a constructor that does not take any arguments.
|
---|
132 | </ul>
|
---|
133 | <p> Note that C++ defaults to field-by-field assignment operators and
|
---|
134 | copy constructors if no explicit version is supplied. In many
|
---|
135 | cases this is sufficient.
|
---|
136 | <p> QValueVector uses an STL-like syntax to manipulate and address the
|
---|
137 | objects it contains. See <a href="qtl.html">this document</a> for
|
---|
138 | more information.
|
---|
139 | <p> Example:
|
---|
140 | <pre>
|
---|
141 | #include <<a href="qvaluevector-h.html">qvaluevector.h</a>>
|
---|
142 | #include <<a href="qstring-h.html">qstring.h</a>>
|
---|
143 | #include <stdio.h>
|
---|
144 |
|
---|
145 | class Employee
|
---|
146 | {
|
---|
147 | public:
|
---|
148 | Employee(): s(0) {}
|
---|
149 | Employee( const <a href="qstring.html">QString</a>& name, int salary )
|
---|
150 | : n( name ), s( salary )
|
---|
151 | { }
|
---|
152 |
|
---|
153 | <a href="qstring.html">QString</a> name() const { return n; }
|
---|
154 | int salary() const { return s; }
|
---|
155 | void setSalary( int salary ) { s = salary; }
|
---|
156 | private:
|
---|
157 | <a href="qstring.html">QString</a> n;
|
---|
158 | int s;
|
---|
159 | };
|
---|
160 |
|
---|
161 | int main()
|
---|
162 | {
|
---|
163 | typedef QValueVector<Employee> EmployeeVector;
|
---|
164 | EmployeeVector vec( 3 ); // vector of 3 Employees
|
---|
165 |
|
---|
166 | vec[0] = Employee( "Bill", 50000 );
|
---|
167 | vec[1] = Employee( "Steve", 80000 );
|
---|
168 | vec[2] = Employee( "Ron", 60000 );
|
---|
169 |
|
---|
170 | Employee joe( "Joe", 50000 );
|
---|
171 | vec.push_back( joe ); // vector expands to accommodate 4 Employees
|
---|
172 | joe.setSalary( 70000 );
|
---|
173 |
|
---|
174 | EmployeeVector::<a href="#iterator">iterator</a> it;
|
---|
175 | for( it = vec.begin(); it != vec.end(); ++it )
|
---|
176 | printf( "%s earns %d\n", (*it).name().latin1(), (*it).salary() );
|
---|
177 |
|
---|
178 | return 0;
|
---|
179 | }
|
---|
180 | </pre>
|
---|
181 |
|
---|
182 | <p> Program output:
|
---|
183 | <pre>
|
---|
184 | Bill earns 50000
|
---|
185 | Steve earns 80000
|
---|
186 | Ron earns 60000
|
---|
187 | Joe earns 50000
|
---|
188 | </pre>
|
---|
189 |
|
---|
190 | <p> As you can see, the most recent change to Joe's salary did not
|
---|
191 | affect the value in the vector because the vector created a copy
|
---|
192 | of Joe's entry.
|
---|
193 | <p> Many Qt functions return const value vectors; to iterate over
|
---|
194 | these you should make a copy and iterate over the copy.
|
---|
195 | <p> There are several ways to find items in the vector. The <a href="#begin">begin</a>()
|
---|
196 | and <a href="#end">end</a>() functions return iterators to the beginning and end of
|
---|
197 | the vector. The advantage of getting an iterator is that you can
|
---|
198 | move forward or backward from this position by
|
---|
199 | incrementing/decrementing the iterator. The iterator returned by
|
---|
200 | end() points to the element which is one past the last element in
|
---|
201 | the container. The past-the-end iterator is still associated with
|
---|
202 | the vector it belongs to, however it is <em>not</em> dereferenceable;
|
---|
203 | <a href="qsize.html#operator*-4">operator*</a>() will not return a well-defined value. If the vector is
|
---|
204 | <a href="#empty">empty</a>(), the iterator returned by begin() will equal the iterator
|
---|
205 | returned by end().
|
---|
206 | <p> The fastest way to access an element of a vector is by using
|
---|
207 | operator[]. This function provides random access and will return
|
---|
208 | a reference to the element located at the specified index. Thus,
|
---|
209 | you can access every element directly, in constant time, providing
|
---|
210 | you know the location of the element. It is undefined to access
|
---|
211 | an element that does not exist (your application will probably
|
---|
212 | crash). For example:
|
---|
213 | <p> <pre>
|
---|
214 | QValueVector<int> vec1; // an empty vector
|
---|
215 | vec1[10] = 4; // WARNING: undefined, probably a crash
|
---|
216 |
|
---|
217 | QValueVector<QString> vec2(25); // initialize with 25 elements
|
---|
218 | vec2[10] = "Dave"; // OK
|
---|
219 | </pre>
|
---|
220 |
|
---|
221 | <p> Whenever inserting, removing or referencing elements in a vector,
|
---|
222 | always make sure you are referring to valid positions. For
|
---|
223 | example:
|
---|
224 | <p> <pre>
|
---|
225 | void func( QValueVector<int>& vec )
|
---|
226 | {
|
---|
227 | if ( vec.<a href="#size">size</a>() > 10 ) {
|
---|
228 | vec[9] = 99; // OK
|
---|
229 | }
|
---|
230 | };
|
---|
231 | </pre>
|
---|
232 |
|
---|
233 | <p> The iterators provided by vector are random access iterators,
|
---|
234 | therefore you can use them with many generic algorithms, for
|
---|
235 | example, algorithms provided by the STL or the <a href="qtl.html">QTL</a>.
|
---|
236 | <p> Another way to find an element in the vector is by using the
|
---|
237 | std::find() or <a href="qtl.html#qFind">qFind()</a> algorithms.
|
---|
238 | For example:
|
---|
239 | <p> <pre>
|
---|
240 | QValueVector<int> vec;
|
---|
241 | ...
|
---|
242 | QValueVector<int>::<a href="#const_iterator">const_iterator</a> it = qFind( vec.<a href="#begin">begin</a>(), vec.<a href="#end">end</a>(), 3 );
|
---|
243 | if ( it != vector.end() )
|
---|
244 | // 'it' points to the found element
|
---|
245 | </pre>
|
---|
246 |
|
---|
247 | <p> It is safe to have multiple iterators on the vector at the same
|
---|
248 | time. Since QValueVector manages memory dynamically, all iterators
|
---|
249 | can become invalid if a memory reallocation occurs. For example,
|
---|
250 | if some member of the vector is removed, iterators that point to
|
---|
251 | the removed element and to all following elements become
|
---|
252 | invalidated. Inserting into the middle of the vector will
|
---|
253 | invalidate all iterators. For convenience, the function <a href="#back">back</a>()
|
---|
254 | returns a reference to the last element in the vector, and <a href="#front">front</a>()
|
---|
255 | returns a reference to the first element. If the vector is
|
---|
256 | <a href="#empty">empty</a>(), both back() and front() have undefined behavior (your
|
---|
257 | application will crash or do unpredictable things). Use back() and
|
---|
258 | front() with caution, for example:
|
---|
259 | <p> <pre>
|
---|
260 | QValueVector<int> vec( 3 );
|
---|
261 | vec.<a href="#push_back">push_back</a>( 1 );
|
---|
262 | vec.<a href="#push_back">push_back</a>( 2 );
|
---|
263 | vec.<a href="#push_back">push_back</a>( 3 );
|
---|
264 | ...
|
---|
265 | if ( !vec.<a href="#empty">empty</a>() ) {
|
---|
266 | // OK: modify the first element
|
---|
267 | int& i = vec.<a href="#front">front</a>();
|
---|
268 | i = 18;
|
---|
269 | }
|
---|
270 | ...
|
---|
271 | QValueVector<double> dvec;
|
---|
272 | double d = dvec.<a href="#back">back</a>(); // undefined behavior
|
---|
273 | </pre>
|
---|
274 |
|
---|
275 | <p> Because QValueVector manages memory dynamically, it is recommended
|
---|
276 | that you contruct a vector with an initial size. Inserting and
|
---|
277 | removing elements happens fastest when:
|
---|
278 | <ul>
|
---|
279 | <li> Inserting or removing elements happens at the <a href="#end">end</a>() of the
|
---|
280 | vector;
|
---|
281 | <li> The vector does not need to allocate additional memory.
|
---|
282 | </ul>
|
---|
283 | <p> By creating a QValueVector with a sufficiently large initial size,
|
---|
284 | there will be less memory allocations. Do not use an initial size
|
---|
285 | that is too big, since it will still take time to construct all
|
---|
286 | the empty entries, and the extra space will be wasted if it is
|
---|
287 | never used.
|
---|
288 | <p> Because QValueVector is value-based there is no need to be careful
|
---|
289 | about deleting elements in the vector. The vector holds its own
|
---|
290 | copies and will free them if the corresponding member or the
|
---|
291 | vector itself is deleted. You can force the vector to free all of
|
---|
292 | its items with <a href="#clear">clear</a>().
|
---|
293 | <p> QValueVector is <a href="shclass.html#shared-implicitly">shared implicitly</a>, which means it can be copied in
|
---|
294 | constant time. If multiple QValueVector instances share the same
|
---|
295 | data and one needs to modify its contents, this modifying instance
|
---|
296 | makes a copy and modifies its private copy; it thus does not
|
---|
297 | affect the other instances. This is often called "copy on write".
|
---|
298 | If a QValueVector is being used in a multi-threaded program, you
|
---|
299 | must protect all access to the vector. See <a href="qmutex.html">QMutex</a>.
|
---|
300 | <p> There are several ways to insert elements into the vector. The
|
---|
301 | <a href="#push_back">push_back</a>() function insert elements into the end of the vector,
|
---|
302 | and is usually fastest. The <a href="#insert">insert</a>() function can be used to add
|
---|
303 | elements at specific positions within the vector.
|
---|
304 | <p> Items can be also be removed from the vector in several ways.
|
---|
305 | There are several variants of the <a href="#erase">erase</a>() function which removes a
|
---|
306 | specific element, or range of elements, from the vector.
|
---|
307 | <p> Vectors can be also sorted with various STL algorithms , or it can
|
---|
308 | be sorted using the <a href="qtl.html">Qt Template Library</a>.
|
---|
309 | For example with qHeapSort():
|
---|
310 | <p> Example:
|
---|
311 | <pre>
|
---|
312 | QValueVector<int> v( 4 );
|
---|
313 | v.<a href="#push_back">push_back</a>( 5 );
|
---|
314 | v.<a href="#push_back">push_back</a>( 8 );
|
---|
315 | v.<a href="#push_back">push_back</a>( 3 );
|
---|
316 | v.<a href="#push_back">push_back</a>( 4 );
|
---|
317 | qHeapSort( v );
|
---|
318 | </pre>
|
---|
319 |
|
---|
320 | <p> QValueVector stores its elements in contiguous memory. This means
|
---|
321 | that you can use a QValueVector in any situation that requires an
|
---|
322 | array.
|
---|
323 | <p>See also <a href="qtl.html">Qt Template Library Classes</a>, <a href="shared.html">Implicitly and Explicitly Shared Classes</a>, and <a href="tools.html">Non-GUI Classes</a>.
|
---|
324 |
|
---|
325 | <hr><h2>Member Type Documentation</h2>
|
---|
326 | <h3 class=fn><a name="ConstIterator"></a>QValueVector::ConstIterator</h3>
|
---|
327 | The vector's const iterator type.
|
---|
328 | <h3 class=fn><a name="Iterator"></a>QValueVector::Iterator</h3>
|
---|
329 | The vector's iterator type.
|
---|
330 | <h3 class=fn><a name="ValueType"></a>QValueVector::ValueType</h3>
|
---|
331 | The type of the object stored in the vector.
|
---|
332 | <h3 class=fn><a name="const_iterator"></a>QValueVector::const_iterator</h3>
|
---|
333 | The vector's const iterator type.
|
---|
334 | <h3 class=fn><a name="const_pointer"></a>QValueVector::const_pointer</h3>
|
---|
335 | The const pointer to T type.
|
---|
336 | <h3 class=fn><a name="const_reference"></a>QValueVector::const_reference</h3>
|
---|
337 | The const reference to T type.
|
---|
338 | <h3 class=fn><a name="difference_type"></a>QValueVector::difference_type</h3>
|
---|
339 | A signed integral type used to represent the distance between two iterators.
|
---|
340 | <h3 class=fn><a name="iterator"></a>QValueVector::iterator</h3>
|
---|
341 | The vector's iterator type.
|
---|
342 | <h3 class=fn><a name="pointer"></a>QValueVector::pointer</h3>
|
---|
343 | The pointer to T type.
|
---|
344 | <h3 class=fn><a name="reference"></a>QValueVector::reference</h3>
|
---|
345 | The reference to T type.
|
---|
346 | <h3 class=fn><a name="size_type"></a>QValueVector::size_type</h3>
|
---|
347 | An unsigned integral type, used to represent various sizes.
|
---|
348 | <h3 class=fn><a name="value_type"></a>QValueVector::value_type</h3>
|
---|
349 | The type of the object stored in the vector.
|
---|
350 | <hr><h2>Member Function Documentation</h2>
|
---|
351 | <h3 class=fn><a name="QValueVector"></a>QValueVector::QValueVector ()
|
---|
352 | </h3>
|
---|
353 |
|
---|
354 | <p> Constructs an empty vector without any elements. To create a
|
---|
355 | vector which reserves an initial amount of space for elements, use
|
---|
356 | <tt>QValueVector(size_type n)</tt>.
|
---|
357 |
|
---|
358 | <h3 class=fn><a name="QValueVector-2"></a>QValueVector::QValueVector ( const <a href="qvaluevector.html">QValueVector</a><T> & v )
|
---|
359 | </h3>
|
---|
360 |
|
---|
361 | <p> Constructs a copy of <em>v</em>.
|
---|
362 | <p> This operation costs O(1) time because QValueVector is <a href="shclass.html#implicitly-shared">implicitly shared</a>.
|
---|
363 | <p> The first modification to the vector does takes O(n) time, because
|
---|
364 | the elements must be copied.
|
---|
365 |
|
---|
366 | <h3 class=fn><a name="QValueVector-3"></a>QValueVector::QValueVector ( <a href="qvaluevector.html#size_type">size_type</a> n, const T & val = T ( ) )
|
---|
367 | </h3>
|
---|
368 |
|
---|
369 | <p> Constructs a vector with an initial size of <em>n</em> elements. Each
|
---|
370 | element is initialized with the value of <em>val</em>.
|
---|
371 |
|
---|
372 | <h3 class=fn><a name="QValueVector-4"></a>QValueVector::QValueVector ( std::vector<T> & v )
|
---|
373 | </h3>
|
---|
374 |
|
---|
375 | <p> Constructs a copy of <em>v</em>.
|
---|
376 |
|
---|
377 | <h3 class=fn><a name="QValueVector-5"></a>QValueVector::QValueVector ( const std::vector<T> & v )
|
---|
378 | </h3>
|
---|
379 |
|
---|
380 | <p> This operation costs O(n) time because <em>v</em> is copied.
|
---|
381 |
|
---|
382 | <h3 class=fn><a name="~QValueVector"></a>QValueVector::~QValueVector ()
|
---|
383 | </h3>
|
---|
384 |
|
---|
385 | <p> Destroys the vector, destroying all elements and freeing the
|
---|
386 | allocated memory. References to the values in the vector and all
|
---|
387 | iterators of this vector become invalidated. Note that it is
|
---|
388 | impossible for an iterator to check whether or not it is valid:
|
---|
389 | QValueVector is tuned for performance, not for error checking.
|
---|
390 |
|
---|
391 | <h3 class=fn>void <a name="append"></a>QValueVector::append ( const T & x )
|
---|
392 | </h3>
|
---|
393 |
|
---|
394 | <p> Appends a copy of <em>x</em> to the end of the vector.
|
---|
395 | <p> <p>See also <a href="#push_back">push_back</a>() and <a href="#insert">insert</a>().
|
---|
396 |
|
---|
397 | <h3 class=fn><a href="qvaluevector.html#reference">reference</a> <a name="at"></a>QValueVector::at ( <a href="qvaluevector.html#size_type">size_type</a> i, bool * ok = 0 )
|
---|
398 | </h3>
|
---|
399 |
|
---|
400 | <p> Returns a reference to the element with index <em>i</em>. If <em>ok</em> is
|
---|
401 | non-null, and the index <em>i</em> is out of range, *<em>ok</em> is set to
|
---|
402 | FALSE and the returned reference is undefined. If the index <em>i</em>
|
---|
403 | is within the range of the vector, and <em>ok</em> is non-null, *<em>ok</em>
|
---|
404 | is set to TRUE and the returned reference is well defined.
|
---|
405 |
|
---|
406 | <h3 class=fn><a href="qvaluevector.html#const_reference">const_reference</a> <a name="at-2"></a>QValueVector::at ( <a href="qvaluevector.html#size_type">size_type</a> i, bool * ok = 0 ) const
|
---|
407 | </h3>
|
---|
408 |
|
---|
409 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
410 | <p> Returns a const reference to the element with index <em>i</em>. If <em>ok</em>
|
---|
411 | is non-null, and the index <em>i</em> is out of range, *<em>ok</em> is set to
|
---|
412 | FALSE and the returned reference is undefined. If the index <em>i</em>
|
---|
413 | is within the range of the vector, and <em>ok</em> is non-null, *<em>ok</em>
|
---|
414 | is set to TRUE and the returned reference is well defined.
|
---|
415 |
|
---|
416 | <h3 class=fn><a href="qvaluevector.html#reference">reference</a> <a name="back"></a>QValueVector::back ()
|
---|
417 | </h3>
|
---|
418 |
|
---|
419 | <p> Returns a reference to the last element in the vector. If there is
|
---|
420 | no last element, this function has undefined behavior.
|
---|
421 | <p> <p>See also <a href="#empty">empty</a>() and <a href="#front">front</a>().
|
---|
422 |
|
---|
423 | <h3 class=fn><a href="qvaluevector.html#const_reference">const_reference</a> <a name="back-2"></a>QValueVector::back () const
|
---|
424 | </h3>
|
---|
425 |
|
---|
426 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
427 | <p> Returns a const reference to the last element in the vector. If
|
---|
428 | there is no last element, this function has undefined behavior.
|
---|
429 | <p> <p>See also <a href="#empty">empty</a>() and <a href="#front">front</a>().
|
---|
430 |
|
---|
431 | <h3 class=fn><a href="qvaluevector.html#iterator">iterator</a> <a name="begin"></a>QValueVector::begin ()
|
---|
432 | </h3>
|
---|
433 |
|
---|
434 | <p> Returns an iterator pointing to the beginning of the vector. If
|
---|
435 | the vector is <a href="#empty">empty</a>(), the returned iterator will equal <a href="#end">end</a>().
|
---|
436 |
|
---|
437 | <h3 class=fn><a href="qvaluevector.html#const_iterator">const_iterator</a> <a name="begin-2"></a>QValueVector::begin () const
|
---|
438 | </h3>
|
---|
439 |
|
---|
440 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
441 | <p> Returns a const iterator pointing to the beginning of the vector.
|
---|
442 | If the vector is <a href="#empty">empty</a>(), the returned iterator will equal <a href="#end">end</a>().
|
---|
443 |
|
---|
444 | <h3 class=fn><a href="qvaluevector.html#size_type">size_type</a> <a name="capacity"></a>QValueVector::capacity () const
|
---|
445 | </h3>
|
---|
446 |
|
---|
447 | <p> Returns the maximum number of elements that can be stored in the
|
---|
448 | vector without forcing memory reallocation. If memory reallocation
|
---|
449 | takes place, some or all iterators may become invalidated.
|
---|
450 |
|
---|
451 | <h3 class=fn>void <a name="clear"></a>QValueVector::clear ()
|
---|
452 | </h3>
|
---|
453 |
|
---|
454 | <p> Removes all the elements from the vector.
|
---|
455 |
|
---|
456 | <h3 class=fn><a href="qvaluevector.html#const_iterator">const_iterator</a> <a name="constBegin"></a>QValueVector::constBegin () const
|
---|
457 | </h3>
|
---|
458 |
|
---|
459 | <p> Returns a const iterator pointing to the beginning of the vector.
|
---|
460 | If the vector is <a href="#empty">empty</a>(), the returned iterator will equal <a href="#end">end</a>().
|
---|
461 | <p> <p>See also <a href="#constEnd">constEnd</a>().
|
---|
462 |
|
---|
463 | <h3 class=fn><a href="qvaluevector.html#const_iterator">const_iterator</a> <a name="constEnd"></a>QValueVector::constEnd () const
|
---|
464 | </h3>
|
---|
465 |
|
---|
466 | <p> Returns a const iterator pointing behind the last element of the
|
---|
467 | vector.
|
---|
468 | <p> <p>See also <a href="#constBegin">constBegin</a>().
|
---|
469 |
|
---|
470 | <h3 class=fn><a href="qvaluevector.html#size_type">size_type</a> <a name="count"></a>QValueVector::count () const
|
---|
471 | </h3>
|
---|
472 |
|
---|
473 | <p> Returns the number of items in the vector.
|
---|
474 | <p> <p>See also <a href="#isEmpty">isEmpty</a>().
|
---|
475 |
|
---|
476 | <h3 class=fn>bool <a name="empty"></a>QValueVector::empty () const
|
---|
477 | </h3>
|
---|
478 |
|
---|
479 | <p> Returns TRUE if the vector is empty; otherwise returns FALSE.
|
---|
480 | Equivalent to <a href="#size">size</a>()==0, only faster.
|
---|
481 | <p> This function is provided for STL compatibility. It is equivalent
|
---|
482 | to <a href="#isEmpty">isEmpty</a>().
|
---|
483 | <p> <p>See also <a href="#size">size</a>().
|
---|
484 |
|
---|
485 | <h3 class=fn><a href="qvaluevector.html#iterator">iterator</a> <a name="end"></a>QValueVector::end ()
|
---|
486 | </h3>
|
---|
487 |
|
---|
488 | <p> Returns an iterator pointing behind the last element of the
|
---|
489 | vector.
|
---|
490 |
|
---|
491 | <h3 class=fn><a href="qvaluevector.html#const_iterator">const_iterator</a> <a name="end-2"></a>QValueVector::end () const
|
---|
492 | </h3>
|
---|
493 |
|
---|
494 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
495 | <p> Returns a const iterator pointing behind the last element of the
|
---|
496 | vector.
|
---|
497 |
|
---|
498 | <h3 class=fn><a href="qvaluevector.html#iterator">iterator</a> <a name="erase"></a>QValueVector::erase ( <a href="qvaluevector.html#iterator">iterator</a> pos )
|
---|
499 | </h3>
|
---|
500 |
|
---|
501 | <p> Removes the element at position <em>pos</em> and returns the position of
|
---|
502 | the next element.
|
---|
503 |
|
---|
504 | <h3 class=fn><a href="qvaluevector.html#iterator">iterator</a> <a name="erase-2"></a>QValueVector::erase ( <a href="qvaluevector.html#iterator">iterator</a> first, <a href="qvaluevector.html#iterator">iterator</a> last )
|
---|
505 | </h3>
|
---|
506 |
|
---|
507 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
508 | <p> Removes all elements from <em>first</em> up to but not including <em>last</em>
|
---|
509 | and returns the position of the next element.
|
---|
510 |
|
---|
511 | <h3 class=fn><a href="qvaluevector.html#reference">reference</a> <a name="first"></a>QValueVector::first ()
|
---|
512 | </h3>
|
---|
513 |
|
---|
514 | <p> Returns a reference to the first item in the vector. If there is
|
---|
515 | no first item, this function has undefined behavior.
|
---|
516 | <p> <p>See also <a href="#empty">empty</a>() and <a href="#last">last</a>().
|
---|
517 |
|
---|
518 | <h3 class=fn><a href="qvaluevector.html#const_reference">const_reference</a> <a name="first-2"></a>QValueVector::first () const
|
---|
519 | </h3>
|
---|
520 |
|
---|
521 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
522 | <p>
|
---|
523 | <h3 class=fn><a href="qvaluevector.html#reference">reference</a> <a name="front"></a>QValueVector::front ()
|
---|
524 | </h3>
|
---|
525 |
|
---|
526 | <p> Returns a reference to the first element in the vector. If there
|
---|
527 | is no first element, this function has undefined behavior.
|
---|
528 | <p> <p>See also <a href="#empty">empty</a>() and <a href="#back">back</a>().
|
---|
529 |
|
---|
530 | <h3 class=fn><a href="qvaluevector.html#const_reference">const_reference</a> <a name="front-2"></a>QValueVector::front () const
|
---|
531 | </h3>
|
---|
532 |
|
---|
533 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
534 | <p> Returns a const reference to the first element in the vector. If
|
---|
535 | there is no first element, this function has undefined behavior.
|
---|
536 | <p> <p>See also <a href="#empty">empty</a>() and <a href="#back">back</a>().
|
---|
537 |
|
---|
538 | <h3 class=fn><a href="qvaluevector.html#iterator">iterator</a> <a name="insert"></a>QValueVector::insert ( <a href="qvaluevector.html#iterator">iterator</a> pos, const T & x )
|
---|
539 | </h3>
|
---|
540 |
|
---|
541 | <p> Inserts a copy of <em>x</em> at the position immediately before <em>pos</em>.
|
---|
542 | <p> <p>See also <a href="#push_back">push_back</a>().
|
---|
543 |
|
---|
544 | <h3 class=fn><a href="qvaluevector.html#iterator">iterator</a> <a name="insert-2"></a>QValueVector::insert ( <a href="qvaluevector.html#iterator">iterator</a> pos, <a href="qvaluevector.html#size_type">size_type</a> n, const T & x )
|
---|
545 | </h3>
|
---|
546 |
|
---|
547 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
548 | <p> Inserts <em>n</em> copies of <em>x</em> immediately before position x.
|
---|
549 | <p> <p>See also <a href="#push_back">push_back</a>().
|
---|
550 |
|
---|
551 | <h3 class=fn>bool <a name="isEmpty"></a>QValueVector::isEmpty () const
|
---|
552 | </h3>
|
---|
553 |
|
---|
554 | <p> Returns TRUE if the vector is empty; returns FALSE otherwise.
|
---|
555 | <p> <p>See also <a href="#count">count</a>().
|
---|
556 |
|
---|
557 | <h3 class=fn><a href="qvaluevector.html#reference">reference</a> <a name="last"></a>QValueVector::last ()
|
---|
558 | </h3>
|
---|
559 |
|
---|
560 | <p> Returns a reference to the last item in the vector. If there is no
|
---|
561 | last item, this function has undefined behavior.
|
---|
562 | <p> <p>See also <a href="#empty">empty</a>() and <a href="#first">first</a>().
|
---|
563 |
|
---|
564 | <h3 class=fn><a href="qvaluevector.html#const_reference">const_reference</a> <a name="last-2"></a>QValueVector::last () const
|
---|
565 | </h3>
|
---|
566 |
|
---|
567 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
568 | <p>
|
---|
569 | <h3 class=fn><a href="qvaluevector.html">QValueVector</a><T> & <a name="operator-eq"></a>QValueVector::operator= ( const <a href="qvaluevector.html">QValueVector</a><T> & v )
|
---|
570 | </h3>
|
---|
571 |
|
---|
572 | <p> Assigns <em>v</em> to this vector and returns a reference to this vector.
|
---|
573 | <p> All iterators of the current vector become invalidated by this
|
---|
574 | operation. The cost of such an assignment is O(1) since
|
---|
575 | QValueVector is <a href="shclass.html#implicitly-shared">implicitly shared</a>.
|
---|
576 |
|
---|
577 | <h3 class=fn><a href="qvaluevector.html">QValueVector</a><T> & <a name="operator-eq-2"></a>QValueVector::operator= ( const std::vector<T> & v )
|
---|
578 | </h3>
|
---|
579 |
|
---|
580 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
581 | <p> Assigns <em>v</em> to this vector and returns a reference to this vector.
|
---|
582 | <p> All iterators of the current vector become invalidated by this
|
---|
583 | operation. The cost of this assignment is O(n) since <em>v</em> is
|
---|
584 | copied.
|
---|
585 |
|
---|
586 | <h3 class=fn>bool <a name="operator-eq-eq"></a>QValueVector::operator== ( const <a href="qvaluevector.html">QValueVector</a><T> & x ) const
|
---|
587 | </h3>
|
---|
588 |
|
---|
589 | <p> Returns TRUE if each element in this vector equals each
|
---|
590 | corresponding element in <em>x</em>; otherwise returns FALSE.
|
---|
591 |
|
---|
592 | <h3 class=fn>bool <a name="operator-eq-eq-2"></a>QValueVector::operator== ( const <a href="qvaluevector.html">QValueVector</a><T> & x )
|
---|
593 | </h3>
|
---|
594 |
|
---|
595 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
596 | <p> Returns TRUE if each element in this vector equals each
|
---|
597 | corresponding element in <em>x</em>; otherwise returns FALSE.
|
---|
598 |
|
---|
599 | <h3 class=fn><a href="qvaluevector.html#reference">reference</a> <a name="operator[]"></a>QValueVector::operator[] ( <a href="qvaluevector.html#size_type">size_type</a> i )
|
---|
600 | </h3>
|
---|
601 |
|
---|
602 | <p> Returns a reference to the element at index <em>i</em>. If <em>i</em> is out
|
---|
603 | of range, this function has undefined behavior.
|
---|
604 | <p> <p>See also <a href="#at">at</a>().
|
---|
605 |
|
---|
606 | <h3 class=fn><a href="qvaluevector.html#const_reference">const_reference</a> <a name="operator[]-2"></a>QValueVector::operator[] ( <a href="qvaluevector.html#size_type">size_type</a> i ) const
|
---|
607 | </h3>
|
---|
608 |
|
---|
609 | <p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
610 | <p> Returns a const reference to the element at index <em>i</em>. If <em>i</em> is
|
---|
611 | out of range, this function has undefined behavior.
|
---|
612 | <p> <p>See also <a href="#at">at</a>().
|
---|
613 |
|
---|
614 | <h3 class=fn>void <a name="pop_back"></a>QValueVector::pop_back ()
|
---|
615 | </h3>
|
---|
616 |
|
---|
617 | <p> Removes the last item from the vector.
|
---|
618 | <p> This function is provided for STL compatibility.
|
---|
619 |
|
---|
620 | <h3 class=fn>void <a name="push_back"></a>QValueVector::push_back ( const T & x )
|
---|
621 | </h3>
|
---|
622 |
|
---|
623 | <p> Appends a copy of <em>x</em> to the end of the vector. This is the
|
---|
624 | fastest way to add new elements.
|
---|
625 | <p> This function is provided for STL compatibility. It is equivalent
|
---|
626 | to <a href="#append">append</a>().
|
---|
627 | <p> <p>See also <a href="#insert">insert</a>().
|
---|
628 |
|
---|
629 | <h3 class=fn>void <a name="reserve"></a>QValueVector::reserve ( <a href="qvaluevector.html#size_type">size_type</a> n )
|
---|
630 | </h3>
|
---|
631 |
|
---|
632 | <p> Increases the vector's capacity. If <em>n</em> is less than or equal to
|
---|
633 | <a href="#capacity">capacity</a>(), nothing happens. Otherwise, additional memory is
|
---|
634 | allocated so that capacity() will be increased to a value greater
|
---|
635 | than or equal to <em>n</em>. All iterators will then become invalidated.
|
---|
636 | Note that the vector's <a href="#size">size</a>() and the values of existing elements
|
---|
637 | remain unchanged.
|
---|
638 |
|
---|
639 | <h3 class=fn>void <a name="resize"></a>QValueVector::resize ( <a href="qvaluevector.html#size_type">size_type</a> n, const T & val = T ( ) )
|
---|
640 | </h3>
|
---|
641 |
|
---|
642 | <p> Changes the size of the vector to <em>n</em>. If <em>n</em> is greater than
|
---|
643 | the current <a href="#size">size</a>(), elements are added to the end and initialized
|
---|
644 | with the value of <em>val</em>. If <em>n</em> is less than size(), elements
|
---|
645 | are removed from the end. If <em>n</em> is equal to size() nothing
|
---|
646 | happens.
|
---|
647 |
|
---|
648 | <h3 class=fn><a href="qvaluevector.html#size_type">size_type</a> <a name="size"></a>QValueVector::size () const
|
---|
649 | </h3>
|
---|
650 |
|
---|
651 | <p> Returns the number of elements in the vector.
|
---|
652 | <p> This function is provided for STL compatibility. It is equivalent
|
---|
653 | to <a href="#count">count</a>().
|
---|
654 | <p> <p>See also <a href="#empty">empty</a>().
|
---|
655 |
|
---|
656 | <!-- eof -->
|
---|
657 | <hr><p>
|
---|
658 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
659 | Copyright © 1995-2007
|
---|
660 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
661 | <table width=100% cellspacing=0 border=0><tr>
|
---|
662 | <td>Copyright © 2007
|
---|
663 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
664 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
665 | </table></div></address></body>
|
---|
666 | </html>
|
---|