source: trunk/doc/html/qptrlistiterator.html

Last change on this file was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 10.4 KB
Line 
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/qptrlist.doc:840 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QPtrListIterator Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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>QPtrListIterator Class Reference</h1>
33
34<p>The QPtrListIterator class provides an iterator for
35QPtrList collections.
36<a href="#details">More...</a>
37<p><tt>#include &lt;<a href="qptrlist-h.html">qptrlist.h</a>&gt;</tt>
38<p>Inherited by <a href="qobjectlistiterator.html">QObjectListIterator</a> and <a href="qstrlistiterator.html">QStrListIterator</a>.
39<p><a href="qptrlistiterator-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn><a href="#QPtrListIterator"><b>QPtrListIterator</b></a> ( const&nbsp;QPtrList&lt;type&gt;&nbsp;&amp;&nbsp;list )</li>
43<li class=fn><a href="#~QPtrListIterator"><b>~QPtrListIterator</b></a> ()</li>
44<li class=fn>uint <a href="#count"><b>count</b></a> () const</li>
45<li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
46<li class=fn>bool <a href="#atFirst"><b>atFirst</b></a> () const</li>
47<li class=fn>bool <a href="#atLast"><b>atLast</b></a> () const</li>
48<li class=fn>type * <a href="#toFirst"><b>toFirst</b></a> ()</li>
49<li class=fn>type * <a href="#toLast"><b>toLast</b></a> ()</li>
50<li class=fn><a href="#operator-type-*"><b>operator type *</b></a> () const</li>
51<li class=fn>type * <a href="#operator*"><b>operator*</b></a> ()</li>
52<li class=fn>type * <a href="#current"><b>current</b></a> () const</li>
53<li class=fn>type * <a href="#operator()"><b>operator()</b></a> ()</li>
54<li class=fn>type * <a href="#operator++"><b>operator++</b></a> ()</li>
55<li class=fn>type * <a href="#operator+-eq"><b>operator+=</b></a> ( uint&nbsp;jump )</li>
56<li class=fn>type * <a href="#operator--"><b>operator--</b></a> ()</li>
57<li class=fn>type * <a href="#operator--eq"><b>operator-=</b></a> ( uint&nbsp;jump )</li>
58<li class=fn>QPtrListIterator&lt;type&gt; &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QPtrListIterator&lt;type&gt;&nbsp;&amp;&nbsp;it )</li>
59</ul>
60<hr><a name="details"></a><h2>Detailed Description</h2>
61
62
63The QPtrListIterator class provides an iterator for
64<a href="qptrlist.html">QPtrList</a> collections.
65<p>
66
67<p> Define a template instance QPtrListIterator&lt;X&gt; to create a list
68iterator that operates on QPtrList&lt;X&gt; (list of X*).
69<p> The following example is similar to the <a href="qptrlist.html#example">example in the QPtrList class documentation</a>, but it uses QPtrListIterator. The class Employee is
70defined there.
71<p> <pre>
72 <a href="qptrlist.html">QPtrList</a>&lt;Employee&gt; list;
73
74 list.<a href="qptrlist.html#append">append</a>( new Employee("John", "Doe", 50000) );
75 list.<a href="qptrlist.html#append">append</a>( new Employee("Jane", "Williams", 80000) );
76 list.<a href="qptrlist.html#append">append</a>( new Employee("Tom", "Jones", 60000) );
77
78 QPtrListIterator&lt;Employee&gt; it( list );
79 Employee *employee;
80 while ( (employee = it.<a href="#current">current</a>()) != 0 ) {
81 ++it;
82 cout &lt;&lt; employee-&gt;surname().latin1() &lt;&lt; ", " &lt;&lt;
83 employee-&gt;forename().latin1() &lt;&lt; " earns " &lt;&lt;
84 employee-&gt;salary() &lt;&lt; endl;
85 }
86 </pre>
87
88<p> The output is
89<pre>
90 Doe, John earns 50000
91 Williams, Jane earns 80000
92 Jones, Tom earns 60000
93 </pre>
94
95<p> Using a list iterator is a more robust way of traversing the list
96than using the <a href="qptrlist.html">QPtrList</a> member functions <a href="qptrlist.html#first">first</a>(), <a href="qptrlist.html#next">next</a>(), <a href="qptrlist.html#current">current</a>(), etc., as many iterators can
97traverse the same list independently.
98<p> An iterator has its own current list item and can get the next and
99previous list items. It doesn't modify the list in any way.
100<p> When an item is removed from the list, all iterators that point to
101that item are updated to point to <a href="qptrlist.html#current">QPtrList::current</a>() instead to
102avoid dangling references.
103<p> <p>See also <a href="qptrlist.html">QPtrList</a>, <a href="collection.html">Collection Classes</a>, and <a href="tools.html">Non-GUI Classes</a>.
104
105<hr><h2>Member Function Documentation</h2>
106<h3 class=fn><a name="QPtrListIterator"></a>QPtrListIterator::QPtrListIterator ( const&nbsp;<a href="qptrlist.html">QPtrList</a>&lt;type&gt;&nbsp;&amp;&nbsp;list )
107</h3>
108
109<p> Constructs an iterator for <em>list</em>. The current iterator item is
110set to point on the first item in the <em>list</em>.
111
112<h3 class=fn><a name="~QPtrListIterator"></a>QPtrListIterator::~QPtrListIterator ()
113</h3>
114
115<p> Destroys the iterator.
116
117<h3 class=fn>bool <a name="atFirst"></a>QPtrListIterator::atFirst () const
118</h3>
119
120<p> Returns TRUE if the current iterator item is the first list item;
121otherwise returns FALSE.
122<p> <p>See also <a href="#toFirst">toFirst</a>() and <a href="#atLast">atLast</a>().
123
124<h3 class=fn>bool <a name="atLast"></a>QPtrListIterator::atLast () const
125</h3>
126
127<p> Returns TRUE if the current iterator item is the last list item;
128otherwise returns FALSE.
129<p> <p>See also <a href="#toLast">toLast</a>() and <a href="#atFirst">atFirst</a>().
130
131<h3 class=fn>uint <a name="count"></a>QPtrListIterator::count () const
132</h3>
133
134<p> Returns the number of items in the list this iterator operates on.
135<p> <p>See also <a href="#isEmpty">isEmpty</a>().
136
137<p>Example: <a href="customlayout-example.html#x1522">customlayout/card.cpp</a>.
138<h3 class=fn>type * <a name="current"></a>QPtrListIterator::current () const
139</h3>
140
141<p> Returns a pointer to the current iterator item. If the iterator is
142positioned before the first item in the list or after the last
143item in the list, 0 is returned.
144
145<p>Examples: <a href="canvas-example.html#x2949">canvas/canvas.cpp</a>, <a href="customlayout-example.html#x1523">customlayout/card.cpp</a>, and <a href="customlayout-example.html#x1481">customlayout/flow.cpp</a>.
146<h3 class=fn>bool <a name="isEmpty"></a>QPtrListIterator::isEmpty () const
147</h3>
148
149<p> Returns TRUE if the list is empty; otherwise returns FALSE.
150<p> <p>See also <a href="#count">count</a>().
151
152<h3 class=fn><a name="operator-type-*"></a>QPtrListIterator::operator type * () const
153</h3>
154
155<p> Cast operator. Returns a pointer to the current iterator item.
156Same as <a href="#current">current</a>().
157
158<h3 class=fn>type * <a name="operator()"></a>QPtrListIterator::operator() ()
159</h3>
160
161<p> Makes the succeeding item current and returns the original current
162item.
163<p> If the current iterator item was the last item in the list or if
164it was 0, 0 is returned.
165
166<h3 class=fn>type * <a name="operator*"></a>QPtrListIterator::operator* ()
167</h3>
168
169<p> Asterisk operator. Returns a pointer to the current iterator item.
170Same as <a href="#current">current</a>().
171
172<h3 class=fn>type * <a name="operator++"></a>QPtrListIterator::operator++ ()
173</h3>
174
175<p> Prefix ++ makes the succeeding item current and returns the new
176current item.
177<p> If the current iterator item was the last item in the list or if
178it was 0, 0 is returned.
179
180<h3 class=fn>type * <a name="operator+-eq"></a>QPtrListIterator::operator+= ( uint&nbsp;jump )
181</h3>
182
183<p> Sets the current item to the item <em>jump</em> positions after the
184current item and returns a pointer to that item.
185<p> If that item is beyond the last item or if the list is empty, it
186sets the current item to 0 and returns 0
187
188<h3 class=fn>type * <a name="operator--"></a>QPtrListIterator::operator-- ()
189</h3>
190
191<p> Prefix - makes the preceding item current and returns the new
192current item.
193<p> If the current iterator item was the first item in the list or if
194it was 0, 0 is returned.
195
196<h3 class=fn>type * <a name="operator--eq"></a>QPtrListIterator::operator-= ( uint&nbsp;jump )
197</h3>
198
199<p> Returns the item <em>jump</em> positions before the current item or 0
200if it is beyond the first item. Makes this the current item.
201
202<h3 class=fn><a href="qptrlistiterator.html">QPtrListIterator</a>&lt;type&gt;&nbsp;&amp; <a name="operator-eq"></a>QPtrListIterator::operator= ( const&nbsp;<a href="qptrlistiterator.html">QPtrListIterator</a>&lt;type&gt;&nbsp;&amp;&nbsp;it )
203</h3>
204
205<p> Assignment. Makes a copy of the iterator <em>it</em> and returns a
206reference to this iterator.
207
208<h3 class=fn>type * <a name="toFirst"></a>QPtrListIterator::toFirst ()
209</h3>
210
211<p> Sets the current iterator item to point to the first list item and
212returns a pointer to the item. Sets the current item to 0 and
213returns 0 if the list is empty.
214<p> <p>See also <a href="#toLast">toLast</a>() and <a href="#atFirst">atFirst</a>().
215
216<h3 class=fn>type * <a name="toLast"></a>QPtrListIterator::toLast ()
217</h3>
218
219<p> Sets the current iterator item to point to the last list item and
220returns a pointer to the item. Sets the current item to 0 and
221returns 0 if the list is empty.
222<p> <p>See also <a href="#toFirst">toFirst</a>() and <a href="#atLast">atLast</a>().
223
224<!-- eof -->
225<hr><p>
226This file is part of the <a href="index.html">Qt toolkit</a>.
227Copyright &copy; 1995-2007
228<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
229<table width=100% cellspacing=0 border=0><tr>
230<td>Copyright &copy; 2007
231<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
232<td align=right><div align=right>Qt 3.3.8</div>
233</table></div></address></body>
234</html>
Note: See TracBrowser for help on using the repository browser.