<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- /tmp/qt-4.2.1-harald-1161357942206/qt-x11-opensource-src-4.2.1/doc/src/q3ptrvector.qdoc --> <head> <title>Qt 4.2: Q3PtrVector Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td> <td width="1"> </td><td class="postheader" 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="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td> <td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">Q3PtrVector Class Reference<br /><sup><sup>[<a href="qt3support.html">Qt3Support</a> module]</sup></sup></h1> <p>The Q3PtrVector class is a template collection class that provides a vector (array). <a href="#details">More...</a></p> <pre> #include <Q3PtrVector></pre><p><b>This class is part of the Qt 3 support library.</b> It is provided to keep old source code working. We strongly advise against using it in new code. See <a href="porting4.html">Porting to Qt 4</a> for more information.</p> <p>Inherits <a href="q3ptrcollection.html">Q3PtrCollection</a>.</p> <ul> <li><a href="q3ptrvector-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-functions"></a> <h3>Public Functions</h3> <ul> <li><div class="fn"/><b><a href="q3ptrvector.html#Q3PtrVector">Q3PtrVector</a></b> ()</li> <li><div class="fn"/><b><a href="q3ptrvector.html#Q3PtrVector-2">Q3PtrVector</a></b> ( uint <i>size</i> )</li> <li><div class="fn"/><b><a href="q3ptrvector.html#Q3PtrVector-3">Q3PtrVector</a></b> ( const Q3PtrVector<type> & <i>v</i> )</li> <li><div class="fn"/><b><a href="q3ptrvector.html#dtor.Q3PtrVector">~Q3PtrVector</a></b> ()</li> <li><div class="fn"/>type * <b><a href="q3ptrvector.html#at">at</a></b> ( uint <i>i</i> ) const</li> <li><div class="fn"/>int <b><a href="q3ptrvector.html#bsearch">bsearch</a></b> ( const type * <i>d</i> ) const</li> <li><div class="fn"/>virtual void <b><a href="q3ptrvector.html#clear">clear</a></b> ()</li> <li><div class="fn"/>uint <b><a href="q3ptrvector.html#contains">contains</a></b> ( const type * <i>d</i> ) const</li> <li><div class="fn"/>uint <b><a href="q3ptrvector.html#containsRef">containsRef</a></b> ( const type * <i>d</i> ) const</li> <li><div class="fn"/>virtual uint <b><a href="q3ptrvector.html#count">count</a></b> () const</li> <li><div class="fn"/>type ** <b><a href="q3ptrvector.html#data">data</a></b> () const</li> <li><div class="fn"/>bool <b><a href="q3ptrvector.html#fill">fill</a></b> ( const type * <i>d</i>, int <i>size</i> = -1 )</li> <li><div class="fn"/>int <b><a href="q3ptrvector.html#find">find</a></b> ( const type * <i>d</i>, uint <i>i</i> = 0 ) const</li> <li><div class="fn"/>int <b><a href="q3ptrvector.html#findRef">findRef</a></b> ( const type * <i>d</i>, uint <i>i</i> = 0 ) const</li> <li><div class="fn"/>bool <b><a href="q3ptrvector.html#insert">insert</a></b> ( uint <i>i</i>, const type * <i>d</i> )</li> <li><div class="fn"/>bool <b><a href="q3ptrvector.html#isEmpty">isEmpty</a></b> () const</li> <li><div class="fn"/>bool <b><a href="q3ptrvector.html#isNull">isNull</a></b> () const</li> <li><div class="fn"/>bool <b><a href="q3ptrvector.html#remove">remove</a></b> ( uint <i>i</i> )</li> <li><div class="fn"/>bool <b><a href="q3ptrvector.html#resize">resize</a></b> ( uint <i>size</i> )</li> <li><div class="fn"/>uint <b><a href="q3ptrvector.html#size">size</a></b> () const</li> <li><div class="fn"/>void <b><a href="q3ptrvector.html#sort">sort</a></b> ()</li> <li><div class="fn"/>type * <b><a href="q3ptrvector.html#take">take</a></b> ( uint <i>i</i> )</li> <li><div class="fn"/>Q3PtrVector<type> & <b><a href="q3ptrvector.html#operator-eq">operator=</a></b> ( const Q3PtrVector<type> & <i>v</i> )</li> <li><div class="fn"/>bool <b><a href="q3ptrvector.html#operator-eq-eq">operator==</a></b> ( const Q3PtrVector<type> & <i>v</i> ) const</li> <li><div class="fn"/>type * <b><a href="q3ptrvector.html#operator-5b-5d">operator[]</a></b> ( int <i>i</i> ) const</li> </ul> <ul> <li><div class="fn"/>4 public functions inherited from <a href="q3ptrcollection.html#public-functions">Q3PtrCollection</a></li> </ul> <a name="protected-functions"></a> <h3>Protected Functions</h3> <ul> <li><div class="fn"/>virtual int <b><a href="q3ptrvector.html#compareItems">compareItems</a></b> ( Q3PtrCollection::Item <i>d1</i>, Q3PtrCollection::Item <i>d2</i> )</li> <li><div class="fn"/>virtual QDataStream & <b><a href="q3ptrvector.html#read">read</a></b> ( QDataStream & <i>s</i>, Q3PtrCollection::Item & <i>item</i> )</li> <li><div class="fn"/>virtual QDataStream & <b><a href="q3ptrvector.html#write">write</a></b> ( QDataStream & <i>s</i>, Q3PtrCollection::Item <i>item</i> ) const</li> </ul> <ul> <li><div class="fn"/>2 protected functions inherited from <a href="q3ptrcollection.html#protected-functions">Q3PtrCollection</a></li> </ul> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The Q3PtrVector class is a template collection class that provides a vector (array).</p> <p><a href="q3valuevector.html">Q3ValueVector</a> is an STL-compatible alternative to this class.</p> <p>Q3PtrVector is implemented as a template class. Defines a template instance Q3PtrVector<X> to create a vector that contains pointers to X (X*).</p> <p>A vector is the same as an array. The main difference between Q3PtrVector and <a href="q3memarray.html">Q3MemArray</a> is that Q3PtrVector stores pointers to the elements, whereas <a href="q3memarray.html">Q3MemArray</a> stores the elements themselves (i.e. <a href="q3memarray.html">Q3MemArray</a> is value-based and Q3PtrVector is pointer-based).</p> <p>Items are added to the vector using <a href="q3ptrvector.html#insert">insert</a>() or <a href="q3ptrvector.html#fill">fill</a>(). Items are removed with <a href="q3ptrvector.html#remove">remove</a>(). You can get a pointer to an item at a particular index position using <a href="q3ptrvector.html#at">at</a>().</p> <p>Unless otherwise stated, all functions that remove items from the vector will also delete the element pointed to if <a href="q3ptrcollection.html#setAutoDelete">auto-deletion</a> is enabled. By default, auto-deletion is disabled; see <a href="q3ptrcollection.html#setAutoDelete">setAutoDelete</a>(). This behavior can be changed in a subclass by reimplementing the virtual function <a href="q3ptrcollection.html#deleteItem">deleteItem</a>().</p> <p>Functions that compare items (<a href="q3ptrvector.html#find">find</a>() and <a href="q3ptrvector.html#sort">sort</a>() for example) will do so using the virtual function <a href="q3ptrvector.html#compareItems">compareItems</a>(). The default implementation of this function only compares the pointer values. Reimplement <a href="q3ptrvector.html#compareItems">compareItems</a>() 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="q3ptrvector.html#findRef">findRef</a>(), or a binary search (of a sorted vector) using <a href="q3ptrvector.html#bsearch">bsearch</a>(). You can count the number of times an item appears in the vector with <a href="q3ptrvector.html#contains">contains</a>() or <a href="q3ptrvector.html#containsRef">containsRef</a>().</p> <p>See also <a href="q3memarray.html">Q3MemArray</a>.</p> <hr /> <h2>Member Function Documentation</h2> <h3 class="fn"><a name="Q3PtrVector"></a>Q3PtrVector::Q3PtrVector ()</h3> <p>Constructs a null vector.</p> <p>See also <a href="q3ptrvector.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="Q3PtrVector-2"></a>Q3PtrVector::Q3PtrVector ( <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )</h3> <p>Constructs an vector with room for <i>size</i> items. Makes a null vector if <i>size</i> == 0.</p> <p>All <i>size</i> positions in the vector are initialized to 0.</p> <p>See also <a href="q3ptrvector.html#size">size</a>(), <a href="q3ptrvector.html#resize">resize</a>(), and <a href="q3ptrvector.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="Q3PtrVector-3"></a>Q3PtrVector::Q3PtrVector ( const Q3PtrVector<type> & <i>v</i> )</h3> <p>Constructs a copy of <i>v</i>. Only the pointers are copied (i.e. shallow copy).</p> <h3 class="fn"><a name="dtor.Q3PtrVector"></a>Q3PtrVector::~Q3PtrVector ()</h3> <p>Removes all items from the vector, and destroys the vector itself.</p> <p>See also <a href="q3ptrvector.html#clear">clear</a>().</p> <h3 class="fn"><a name="at"></a>type * Q3PtrVector::at ( <a href="qtglobal.html#uint-typedef">uint</a> <i>i</i> ) const</h3> <p>Returns the item at position <i>i</i>, or 0 if there is no item at that position. <i>i</i> must be less than <a href="q3ptrvector.html#size">size</a>().</p> <h3 class="fn"><a name="bsearch"></a>int Q3PtrVector::bsearch ( const type * <i>d</i> ) const</h3> <p>In a sorted array, finds the first occurrence of <i>d</i> using a binary search. For a sorted array, this is generally much faster than <a href="q3ptrvector.html#find">find</a>(), which performs a linear search.</p> <p>Returns the position of <i>d</i>, or -1 if <i>d</i> could not be found. <i>d</i> must not be 0.</p> <p>Compares items using the virtual function <a href="q3ptrvector.html#compareItems">compareItems</a>().</p> <p>See also <a href="q3ptrvector.html#sort">sort</a>() and <a href="q3ptrvector.html#find">find</a>().</p> <h3 class="fn"><a name="clear"></a>void Q3PtrVector::clear () <tt> [virtual]</tt></h3> <p>Removes all items from the vector, and destroys the vector itself.</p> <p>The vector becomes a null vector.</p> <p>Reimplemented from <a href="q3ptrcollection.html#clear">Q3PtrCollection</a>.</p> <p>See also <a href="q3ptrvector.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="compareItems"></a>int Q3PtrVector::compareItems ( <a href="q3ptrcollection.html#Item-typedef">Q3PtrCollection::Item</a> <i>d1</i>, <a href="q3ptrcollection.html#Item-typedef">Q3PtrCollection::Item</a> <i>d2</i> ) <tt> [virtual protected]</tt></h3> <p>This virtual function compares two list items.</p> <p>Returns:</p> <ul> <li>zero if <i>d1</i> == <i>d2</i></li> <li>nonzero if <i>d1</i> != <i>d2</i></li> </ul> <p>This function returns <i>int</i> rather than <i>bool</i> so that reimplementations can return one of three values and use it to sort by:</p> <ul> <li>0 if <i>d1</i> == <i>d2</i></li> <li>> 0 (positive integer) if <i>d1</i> > <i>d2</i></li> <li>< 0 (negative integer) if <i>d1</i> < <i>d2</i></li> </ul> <p>The <a href="q3ptrvector.html#sort">sort</a>() and <a href="q3ptrvector.html#bsearch">bsearch</a>() functions require compareItems() to be implemented as described here.</p> <p>This function should not modify the vector because some const functions call compareItems().</p> <h3 class="fn"><a name="contains"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3PtrVector::contains ( const type * <i>d</i> ) const</h3> <p>Returns the number of occurrences of item <i>d</i> in the vector.</p> <p>Compares items using the virtual function <a href="q3ptrvector.html#compareItems">compareItems</a>().</p> <p>See also <a href="q3ptrvector.html#containsRef">containsRef</a>().</p> <h3 class="fn"><a name="containsRef"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3PtrVector::containsRef ( const type * <i>d</i> ) const</h3> <p>Returns the number of occurrences of the item pointer <i>d</i> in the vector.</p> <p>This function does <i>not</i> use <a href="q3ptrvector.html#compareItems">compareItems</a>() to compare items.</p> <p>See also <a href="q3ptrvector.html#findRef">findRef</a>().</p> <h3 class="fn"><a name="count"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3PtrVector::count () const <tt> [virtual]</tt></h3> <p>Returns the number of items in the vector. The vector is empty if count() == 0.</p> <p>Reimplemented from <a href="q3ptrcollection.html#count">Q3PtrCollection</a>.</p> <p>See also <a href="q3ptrvector.html#isEmpty">isEmpty</a>(), <a href="q3ptrvector.html#size">size</a>(), and <a href="q3ptrvector.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="data"></a>type ** Q3PtrVector::data () const</h3> <p>Returns a pointer to the actual vector data, which is an array of type*.</p> <p>The vector is a null vector if data() == 0 (null pointer).</p> <p>See also <a href="q3ptrvector.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="fill"></a>bool Q3PtrVector::fill ( const type * <i>d</i>, int <i>size</i> = -1 )</h3> <p>Inserts item <i>d</i> in all positions in the vector. Any existing items are removed. If <i>d</i> is 0, the vector becomes empty.</p> <p>If <i>size</i> >= 0, the vector is first resized to <i>size</i>. By default, <i>size</i> is -1.</p> <p>Returns TRUE if successful, i.e. <i>size</i> is the same as the current size, or <i>size</i> is larger and the memory has successfully been allocated; otherwise returns FALSE.</p> <p>See also <a href="q3ptrvector.html#resize">resize</a>(), <a href="q3ptrvector.html#insert">insert</a>(), and <a href="q3ptrvector.html#isEmpty">isEmpty</a>().</p> <h3 class="fn"><a name="find"></a>int Q3PtrVector::find ( const type * <i>d</i>, <a href="qtglobal.html#uint-typedef">uint</a> <i>i</i> = 0 ) const</h3> <p>Finds the first occurrence of item <i>d</i> in the vector using a linear search. The search starts at position <i>i</i>, which must be less than <a href="q3ptrvector.html#size">size</a>(). <i>i</i> is by default 0; i.e. the search starts at the start of the vector.</p> <p>Returns the position of <i>d</i>, or -1 if <i>d</i> could not be found.</p> <p>Compares items using the virtual function <a href="q3ptrvector.html#compareItems">compareItems</a>().</p> <p>Use the much faster <a href="q3ptrvector.html#bsearch">bsearch</a>() to search a sorted vector.</p> <p>See also <a href="q3ptrvector.html#findRef">findRef</a>() and <a href="q3ptrvector.html#bsearch">bsearch</a>().</p> <h3 class="fn"><a name="findRef"></a>int Q3PtrVector::findRef ( const type * <i>d</i>, <a href="qtglobal.html#uint-typedef">uint</a> <i>i</i> = 0 ) const</h3> <p>Finds the first occurrence of the item pointer <i>d</i> in the vector using a linear search. The search starts at position <i>i</i>, which must be less than <a href="q3ptrvector.html#size">size</a>(). <i>i</i> is by default 0; i.e. the search starts at the start of the vector.</p> <p>Returns the position of <i>d</i>, or -1 if <i>d</i> could not be found.</p> <p>This function does <i>not</i> use <a href="q3ptrvector.html#compareItems">compareItems</a>() to compare items.</p> <p>Use the much faster <a href="q3ptrvector.html#bsearch">bsearch</a>() to search a sorted vector.</p> <p>See also <a href="q3ptrvector.html#find">find</a>() and <a href="q3ptrvector.html#bsearch">bsearch</a>().</p> <h3 class="fn"><a name="insert"></a>bool Q3PtrVector::insert ( <a href="qtglobal.html#uint-typedef">uint</a> <i>i</i>, const type * <i>d</i> )</h3> <p>Sets position <i>i</i> in the vector to contain the item <i>d</i>. <i>i</i> must be less than <a href="q3ptrvector.html#size">size</a>(). Any previous element in position <i>i</i> is removed.</p> <p>See also <a href="q3ptrvector.html#at">at</a>().</p> <h3 class="fn"><a name="isEmpty"></a>bool Q3PtrVector::isEmpty () const</h3> <p>Returns TRUE if the vector is empty; otherwise returns FALSE.</p> <p>See also <a href="q3ptrvector.html#count">count</a>().</p> <h3 class="fn"><a name="isNull"></a>bool Q3PtrVector::isNull () const</h3> <p>Returns TRUE if the vector is null; otherwise returns FALSE.</p> <p>A null vector has <a href="q3ptrvector.html#size">size</a>() == 0 and <a href="q3ptrvector.html#data">data</a>() == 0.</p> <p>See also <a href="q3ptrvector.html#size">size</a>().</p> <h3 class="fn"><a name="read"></a><a href="qdatastream.html">QDataStream</a> & Q3PtrVector::read ( <a href="qdatastream.html">QDataStream</a> & <i>s</i>, <a href="q3ptrcollection.html#Item-typedef">Q3PtrCollection::Item</a> & <i>item</i> ) <tt> [virtual protected]</tt></h3> <p>Reads a vector item, <i>item</i>, from the stream <i>s</i> and returns a reference to the stream.</p> <p>The default implementation sets <i>item</i> to 0.</p> <p>See also <a href="q3ptrvector.html#write">write</a>().</p> <h3 class="fn"><a name="remove"></a>bool Q3PtrVector::remove ( <a href="qtglobal.html#uint-typedef">uint</a> <i>i</i> )</h3> <p>Removes the item at position <i>i</i> in the vector, if there is one. <i>i</i> must be less than <a href="q3ptrvector.html#size">size</a>().</p> <p>Returns TRUE if <i>i</i> is within range; otherwise returns FALSE.</p> <p>See also <a href="q3ptrvector.html#take">take</a>() and <a href="q3ptrvector.html#at">at</a>().</p> <h3 class="fn"><a name="resize"></a>bool Q3PtrVector::resize ( <a href="qtglobal.html#uint-typedef">uint</a> <i>size</i> )</h3> <p>Resizes (expands or shrinks) the vector to <i>size</i> elements. The vector becomes a null vector if <i>size</i> == 0.</p> <p>Any items at position <i>size</i> or beyond in the vector are removed. New positions are initialized to 0.</p> <p>Returns TRUE if successful, i.e. if the memory was successfully allocated; otherwise returns FALSE.</p> <p>See also <a href="q3ptrvector.html#size">size</a>() and <a href="q3ptrvector.html#isNull">isNull</a>().</p> <h3 class="fn"><a name="size"></a><a href="qtglobal.html#uint-typedef">uint</a> Q3PtrVector::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> <p>The vector is a null vector if size() == 0.</p> <p>See also <a href="q3ptrvector.html#isNull">isNull</a>(), <a href="q3ptrvector.html#resize">resize</a>(), and <a href="q3ptrvector.html#count">count</a>().</p> <h3 class="fn"><a name="sort"></a>void Q3PtrVector::sort ()</h3> <p>Sorts the items in ascending order. Any empty positions will be put last.</p> <p>Compares items using the virtual function <a href="q3ptrvector.html#compareItems">compareItems</a>().</p> <p>See also <a href="q3ptrvector.html#bsearch">bsearch</a>().</p> <h3 class="fn"><a name="take"></a>type * Q3PtrVector::take ( <a href="qtglobal.html#uint-typedef">uint</a> <i>i</i> )</h3> <p>Returns the item at position <i>i</i> in the vector, and removes that item from the vector. <i>i</i> must be less than <a href="q3ptrvector.html#size">size</a>(). If there is no item at position <i>i</i>, 0 is returned.</p> <p>Unlike <a href="q3ptrvector.html#remove">remove</a>(), this function does <i>not</i> call <a href="q3ptrcollection.html#deleteItem">deleteItem</a>() for the removed item.</p> <p>See also <a href="q3ptrvector.html#remove">remove</a>() and <a href="q3ptrvector.html#at">at</a>().</p> <h3 class="fn"><a name="write"></a><a href="qdatastream.html">QDataStream</a> & Q3PtrVector::write ( <a href="qdatastream.html">QDataStream</a> & <i>s</i>, <a href="q3ptrcollection.html#Item-typedef">Q3PtrCollection::Item</a> <i>item</i> ) const <tt> [virtual protected]</tt></h3> <p>Writes a vector item, <i>item</i>, to the stream <i>s</i> and returns a reference to the stream.</p> <p>The default implementation does nothing.</p> <p>See also <a href="q3ptrvector.html#read">read</a>().</p> <h3 class="fn"><a name="operator-eq"></a>Q3PtrVector<type> & Q3PtrVector::operator= ( const Q3PtrVector<type> & <i>v</i> )</h3> <p>Assigns <i>v</i> to this vector and returns a reference to this vector.</p> <p>This vector is first cleared and then all the items from <i>v</i> are copied into the vector. Only the pointers are copied (i.e. shallow copy).</p> <p>See also <a href="q3ptrvector.html#clear">clear</a>().</p> <h3 class="fn"><a name="operator-eq-eq"></a>bool Q3PtrVector::operator== ( const Q3PtrVector<type> & <i>v</i> ) const</h3> <p>Returns TRUE if this vector and <i>v</i> are equal; otherwise returns FALSE.</p> <h3 class="fn"><a name="operator-5b-5d"></a>type * Q3PtrVector::operator[] ( int <i>i</i> ) const</h3> <p>Returns the item at position <i>i</i>, or 0 if there is no item at that position. <i>i</i> must be less than <a href="q3ptrvector.html#size">size</a>().</p> <p>Equivalent to at( <i>i</i> ).</p> <p>See also <a href="q3ptrvector.html#at">at</a>().</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td width="30%">Copyright © 2006 <a href="trolltech.html">Trolltech</a></td> <td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="30%" align="right"><div align="right">Qt 4.2.1</div></td> </tr></table></div></address></body> </html>