~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qmutablelinkedlistiterator.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-10-12 23:14:14 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20061012231414-y2oqbom5dy389os0
Tags: upstream-4.2.0
ImportĀ upstreamĀ versionĀ 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
 
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/doc/src/qiterator.qdoc -->
6
 
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/doc/src/qiterator.qdoc -->
 
5
<!-- /tmp/qt-4.2.0-qt-1159540607313/qt-x11-opensource-src-4.2.0/doc/src/qiterator.qdoc -->
7
6
<head>
8
 
    <title>Qt 4.1: QMutableLinkedListIterator Class Reference</title>
9
 
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
10
 
a:link { color: #004faf; text-decoration: none }
11
 
a:visited { color: #672967; text-decoration: none }
12
 
td.postheader { font-family: sans-serif }
13
 
tr.address { font-family: sans-serif }
14
 
body { background: #ffffff; color: black; }</style>
 
7
  <title>Qt 4.2: QMutableLinkedListIterator Class Reference</title>
 
8
  <link href="classic.css" rel="stylesheet" type="text/css" />
15
9
</head>
16
10
<body>
17
11
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
12
<tr>
19
 
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
13
<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>
20
14
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
21
 
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QMutableLinkedListIterator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
 
15
<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">QMutableLinkedListIterator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
22
16
<p>The QMutableLinkedListIterator class provides a Java-style non-const iterator for <a href="qlinkedlist.html">QLinkedList</a>. <a href="#details">More...</a></p>
23
 
<pre>#include &lt;QMutableLinkedListIterator&gt;</pre><ul>
 
17
<pre> #include &lt;QMutableLinkedListIterator&gt;</pre><ul>
24
18
<li><a href="qmutablelinkedlistiterator-members.html">List of all members, including inherited members</a></li>
25
19
</ul>
26
20
<a name="public-functions"></a>
52
46
<p><a href="qlinkedlist.html">QLinkedList</a> has both <a href="containers.html#java-style-iterators">Java-style iterators</a> and <a href="containers.html#stl-style-iterators">STL-style iterators</a>. The Java-style iterators are more high-level and easier to use than the STL-style iterators; on the other hand, they are slightly less efficient.</p>
53
47
<p>QMutableLinkedListIterator&lt;T&gt; allows you to iterate over a <a href="qlinkedlist.html">QLinkedList</a>&lt;T&gt; and modify the list. If you don't want to modify the list (or have a const <a href="qlinkedlist.html">QLinkedList</a>), use the slightly faster <a href="qlinkedlistiterator.html">QLinkedListIterator</a>&lt;T&gt; instead.</p>
54
48
<p>The QMutableLinkedListIterator constructor takes a <a href="qlinkedlist.html">QLinkedList</a> as argument. After construction, the iterator is located at the very beginning of the list (before the first item). Here's how to iterate over all the elements sequentially:</p>
55
 
<pre>&nbsp;   QLinkedList&lt;float&gt; list;
56
 
    ...
57
 
    QMutableLinkedListIterator&lt;float&gt; i(list);
58
 
    while (i.hasNext())
59
 
        qDebug() &lt;&lt; i.next();</pre>
 
49
<pre> QLinkedList&lt;float&gt; list;
 
50
 ...
 
51
 QMutableLinkedListIterator&lt;float&gt; i(list);
 
52
 while (i.hasNext())
 
53
     qDebug() &lt;&lt; i.next();</pre>
60
54
<p>The <a href="qmutablelinkedlistiterator.html#next">next</a>() function returns the next item in the list and advances the iterator. Unlike STL-style iterators, Java-style iterators point <i>between</i> items rather than directly <i>at</i> items. The first call to <a href="qmutablelinkedlistiterator.html#next">next</a>() advances the iterator to the position between the first and second item, and returns the first item; the second call to <a href="qmutablelinkedlistiterator.html#next">next</a>() advances the iterator to the position between the second and third item, returning the second item; and so on.</p>
61
55
<p align="center"><img src="images/javaiterators1.png" /></p><p>Here's how to iterate over the elements in reverse order:</p>
62
 
<pre>&nbsp;   QMutableLinkedListIterator&lt;float&gt; i(list);
63
 
    i.toBack();
64
 
    while (i.hasPrevious())
65
 
        qDebug() &lt;&lt; i.previous();</pre>
 
56
<pre> QMutableLinkedListIterator&lt;float&gt; i(list);
 
57
 i.toBack();
 
58
 while (i.hasPrevious())
 
59
     qDebug() &lt;&lt; i.previous();</pre>
66
60
<p>If you want to find all occurrences of a particular value, use <a href="qmutablelinkedlistiterator.html#findNext">findNext</a>() or <a href="qmutablelinkedlistiterator.html#findPrevious">findPrevious</a>() in a loop.</p>
67
61
<p>If you want to remove items as you iterate over the list, use <a href="qmutablelinkedlistiterator.html#remove">remove</a>(). If you want to modify the value of an item, use <a href="qmutablelinkedlistiterator.html#setValue">setValue</a>(). If you want to insert a new item in the list, use <a href="qmutablelinkedlistiterator.html#insert">insert</a>().</p>
68
62
<p>Example:</p>
69
 
<pre>&nbsp;   QMutableLinkedListIterator&lt;int&gt; i(list);
70
 
    while (i.hasNext()) {
71
 
        int val = i.next();
72
 
        if (val &lt; 0) {
73
 
            i.setValue(-val);
74
 
        } else if (val == 0) {
75
 
            i.remove();
76
 
        }
77
 
    }</pre>
 
63
<pre> QMutableLinkedListIterator&lt;int&gt; i(list);
 
64
 while (i.hasNext()) {
 
65
     int val = i.next();
 
66
     if (val &lt; 0) {
 
67
         i.setValue(-val);
 
68
     } else if (val == 0) {
 
69
         i.remove();
 
70
     }
 
71
 }</pre>
78
72
<p>The example traverses a list, replacing negative numbers with their absolute values, and eliminating zeroes.</p>
79
73
<p>Only one mutable iterator can be active on a given list at any time. Furthermore, no changes should be done directly to the list while the iterator is active (as opposed to through the iterator), since this could invalidate the iterator and lead to undefined behavior.</p>
80
74
<p>See also <a href="qlinkedlistiterator.html">QLinkedListIterator</a> and <a href="qlinkedlist-iterator.html">QLinkedList::iterator</a>.</p>
122
116
<h3 class="fn"><a name="remove"></a>void QMutableLinkedListIterator::remove ()</h3>
123
117
<p>Removes the last item that was jumped over using one of the traversal functions (<a href="qmutablelinkedlistiterator.html#next">next</a>(), <a href="qmutablelinkedlistiterator.html#previous">previous</a>(), <a href="qmutablelinkedlistiterator.html#findNext">findNext</a>(), <a href="qmutablelinkedlistiterator.html#findPrevious">findPrevious</a>()).</p>
124
118
<p>Example:</p>
125
 
<pre>&nbsp;   QMutableLinkedListIterator&lt;int&gt; i(list);
126
 
    while (i.hasNext()) {
127
 
        int val = i.next();
128
 
        if (val &lt; -32768 || val &gt; 32767)
129
 
            i.remove();
130
 
    }</pre>
 
119
<pre> QMutableLinkedListIterator&lt;int&gt; i(list);
 
120
 while (i.hasNext()) {
 
121
     int val = i.next();
 
122
     if (val &lt; -32768 || val &gt; 32767)
 
123
         i.remove();
 
124
 }</pre>
131
125
<p>See also <a href="qmutablelinkedlistiterator.html#insert">insert</a>() and <a href="qmutablelinkedlistiterator.html#setValue">setValue</a>().</p>
132
126
<h3 class="fn"><a name="setValue"></a>void QMutableLinkedListIterator::setValue ( const T &amp; <i>value</i> ) const</h3>
133
127
<p>Replaces the value of the last item that was jumped over using one of the traversal functions with <i>value</i>.</p>
134
128
<p>The traversal functions are <a href="qmutablelinkedlistiterator.html#next">next</a>(), <a href="qmutablelinkedlistiterator.html#previous">previous</a>(), <a href="qmutablelinkedlistiterator.html#findNext">findNext</a>(), and <a href="qmutablelinkedlistiterator.html#findPrevious">findPrevious</a>().</p>
135
129
<p>Example:</p>
136
 
<pre>&nbsp;   QMutableLinkedListIterator&lt;double&gt; i(list);
137
 
    while (i.hasNext()) {
138
 
        double val = i.next();
139
 
        i.setValue(sqrt(val));
140
 
    }</pre>
 
130
<pre> QMutableLinkedListIterator&lt;double&gt; i(list);
 
131
 while (i.hasNext()) {
 
132
     double val = i.next();
 
133
     i.setValue(sqrt(val));
 
134
 }</pre>
141
135
<p>See also <a href="qmutablelinkedlistiterator.html#value">value</a>(), <a href="qmutablelinkedlistiterator.html#remove">remove</a>(), and <a href="qmutablelinkedlistiterator.html#insert">insert</a>().</p>
142
136
<h3 class="fn"><a name="toBack"></a>void QMutableLinkedListIterator::toBack ()</h3>
143
137
<p>Moves the iterator to the back of the container (after the last item).</p>
159
153
<table width="100%" cellspacing="0" border="0"><tr class="address">
160
154
<td width="30%">Copyright &copy; 2006 <a href="trolltech.html">Trolltech</a></td>
161
155
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
162
 
<td width="30%" align="right"><div align="right">Qt 4.1.4</div></td>
 
156
<td width="30%" align="right"><div align="right">Qt 4.2.0</div></td>
163
157
</tr></table></div></address></body>
164
158
</html>