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

« back to all changes in this revision

Viewing changes to doc/html/qmap-const-iterator.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/src/corelib/tools/qmap.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QMap::const_iterator 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">QMap::const_iterator Class Reference</h1>
 
21
<p>The QMap::const_iterator class provides an STL-style const iterator for <a href="qmap.html">QMap</a> and <a href="qmultimap.html">QMultiMap</a>. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QMap&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<ul>
 
24
<li><a href="qmap-const-iterator-members.html">List of all members, including inherited members</a></li>
 
25
<li><a href="qmap-const-iterator-qt3.html">Qt 3 support members</a></li>
 
26
</ul>
 
27
<a name="public-functions"></a>
 
28
<h3>Public Functions</h3>
 
29
<ul>
 
30
<li><div class="fn"/><b><a href="qmap-const-iterator.html#const_iterator">const_iterator</a></b> ()</li>
 
31
<li><div class="fn"/><b><a href="qmap-const-iterator.html#const_iterator-3">const_iterator</a></b> ( const iterator &amp; <i>other</i> )</li>
 
32
<li><div class="fn"/>const Key &amp; <b><a href="qmap-const-iterator.html#key">key</a></b> () const</li>
 
33
<li><div class="fn"/>const T &amp; <b><a href="qmap-const-iterator.html#value">value</a></b> () const</li>
 
34
<li><div class="fn"/>bool <b><a href="qmap-const-iterator.html#operator-not-eq">operator!=</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
35
<li><div class="fn"/>const T &amp; <b><a href="qmap-const-iterator.html#operator-2a">operator*</a></b> () const</li>
 
36
<li><div class="fn"/>const_iterator <b><a href="qmap-const-iterator.html#operator-2b">operator+</a></b> ( int <i>j</i> ) const</li>
 
37
<li><div class="fn"/>const_iterator &amp; <b><a href="qmap-const-iterator.html#operator-2b-2b">operator++</a></b> ()</li>
 
38
<li><div class="fn"/>const_iterator <b><a href="qmap-const-iterator.html#operator-2b-2b-2">operator++</a></b> ( int )</li>
 
39
<li><div class="fn"/>const_iterator &amp; <b><a href="qmap-const-iterator.html#operator-2b-eq">operator+=</a></b> ( int <i>j</i> )</li>
 
40
<li><div class="fn"/>const_iterator <b><a href="qmap-const-iterator.html#operator-">operator-</a></b> ( int <i>j</i> ) const</li>
 
41
<li><div class="fn"/>const_iterator &amp; <b><a href="qmap-const-iterator.html#operator--">operator--</a></b> ()</li>
 
42
<li><div class="fn"/>const_iterator <b><a href="qmap-const-iterator.html#operator---2">operator--</a></b> ( int )</li>
 
43
<li><div class="fn"/>const_iterator &amp; <b><a href="qmap-const-iterator.html#operator--eq">operator-=</a></b> ( int <i>j</i> )</li>
 
44
<li><div class="fn"/>const T * <b><a href="qmap-const-iterator.html#operator--gt">operator-&gt;</a></b> () const</li>
 
45
<li><div class="fn"/>bool <b><a href="qmap-const-iterator.html#operator-eq-eq">operator==</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
46
</ul>
 
47
<a name="details"></a>
 
48
<hr />
 
49
<h2>Detailed Description</h2>
 
50
<p>The QMap::const_iterator class provides an STL-style const iterator for <a href="qmap.html">QMap</a> and <a href="qmultimap.html">QMultiMap</a>.</p>
 
51
<p><a href="qmap.html">QMap</a> features both <a href="containers.html#stl-style-iterators">STL-style iterators</a> and <a href="containers.html#java-style-iterators">Java-style iterators</a>. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity.</p>
 
52
<p><a href="qmap.html">QMap</a>&lt;Key, T&gt;::const_iterator allows you to iterate over a <a href="qmap.html">QMap</a> (or a <a href="qmultimap.html">QMultiMap</a>). If you want to modify the <a href="qmap.html">QMap</a> as you iterate over it, you must use <a href="qmap-iterator.html">QMap::iterator</a> instead. It is generally good practice to use QMap::const_iterator on a non-const <a href="qmap.html">QMap</a> as well, unless you need to change the <a href="qmap.html">QMap</a> through the iterator. Const iterators are slightly faster, and can improve code readability.</p>
 
