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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/harald/tmp/qt-3.3.7-harald-4508/qt-x11-free-3.3.7/doc/qptrvector.doc:41 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QPtrVector Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QPtrVector Class Reference</h1>
<p>The QPtrVector class is a template collection class that
provides a vector (array).
<a href="#details">More...</a>
<p><tt>#include <<a href="qptrvector-h.html">qptrvector.h</a>></tt>
<p>Inherits <a href="qptrcollection.html">QPtrCollection</a>.
<p><a href="qptrvector-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QPtrVector"><b>QPtrVector</b></a> ()</li>
<li class=fn><a href="#QPtrVector-2"><b>QPtrVector</b></a> ( uint size )</li>
<li class=fn><a href="#QPtrVector-3"><b>QPtrVector</b></a> ( const QPtrVector<type> & v )</li>
<li class=fn><a href="#~QPtrVector"><b>~QPtrVector</b></a> ()</li>
<li class=fn>QPtrVector<type> & <a href="#operator-eq"><b>operator=</b></a> ( const QPtrVector<type> & v )</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QPtrVector<type> & v ) const</li>
<li class=fn>type ** <a href="#data"><b>data</b></a> () const</li>
<li class=fn>uint <a href="#size"><b>size</b></a> () const</li>
<li class=fn>virtual uint <a href="#count"><b>count</b></a> () const</li>
<li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
<li class=fn>bool <a href="#resize"><b>resize</b></a> ( uint size )</li>
<li class=fn>bool <a href="#insert"><b>insert</b></a> ( uint i, const type * d )</li>
<li class=fn>bool <a href="#remove"><b>remove</b></a> ( uint i )</li>
<li class=fn>type * <a href="#take"><b>take</b></a> ( uint i )</li>
<li class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</li>
<li class=fn>bool <a href="#fill"><b>fill</b></a> ( const type * d, int size = -1 )</li>
<li class=fn>void <a href="#sort"><b>sort</b></a> ()</li>
<li class=fn>int <a href="#bsearch"><b>bsearch</b></a> ( const type * d ) const</li>
<li class=fn>int <a href="#findRef"><b>findRef</b></a> ( const type * d, uint i = 0 ) const</li>
<li class=fn>int <a href="#find"><b>find</b></a> ( const type * d, uint i = 0 ) const</li>
<li class=fn>uint <a href="#containsRef"><b>containsRef</b></a> ( const type * d ) const</li>
<li class=fn>uint <a href="#contains"><b>contains</b></a> ( const type * d ) const</li>
<li class=fn>type * <a href="#operator[]"><b>operator[]</b></a> ( int i ) const</li>
<li class=fn>type * <a href="#at"><b>at</b></a> ( uint i ) const</li>
</ul>
<h2>Important Inherited Members</h2>
<ul>
<li class=fn>bool <a href="#autoDelete"><b>autoDelete</b></a> () const</li>
<li class=fn>void <a href="#setAutoDelete"><b>setAutoDelete</b></a> ( bool enable )</li>
</ul>
<h2>Protected Members</h2>
<ul>
<li class=fn>virtual int <a href="#compareItems"><b>compareItems</b></a> ( QPtrCollection::Item d1, QPtrCollection::Item d2 )</li>
<li class=fn>virtual QDataStream & <a href="#read"><b>read</b></a> ( QDataStream & s, QPtrCollection::Item & item )</li>
<li class=fn>virtual QDataStream & <a href="#write"><b>write</b></a> ( QDataStream & s, QPtrCollection::Item item ) const</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The QPtrVector class is a template collection class that
provides a vector (array).
<p>
<p>
<p> <a href="qvaluevector.html">QValueVector</a> is an STL-compatible alternative to this class.
<p> QPtrVector is implemented as a template class. Defines a template
instance QPtrVector<X> to create a vector that contains pointers
to X (X*).
<p> A vector is the same as an array. The main difference between
QPtrVector and <a href="qmemarray.html">QMemArray</a> 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).
<p> Items are added to the vector using <a href="#insert">insert</a>() or <a href="#fill">fill</a>(). Items are
removed with <a href="#remove">remove</a>(). You can get a pointer to an item at a
particular index position using <a href="#at">at</a>().
<p> Unless otherwise stated, all functions that remove items from the
vector will also delete the element pointed to if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled. By default,
auto-deletion is disabled; see <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(). This behaviour can
be changed in a subclass by reimplementing the virtual function
<a href="qptrcollection.html#deleteItem">deleteItem</a>().
<p> Functions that compare items (<a href="#find">find</a>() and <a href="#sort">sort</a>() for example) will
do so using the virtual function <a href="#compareItems">compareItems</a>(). 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 <a href="#findRef">findRef</a>(), or a binary
search (of a sorted vector) using <a href="#bsearch">bsearch</a>(). You can count the
number of times an item appears in the vector with <a href="#contains">contains</a>() or
<a href="#containsRef">containsRef</a>().
<p> <p>See also <a href="qmemarray.html">QMemArray</a> and <a href="tools.html">Non-GUI Classes</a>.
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QPtrVector"></a>QPtrVector::QPtrVector ()
</h3>
<p> Constructs a null vector.
<p> <p>See also <a href="#isNull">isNull</a>().
<h3 class=fn><a name="QPtrVector-2"></a>QPtrVector::QPtrVector ( uint size )
</h3>
<p> Constructs an vector with room for <em>size</em> items. Makes a null
vector if <em>size</em> == 0.
<p> All <em>size</em> positions in the vector are initialized to 0.
<p> <p>See also <a href="#size">size</a>(), <a href="#resize">resize</a>(), and <a href="#isNull">isNull</a>().
<h3 class=fn><a name="QPtrVector-3"></a>QPtrVector::QPtrVector ( const <a href="qptrvector.html">QPtrVector</a><type> & v )
</h3>
<p> Constructs a copy of <em>v</em>. Only the pointers are copied (i.e.
<a href="shclass.html#shallow-copy">shallow copy</a>).
<h3 class=fn><a name="~QPtrVector"></a>QPtrVector::~QPtrVector ()
</h3>
<p> Removes all items from the vector, and destroys the vector itself.
<p> <p>See also <a href="#clear">clear</a>().
<h3 class=fn>type * <a name="at"></a>QPtrVector::at ( uint i ) const
</h3>
<p> Returns the item at position <em>i</em>, or 0 if there is no item at
that position. <em>i</em> must be less than <a href="#size">size</a>().
<h3 class=fn>bool <a name="autoDelete"></a>QPtrCollection::autoDelete () const
</h3>
<p> Returns the setting of the auto-delete option. The default is FALSE.
<p> <p>See also <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
<h3 class=fn>int <a name="bsearch"></a>QPtrVector::bsearch ( const type * d ) const
</h3>
<p> In a sorted array, finds the first occurrence of <em>d</em> using a
binary search. For a sorted array, this is generally much faster
than <a href="#find">find</a>(), which performs a linear search.
<p> Returns the position of <em>d</em>, or -1 if <em>d</em> could not be found. <em>d</em> must not be 0.
<p> Compares items using the virtual function <a href="#compareItems">compareItems</a>().
<p> <p>See also <a href="#sort">sort</a>() and <a href="#find">find</a>().
<h3 class=fn>void <a name="clear"></a>QPtrVector::clear ()<tt> [virtual]</tt>
</h3>
<p> Removes all items from the vector, and destroys the vector itself.
<p> The vector becomes a null vector.
<p> <p>See also <a href="#isNull">isNull</a>().
<p>Reimplemented from <a href="qptrcollection.html#clear">QPtrCollection</a>.
<h3 class=fn>int <a name="compareItems"></a>QPtrVector::compareItems ( <a href="qptrcollection.html#Item">QPtrCollection::Item</a> d1, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> d2 )<tt> [virtual protected]</tt>
</h3>
<p> This virtual function compares two list items.
<p> Returns:
<ul>
<li> zero if <em>d1</em> == <em>d2</em>
<li> nonzero if <em>d1</em> != <em>d2</em>
</ul>
<p> This function returns <em>int</em> rather than <em>bool</em> so that
reimplementations can return one of three values and use it to
sort by:
<ul>
<li> 0 if <em>d1</em> == <em>d2</em>
<li> > 0 (positive integer) if <em>d1</em> > <em>d2</em>
<li> < 0 (negative integer) if <em>d1</em> < <em>d2</em>
</ul>
<p> The <a href="#sort">sort</a>() and <a href="#bsearch">bsearch</a>() functions require <a href="#compareItems">compareItems</a>() to be
implemented as described here.
<p> This function should not modify the vector because some const
functions call compareItems().
<h3 class=fn>uint <a name="contains"></a>QPtrVector::contains ( const type * d ) const
</h3>
<p> Returns the number of occurrences of item <em>d</em> in the vector.
<p> Compares items using the virtual function <a href="#compareItems">compareItems</a>().
<p> <p>See also <a href="#containsRef">containsRef</a>().
<h3 class=fn>uint <a name="containsRef"></a>QPtrVector::containsRef ( const type * d ) const
</h3>
<p> Returns the number of occurrences of the item pointer <em>d</em> in the
vector.
<p> This function does <em>not</em> use <a href="#compareItems">compareItems</a>() to compare items.
<p> <p>See also <a href="#findRef">findRef</a>().
<h3 class=fn>uint <a name="count"></a>QPtrVector::count () const<tt> [virtual]</tt>
</h3>
<p> Returns the number of items in the vector. The vector is empty if
<a href="#count">count</a>() == 0.
<p> <p>See also <a href="#isEmpty">isEmpty</a>(), <a href="#size">size</a>(), and <a href="#isNull">isNull</a>().
<p>Reimplemented from <a href="qptrcollection.html#count">QPtrCollection</a>.
<h3 class=fn>type ** <a name="data"></a>QPtrVector::data () const
</h3>
<p> Returns a pointer to the actual vector data, which is an array of
type*.
<p> The vector is a null vector if <a href="#data">data</a>() == 0 (null pointer).
<p> <p>See also <a href="#isNull">isNull</a>().
<h3 class=fn>bool <a name="fill"></a>QPtrVector::fill ( const type * d, int size = -1 )
</h3>
<p> Inserts item <em>d</em> in all positions in the vector. Any existing
items are removed. If <em>d</em> is 0, the vector becomes empty.
<p> If <em>size</em> >= 0, the vector is first resized to <em>size</em>. By
default, <em>size</em> is -1.
<p> Returns TRUE if successful, i.e. <em>size</em> is the same as the
current size, or <em>size</em> is larger and the memory has successfully
been allocated; otherwise returns FALSE.
<p> <p>See also <a href="#resize">resize</a>(), <a href="#insert">insert</a>(), and <a href="#isEmpty">isEmpty</a>().
<h3 class=fn>int <a name="find"></a>QPtrVector::find ( const type * d, uint i = 0 ) const
</h3>
<p> Finds the first occurrence of item <em>d</em> in the vector using a
linear search. The search starts at position <em>i</em>, which must be
less than <a href="#size">size</a>(). <em>i</em> is by default 0; i.e. the search starts at
the start of the vector.
<p> Returns the position of <em>d</em>, or -1 if <em>d</em> could not be found.
<p> Compares items using the virtual function <a href="#compareItems">compareItems</a>().
<p> Use the much faster <a href="#bsearch">bsearch</a>() to search a sorted vector.
<p> <p>See also <a href="#findRef">findRef</a>() and <a href="#bsearch">bsearch</a>().
<h3 class=fn>int <a name="findRef"></a>QPtrVector::findRef ( const type * d, uint i = 0 ) const
</h3>
<p> Finds the first occurrence of the item pointer <em>d</em> in the vector
using a linear search. The search starts at position <em>i</em>, which
must be less than <a href="#size">size</a>(). <em>i</em> is by default 0; i.e. the search
starts at the start of the vector.
<p> Returns the position of <em>d</em>, or -1 if <em>d</em> could not be found.
<p> This function does <em>not</em> use <a href="#compareItems">compareItems</a>() to compare items.
<p> Use the much faster <a href="#bsearch">bsearch</a>() to search a sorted vector.
<p> <p>See also <a href="#find">find</a>() and <a href="#bsearch">bsearch</a>().
<h3 class=fn>bool <a name="insert"></a>QPtrVector::insert ( uint i, const type * d )
</h3>
<p> Sets position <em>i</em> in the vector to contain the item <em>d</em>. <em>i</em>
must be less than <a href="#size">size</a>(). Any previous element in position <em>i</em> is
removed.
<p> <p>See also <a href="#at">at</a>().
<h3 class=fn>bool <a name="isEmpty"></a>QPtrVector::isEmpty () const
</h3>
<p> Returns TRUE if the vector is empty; otherwise returns FALSE.
<p> <p>See also <a href="#count">count</a>().
<h3 class=fn>bool <a name="isNull"></a>QPtrVector::isNull () const
</h3>
<p> Returns TRUE if the vector is null; otherwise returns FALSE.
<p> A null vector has <a href="#size">size</a>() == 0 and <a href="#data">data</a>() == 0.
<p> <p>See also <a href="#size">size</a>().
<h3 class=fn><a href="qptrvector.html">QPtrVector</a><type> & <a name="operator-eq"></a>QPtrVector::operator= ( const <a href="qptrvector.html">QPtrVector</a><type> & v )
</h3>
<p> Assigns <em>v</em> to this vector and returns a reference to this
vector.
<p> This vector is first cleared and then all the items from <em>v</em> are
copied into the vector. Only the pointers are copied (i.e. <a href="shclass.html#shallow-copy">shallow copy</a>).
<p> <p>See also <a href="#clear">clear</a>().
<h3 class=fn>bool <a name="operator-eq-eq"></a>QPtrVector::operator== ( const <a href="qptrvector.html">QPtrVector</a><type> & v ) const
</h3>
<p> Returns TRUE if this vector and <em>v</em> are equal; otherwise returns
FALSE.
<h3 class=fn>type * <a name="operator[]"></a>QPtrVector::operator[] ( int i ) const
</h3>
<p> Returns the item at position <em>i</em>, or 0 if there is no item at
that position. <em>i</em> must be less than <a href="#size">size</a>().
<p> Equivalent to <a href="#at">at</a>( <em>i</em> ).
<p> <p>See also <a href="#at">at</a>().
<h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="read"></a>QPtrVector::read ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> & item )<tt> [virtual protected]</tt>
</h3>
<p> Reads a vector item, <em>item</em>, from the stream <em>s</em> and returns a
reference to the stream.
<p> The default implementation sets <em>item</em> to 0.
<p> <p>See also <a href="#write">write</a>().
<h3 class=fn>bool <a name="remove"></a>QPtrVector::remove ( uint i )
</h3>
<p> Removes the item at position <em>i</em> in the vector, if there is one.
<em>i</em> must be less than <a href="#size">size</a>().
<p> Returns TRUE if <em>i</em> is within range; otherwise returns FALSE.
<p> <p>See also <a href="#take">take</a>() and <a href="#at">at</a>().
<h3 class=fn>bool <a name="resize"></a>QPtrVector::resize ( uint size )
</h3>
<p> Resizes (expands or shrinks) the vector to <em>size</em> elements. The
vector becomes a null vector if <em>size</em> == 0.
<p> Any items at position <em>size</em> or beyond in the vector are removed.
New positions are initialized to 0.
<p> Returns TRUE if successful, i.e. if the memory was successfully
allocated; otherwise returns FALSE.
<p> <p>See also <a href="#size">size</a>() and <a href="#isNull">isNull</a>().
<h3 class=fn>void <a name="setAutoDelete"></a>QPtrCollection::setAutoDelete ( bool enable )
</h3>
<p> Sets the collection to auto-delete its contents if <em>enable</em> is
TRUE and to never delete them if <em>enable</em> is FALSE.
<p> 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.
<p> 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.
<p> Note that the auto-delete setting may also affect other functions
in subclasses. For example, a subclass that has a <a href="#remove">remove</a>()
function will remove the item from its data structure, and if
auto-delete is enabled, will also delete the item.
<p> <p>See also <a href="qptrcollection.html#autoDelete">autoDelete</a>().
<p>Examples: <a href="grapher-nsplugin-example.html#x2770">grapher/grapher.cpp</a>, <a href="scribble-example.html#x924">scribble/scribble.cpp</a>, and <a href="bigtable-example.html#x1582">table/bigtable/main.cpp</a>.
<h3 class=fn>uint <a name="size"></a>QPtrVector::size () const
</h3>
<p> 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.
<p> The vector is a null vector if <a href="#size">size</a>() == 0.
<p> <p>See also <a href="#isNull">isNull</a>(), <a href="#resize">resize</a>(), and <a href="#count">count</a>().
<h3 class=fn>void <a name="sort"></a>QPtrVector::sort ()
</h3>
<p> Sorts the items in ascending order. Any empty positions will be
put last.
<p> Compares items using the virtual function <a href="#compareItems">compareItems</a>().
<p> <p>See also <a href="#bsearch">bsearch</a>().
<h3 class=fn>type * <a name="take"></a>QPtrVector::take ( uint i )
</h3>
<p> Returns the item at position <em>i</em> in the vector, and removes that
item from the vector. <em>i</em> must be less than <a href="#size">size</a>(). If there is
no item at position <em>i</em>, 0 is returned.
<p> Unlike <a href="#remove">remove</a>(), this function does <em>not</em> call <a href="qptrcollection.html#deleteItem">deleteItem</a>() for
the removed item.
<p> <p>See also <a href="#remove">remove</a>() and <a href="#at">at</a>().
<h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="write"></a>QPtrVector::write ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> item ) const<tt> [virtual protected]</tt>
</h3>
<p> Writes a vector item, <em>item</em>, to the stream <em>s</em> and returns a
reference to the stream.
<p> The default implementation does nothing.
<p> <p>See also <a href="#read">read</a>().
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright © 1995-2005
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright © 2005
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.7</div>
</table></div></address></body>
</html>
|