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

« back to all changes in this revision

Viewing changes to doc/html/qmutablehashiterator.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/doc/src/qiterator.qdoc -->
 
6
<head>
 
7
    <title>Qt 4.0: QMutableHashIterator Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<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="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<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">QMutableHashIterator Class Reference</h1>
 
21
<p>The QMutableHashIterator class provides a Java-style non-const iterator for <a href="qhash.html">QHash</a> and <a href="qmultihash.html">QMultiHash</a>. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QMutableHashIterator&gt;</pre><ul>
 
23
<li><a href="qmutablehashiterator-members.html">List of all members, including inherited members</a></li>
 
24
</ul>
 
25
<a name="public-functions"></a>
 
26
<h3>Public Functions</h3>
 
27
<ul>
 
28
<li><div class="fn"/><b><a href="qmutablehashiterator.html#QMutableHashIterator">QMutableHashIterator</a></b> ( QHash&lt;Key, T&gt; &amp; <i>hash</i> )</li>
 
29
<li><div class="fn"/><b><a href="qmutablehashiterator.html#dtor.QMutableHashIterator">~QMutableHashIterator</a></b> ()</li>
 
30
<li><div class="fn"/>bool <b><a href="qmutablehashiterator.html#findNext">findNext</a></b> ( const T &amp; <i>value</i> )</li>
 
31
<li><div class="fn"/>bool <b><a href="qmutablehashiterator.html#findPrevious">findPrevious</a></b> ( const T &amp; <i>value</i> )</li>
 
32
<li><div class="fn"/>bool <b><a href="qmutablehashiterator.html#hasNext">hasNext</a></b> () const</li>
 
33
<li><div class="fn"/>bool <b><a href="qmutablehashiterator.html#hasPrevious">hasPrevious</a></b> () const</li>
 
34
<li><div class="fn"/>const Key &amp; <b><a href="qmutablehashiterator.html#key">key</a></b> () const</li>
 
35
<li><div class="fn"/>Item <b><a href="qmutablehashiterator.html#next">next</a></b> ()</li>
 
36
<li><div class="fn"/>Item <b><a href="qmutablehashiterator.html#peekNext">peekNext</a></b> () const</li>
 
37
<li><div class="fn"/>Item <b><a href="qmutablehashiterator.html#peekPrevious">peekPrevious</a></b> () const</li>
 
38
<li><div class="fn"/>Item <b><a href="qmutablehashiterator.html#previous">previous</a></b> ()</li>
 
39
<li><div class="fn"/>void <b><a href="qmutablehashiterator.html#remove">remove</a></b> ()</li>
 
40
<li><div class="fn"/>void <b><a href="qmutablehashiterator.html#setValue">setValue</a></b> ( const T &amp; <i>value</i> )</li>
 
41
<li><div class="fn"/>void <b><a href="qmutablehashiterator.html#toBack">toBack</a></b> ()</li>
 
42
<li><div class="fn"/>void <b><a href="qmutablehashiterator.html#toFront">toFront</a></b> ()</li>
 
43
<li><div class="fn"/>const T &amp; <b><a href="qmutablehashiterator.html#value">value</a></b> () const</li>
 
44
<li><div class="fn"/>QMutableHashIterator &amp; <b><a href="qmutablehashiterator.html#operator-eq">operator=</a></b> ( QHash&lt;Key, T&gt; &amp; <i>hash</i> )</li>
 
45
</ul>
 
46
<a name="details"></a>
 
47
<hr />
 
48
<h2>Detailed Description</h2>
 
49
<p>The QMutableHashIterator class provides a Java-style non-const iterator for <a href="qhash.html">QHash</a> and <a href="qmultihash.html">QMultiHash</a>.</p>
 
50
<p><a href="qhash.html">QHash</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>
 
51
<p>QMutableHashIterator&lt;Key, T&gt; allows you to iterate over a <a href="qhash.html">QHash</a> (or a <a href="qmultihash.html">QMultiHash</a>) and modify the hash. If you don't want to modify the hash (or have a const <a href="qhash.html">QHash</a>), use the slightly faster <a href="qhashiterator.html">QHashIterator</a> instead.</p>
 
52
<p>The QMutableHashIterator constructor takes a <a href="qhash.html">QHash</a> as argument. After construction, the iterator is located at the very beginning of the hash (before the first item). Here's how to iterate over all the elements sequentially:</p>
 
53
<pre>&nbsp;   QHash&lt;int, QWidget *&gt; hash;
 