53
<p>The default QMap::const_iterator constructor creates an uninitialized iterator. You must initialize it using a <a href="qmap.html">QMap</a> function like <a href="qmap.html#constBegin">QMap::constBegin</a>(), <a href="qmap.html#constEnd">QMap::constEnd</a>(), or <a href="qmap.html#find">QMap::find</a>() before you can start iterating. Here's a typical loop that prints all the (key, value) pairs stored in a map:</p>
 
54
<pre>&nbsp;   QMap&lt;QString, int&gt; map;
 
55
    map.insert(&quot;January&quot;, 1);
 
56
    map.insert(&quot;February&quot;, 2);
 
57
    ...
 
58
    map.insert(&quot;December&quot;, 12);
 
59
 
 
60
    QMap&lt;QString, int&gt;::const_iterator i;
 
61
    for (i = map.constBegin(); i != map.constEnd(); ++i)
 
62
        cout &lt;&lt; i.key() &lt;&lt; &quot;: &quot; &lt;&lt; i.value() &lt;&lt; endl;</pre>
 
63
<p>Unlike <a href="qhash.html">QHash</a>, which stores its items in an arbitrary order, <a href="qmap.html">QMap</a> stores its items ordered by key. Items that share the same key (because they were inserted using <a href="qmap.html#insertMulti">QMap::insertMulti</a>()) will appear consecutively, from the most recently to the least recently inserted value.</p>
 
64
<p>Multiple iterators can be used on the same map. If you add items to the map, existing iterators will remain valid. If you remove items from the map, iterators that point to the removed items will become dangling iterators.</p>
 
65
<p>See also <a href="qmap-iterator.html">QMap::iterator</a> and <a href="qmapiterator.html">QMapIterator</a>.</p>
 
66
<hr />
 
67
<h2>Member Function Documentation</h2>
 
68
<h3 class="fn"><a name="const_iterator"></a>const_iterator::const_iterator ()</h3>
 
69
<p>Constructs an uninitialized iterator.</p>
 
70
<p>Functions like <a href="qmap-const-iterator.html#key">key</a>(), <a href="qmap-const-iterator.html#value">value</a>(), and operator++() must not be called on an uninitialized iterator. Use operator=() to assign a value to it before using it.</p>
 
71
<p>See also <a href="qmap.html#constBegin">QMap::constBegin</a>() and <a href="qmap.html#constEnd">QMap::constEnd</a>().</p>
 
72
<h3 class="fn"><a name="const_iterator-3"></a>const_iterator::const_iterator ( const <a href="qmap-iterator.html">iterator</a> &amp; <i>other</i> )</h3>
 
73
<p>Constructs a copy of <i>other</i>.</p>
 
74
<h3 class="fn"><a name="key"></a>const Key &amp; const_iterator::key () const</h3>
 
75
<p>Returns the current item's key.</p>
 
76
<p>See also <a href="qmap-const-iterator.html#value">value</a>().</p>
 
77
<h3 class="fn"><a name="value"></a>const T &amp; const_iterator::value () const</h3>
 
78
<p>Returns the current item's value.</p>
 
79
<p>See also <a href="qmap-const-iterator.html#key">key</a>() and <a href="qmap-const-iterator.html#operator-2a">operator*</a>().</p>
 
80
<h3 class="fn"><a name="operator-not-eq"></a>bool const_iterator::operator!= ( const const_iterator &amp; <i>other</i> ) const</h3>
 
81
<p>Returns true if <i>other</i> points to a different item than this iterator; otherwise returns false.</p>
 
82
<p>See also <a href="qmap-const-iterator.html#operator-eq-eq">operator==</a>().</p>
 
83
<h3 class="fn"><a name="operator-2a"></a>const T &amp; const_iterator::operator* () const</h3>
 
84
<p>Returns the current item's value.</p>
 
85
<p>Same as <a href="qmap-const-iterator.html#value">value</a>().</p>
 
86
<p>See also <a href="qmap-const-iterator.html#key">key</a>().</p>
 
87
<h3 class="fn"><a name="operator-2b"></a>const_iterator const_iterator::operator+ ( int <i>j</i> ) const</h3>
 