54
    ...
 
55
    QMutableHashIterator&lt;QString, QWidget *&gt; i(hash);
 
56
    while (i.hasNext()) {
 
57
        i.next();
 
58
        cout &lt;&lt; i.key() &lt;&lt; &quot;: &quot; &lt;&lt; i.value() &lt;&lt; endl;
 
59
    }</pre>
 
60
<p>The <a href="qmutablehashiterator.html#next">next</a>() function returns the next item in the hash and advances the iterator. The <a href="qmutablehashiterator.html#key">key</a>() and <a href="qmutablehashiterator.html#value">value</a>() functions return the key and value of the last item that was jumped over.</p>
 
61
<p>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="qmutablehashiterator.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="qmutablehashiterator.html#next">next</a>() advances the iterator to the position between the second and third item; and so on.</p>
 
62
<center><img src="images/javaiterators1.png" /></center><p>Here's how to iterate over the elements in reverse order:</p>
 
63
<pre>&nbsp;   QMutableHashIterator&lt;int, QWidget *&gt; i(hash);
 
64
    i.toBack();
 
65
    while (i.hasPrevious()) {
 
66
        i.previous();
 
67
        cout &lt;&lt; i.key() &lt;&lt; &quot;: &quot; &lt;&lt; i.value() &lt;&lt; endl;
 
68
    }</pre>
 
69
<p>If you want to find all occurrences of a particular value, use <a href="qmutablehashiterator.html#findNext">findNext</a>() or <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>() in a loop. For example:</p>
 
70
<pre>&nbsp;   QMutableHashIterator&lt;int, QWidget *&gt; i(hash);
 
71
    while (i.findNext(widget)) {
 
72
        cout &lt;&lt; &quot;Found widget &quot; &lt;&lt; widget &lt;&lt; &quot; under key &quot;
 
73
             &lt;&lt; i.key() &lt;&lt; endl;
 
74
    }</pre>
 
75
<p>If you want to remove items as you iterate over the hash, use <a href="qmutablehashiterator.html#remove">remove</a>(). If you want to modify the value of an item, use <a href="qmutablehashiterator.html#setValue">setValue</a>().</p>
 
76
<p>Example:</p>
 
77
<pre>&nbsp;   QMutableHashIterator&lt;QString, QString&gt; i(hash);
 
78
    while (i.hasNext()) {
 
79
        i.next();
 
80
        if (i.key() == i.value())
 
81
            i.remove();
 
82
    }</pre>
 
83
<p>The example removes all (key, value) pairs where the key and the value are the same.</p>
 
84
<p>Only one mutable iterator can be active on a given hash at any time. Furthermore, no changes should be done directly to the hash while the iterator is active (as opposed to through the iterator), since this could invalidate the iterator and lead to undefined behavior.</p>
 
85
<p>See also <a href="qhashiterator.html">QHashIterator</a> and <a href="qhash-iterator.html">QHash::iterator</a>.</p>
 
86
<hr />
 
87
<h2>Member Function Documentation</h2>
 
88
<h3 class="fn"><a name="QMutableHashIterator"></a>QMutableHashIterator::QMutableHashIterator ( <a href="qhash.html">QHash</a>&lt;Key, T&gt; &amp; <i>hash</i> )</h3>
 
89
<p>Constructs an iterator for traversing <i>hash</i>. The iterator is set to be at the front of the hash (before the first item).</p>
 
90
<p>See also <a href="qmutablehashiterator.html#operator-eq">operator=</a>().</p>
 
91
<h3 class="fn"><a name="dtor.QMutableHashIterator"></a>QMutableHashIterator::~QMutableHashIterator ()</h3>
 
92
<p>Destroys the iterator.</p>
 
93
<p>See also <a href="qmutablehashiterator.html#operator-eq">operator=</a>().</p>
 
94
<h3 class="fn"><a name="findNext"></a>bool QMutableHashIterator::findNext ( const T &amp; <i>value</i> )</h3>
 
95
<p>Searches for <i>value</i> starting from the current iterator position forward. Returns true if a (key, value) pair with value <i>value</i> is found; otherwise returns false.</p>
 
96
<p>After the call, if <i>value</i> was found, the iterator is positioned just after the matching item; otherwise, the iterator is positioned at the back of the container.</p>
 
97
<p>See also <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>().</p>
 
98
<h3 class="fn"><a name="findPrevious"></a>bool QMutableHashIterator::findPrevious ( const T &amp; <i>value</i> )</h3>
 
99
<p>Searches for <i>value</i> starting from the current iterator position backward. Returns true if a (key, value) pair with value <i>value</i> is found; otherwise returns false.</p>
 
100
<p>After the call, if <i>value</i> was found, the iterator is positioned just before the matching item; otherwise, the iterator is positioned at the front of the container.</p>
 
101
<p>See also <a href="qmutablehashiterator.html#findNext">findNext</a>().</p>
 
102
<h3 class="fn"><a name="hasNext"></a>bool QMutableHashIterator::hasNext () const</h3>
 
103
<p>Returns true if there is at least one item ahead of the iterator, i.e. the iterator is <i>not</i> at the back of the container; otherwise returns false.</p>
 
104
<p>See also <a href="qmutablehashiterator.html#hasPrevious">hasPrevious</a>() and <a href="qmutablehashiterator.html#next">next</a>().</p>
 
105
<h3 class="fn"><a name="hasPrevious"></a>bool QMutableHashIterator::hasPrevious () const</h3>
 
106
<p>Returns true if there is at least one item behind the iterator, i.e. the iterator is <i>not</i> at the front of the container; otherwise returns false.</p>
 
107
<p>See also <a href="qmutablehashiterator.html#hasNext">hasNext</a>() and <a href="qmutablehashiterator.html#previous">previous</a>().</p>
 
108
<h3 class="fn"><a name="key"></a>const Key &amp; QMutableHashIterator::key () const</h3>
 
109
<p>Returns the key of the last item that was jumped over using one of the traversal functions (<a href="qmutablehashiterator.html#next">next</a>(), <a href="qmutablehashiterator.html#previous">previous</a>(), <a href="qmutablehashiterator.html#findNext">findNext</a>(), <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>()).</p>
 
110
<p>After a call to <a href="qmutablehashiterator.html#next">next</a>() or <a href="qmutablehashiterator.html#findNext">findNext</a>(), key() is equivalent to <a href="qmutablehashiterator.html#peekPrevious">peekPrevious</a>().key(). After a call to <a href="qmutablehashiterator.html#previous">previous</a>() or <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>(), key() is equivalent to <a href="qmutablehashiterator.html#peekNext">peekNext</a>().key().</p>
 
111
<p>See also <a href="qmutablehashiterator.html#value">value</a>().</p>
 
112
<h3 class="fn"><a name="next"></a><a href="qmutablehashiterator.html#Item-typedef">Item</a> QMutableHashIterator::next ()</h3>
 
113
<p>Returns the next item and advances the iterator by one position.</p>
 
114
<p>Call <a href="qmutablehashiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmutablehashiterator.html#value">value</a>() to obtain the value.</p>
 
115
<p>Calling this function on an iterator located at the back of the container leads to undefined results.</p>
 
116
<p>See also <a href="qmutablehashiterator.html#hasNext">hasNext</a>(), <a href="qmutablehashiterator.html#peekNext">peekNext</a>(), and <a href="qmutablehashiterator.html#previous">previous</a>().</p>
 
117
<h3 class="fn"><a name="peekNext"></a><a href="qmutablehashiterator.html#Item-typedef">Item</a> QMutableHashIterator::peekNext () const</h3>
 
118
<p>Returns a reference to the next item without moving the iterator.</p>
 
119
<p>Call <a href="qmutablehashiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmutablehashiterator.html#value">value</a>() to obtain the value.</p>
 
120
<p>Calling this function on an iterator located at the back of the container leads to undefined results.</p>
 
121
<p>See also <a href="qmutablehashiterator.html#hasNext">hasNext</a>(), <a href="qmutablehashiterator.html#next">next</a>(), and <a href="qmutablehashiterator.html#peekPrevious">peekPrevious</a>().</p>
 
122
<h3 class="fn"><a name="peekPrevious"></a><a href="qmutablehashiterator.html#Item-typedef">Item</a> QMutableHashIterator::peekPrevious () const</h3>
 
123
<p>Returns the previous item without moving the iterator.</p>
 
124
<p>Call <a href="qmutablehashiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmutablehashiterator.html#value">value</a>() to obtain the value.</p>
 
125
<p>Calling this function on an iterator located at the front of the container leads to undefined results.</p>
 
126
<p>See also <a href="qmutablehashiterator.html#hasPrevious">hasPrevious</a>(), <a href="qmutablehashiterator.html#previous">previous</a>(), and <a href="qmutablehashiterator.html#peekNext">peekNext</a>().</p>
 