88
<p>Returns an iterator to the item at <i>j</i> positions forward from this iterator. (If <i>j</i> is negative, the iterator goes backward.)</p>
 
89
<p>This operation can be slow for large <i>j</i> values.</p>
 
90
<p>See also <a href="qmap-const-iterator.html#operator-">operator-</a>().</p>
 
91
<h3 class="fn"><a name="operator-2b-2b"></a>const_iterator &amp; const_iterator::operator++ ()</h3>
 
92
<p>The prefix ++ operator (<tt>++i</tt>) advances the iterator to the next item in the map and returns an iterator to the new current item.</p>
 
93
<p>Calling this function on <a href="qmap.html#end">QMap::end</a>() leads to undefined results.</p>
 
94
<p>See also <a href="qmap-const-iterator.html#operator--">operator--</a>().</p>
 
95
<h3 class="fn"><a name="operator-2b-2b-2"></a>const_iterator const_iterator::operator++ ( int )</h3>
 
96
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
97
<p>The postfix ++ operator (<tt>i++</tt>) advances the iterator to the next item in the map and returns an iterator to the previously current item.</p>
 
98
<h3 class="fn"><a name="operator-2b-eq"></a>const_iterator &amp; const_iterator::operator+= ( int <i>j</i> )</h3>
 
99
<p>Advances the iterator by <i>j</i> items. (If <i>j</i> is negative, the iterator goes backward.)</p>
 
100
<p>This operation can be slow for large <i>j</i> values.</p>
 
101
<p>See also <a href="qmap-const-iterator.html#operator--eq">operator-=</a>() and <a href="qmap-const-iterator.html#operator-2b">operator+</a>().</p>
 
102
<h3 class="fn"><a name="operator-"></a>const_iterator const_iterator::operator- ( int <i>j</i> ) const</h3>
 
103
<p>Returns an iterator to the item at <i>j</i> positions backward from this iterator. (If <i>j</i> is negative, the iterator goes forward.)</p>
 
104
<p>This operation can be slow for large <i>j</i> values.</p>
 
105
<p>See also <a href="qmap-const-iterator.html#operator-2b">operator+</a>().</p>
 
106
<h3 class="fn"><a name="operator--"></a>const_iterator &amp; const_iterator::operator-- ()</h3>
 
107
<p>The prefix -- operator (<tt>--i</tt>) makes the preceding item current and returns an iterator pointing to the new current item.</p>
 
108
<p>Calling this function on <a href="qmap.html#begin">QMap::begin</a>() leads to undefined results.</p>
 
109
<p>See also <a href="qmap-const-iterator.html#operator-2b-2b">operator++</a>().</p>
 
110
<h3 class="fn"><a name="operator---2"></a>const_iterator const_iterator::operator-- ( int )</h3>
 
111
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
112
<p>The postfix -- operator (<tt>i--</tt>) makes the preceding item current and returns an iterator pointing to the previously current item.</p>
 
113
<h3 class="fn"><a name="operator--eq"></a>const_iterator &amp; const_iterator::operator-= ( int <i>j</i> )</h3>
 
114
<p>Makes the iterator go back by <i>j</i> items. (If <i>j</i> is negative, the iterator goes forward.)</p>
 
115
<p>This operation can be slow for large <i>j</i> values.</p>
 
116
<p>See also <a href="qmap-const-iterator.html#operator-2b-eq">operator+=</a>() and <a href="qmap-const-iterator.html#operator-">operator-</a>().</p>
 
117
<h3 class="fn"><a name="operator--gt"></a>const T * const_iterator::operator-&gt; () const</h3>
 
118
<p>Returns a pointer to the current item's value.</p>
 
119
<p>See also <a href="qmap-const-iterator.html#value">value</a>().</p>
 
120
<h3 class="fn"><a name="operator-eq-eq"></a>bool const_iterator::operator== ( const const_iterator &amp; <i>other</i> ) const</h3>
 
121
<p>Returns true if <i>other</i> points to the same item as this iterator; otherwise returns false.</p>
 
122
<p>See also <a href="qmap-const-iterator.html#operator-not-eq">operator!=</a>().</p>
 
123
<p /><address><hr /><div align="center">
 
124
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
125
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
126
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
127
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
128
</tr></table></div></address></body>
 
129
</html>