127
<h3 class="fn"><a name="previous"></a><a href="qmutablehashiterator.html#Item-typedef">Item</a> QMutableHashIterator::previous ()</h3>
 
128
<p>Returns the previous item and moves the iterator back by one position.</p>
 
129
<p>Call <a href="qmutablehashiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmutablehashiterator.html#value">value</a>() to obtain the value.</p>
 
130
<p>Calling this function on an iterator located at the front of the container leads to undefined results.</p>
 
131
<p>See also <a href="qmutablehashiterator.html#hasPrevious">hasPrevious</a>(), <a href="qmutablehashiterator.html#peekPrevious">peekPrevious</a>(), and <a href="qmutablehashiterator.html#next">next</a>().</p>
 
132
<h3 class="fn"><a name="remove"></a>void QMutableHashIterator::remove ()</h3>
 
133
<p>Removes the last item that was jumped over using one of the traversal functions (<a href="qmutablehashiterator.html#next">next</a>(), <a href="qmutablehashiterator.html#previous">previous</a>(), <a href="qmutablehashiterator.html#findNext">findNext</a>(), <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>()).</p>
 
134
<p>See also <a href="qmutablehashiterator.html#setValue">setValue</a>().</p>
 
135
<h3 class="fn"><a name="setValue"></a>void QMutableHashIterator::setValue ( const T &amp; <i>value</i> )</h3>
 
136
<p>Replaces the value of the last item that was jumped over using one of the traversal functions with <i>value</i>.</p>
 
137
<p>The traversal functions are <a href="qmutablehashiterator.html#next">next</a>(), <a href="qmutablehashiterator.html#previous">previous</a>(), <a href="qmutablehashiterator.html#findNext">findNext</a>(), and <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>().</p>
 
138
<p>See also <a href="qmutablehashiterator.html#key">key</a>(), <a href="qmutablehashiterator.html#value">value</a>(), and <a href="qmutablehashiterator.html#remove">remove</a>().</p>
 
139
<h3 class="fn"><a name="toBack"></a>void QMutableHashIterator::toBack ()</h3>
 
140
<p>Moves the iterator to the back of the container (after the last item).</p>
 
141
<p>See also <a href="qmutablehashiterator.html#toFront">toFront</a>() and <a href="qmutablehashiterator.html#previous">previous</a>().</p>
 
142
<h3 class="fn"><a name="toFront"></a>void QMutableHashIterator::toFront ()</h3>
 
143
<p>Moves the iterator to the front of the container (before the first item).</p>
 
144
<p>See also <a href="qmutablehashiterator.html#toBack">toBack</a>() and <a href="qmutablehashiterator.html#next">next</a>().</p>
 
145
<h3 class="fn"><a name="value"></a>const T &amp; QMutableHashIterator::value () const</h3>
 
146
<p>Returns the value of the last item that was jumped over using one of the traversal functions (<a href="qmutablehashiterator.html#next">next</a>(), <a href="qmutablehashiterator.html#previous">previous</a>(), <a href="qmutablehashiterator.html#findNext">findNext</a>(), <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>()).</p>
 
147
<p>After a call to <a href="qmutablehashiterator.html#next">next</a>() or <a href="qmutablehashiterator.html#findNext">findNext</a>(), value() is equivalent to <a href="qmutablehashiterator.html#peekPrevious">peekPrevious</a>().value(). After a call to <a href="qmutablehashiterator.html#previous">previous</a>() or <a href="qmutablehashiterator.html#findPrevious">findPrevious</a>(), value() is equivalent to <a href="qmutablehashiterator.html#peekNext">peekNext</a>().value().</p>
 
148
<p>See also <a href="qmutablehashiterator.html#key">key</a>() and <a href="qmutablehashiterator.html#setValue">setValue</a>().</p>
 
149
<h3 class="fn"><a name="operator-eq"></a>QMutableHashIterator &amp; QMutableHashIterator::operator= ( <a href="qhash.html">QHash</a>&lt;Key, T&gt; &amp; <i>hash</i> )</h3>
 
150
<p>Makes the iterator operate on <i>hash</i>. The iterator is set to be at the front of the hash (before the first item).</p>
 
151
<p>See also <a href="qmutablehashiterator.html#toFront">toFront</a>() and <a href="qmutablehashiterator.html#toBack">toBack</a>().</p>
 
152
<p /><address><hr /><div align="center">
 
153
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
154
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
155
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
156
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
157
</tr></table></div></address></body>
 
158
</html>