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

« back to all changes in this revision

Viewing changes to doc/html/qvectoriterator.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: QVectorIterator 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">QVectorIterator Class Reference</h1>
 
21
<p>The QVectorIterator class provides a Java-style const iterator for <a href="qvector.html">QVector</a> and <a href="qstack.html">QStack</a>. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QVectorIterator&gt;</pre><ul>
 
23
<li><a href="qvectoriterator-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="qvectoriterator.html#QVectorIterator">QVectorIterator</a></b> ( const QVector&lt;T&gt; &amp; <i>vector</i> )</li>
 
29
<li><div class="fn"/>bool <b><a href="qvectoriterator.html#findNext">findNext</a></b> ( const T &amp; <i>value</i> )</li>
 
30
<li><div class="fn"/>bool <b><a href="qvectoriterator.html#findPrevious">findPrevious</a></b> ( const T &amp; <i>value</i> )</li>
 
31
<li><div class="fn"/>bool <b><a href="qvectoriterator.html#hasNext">hasNext</a></b> () const</li>
 
32
<li><div class="fn"/>bool <b><a href="qvectoriterator.html#hasPrevious">hasPrevious</a></b> () const</li>
 
33
<li><div class="fn"/>const T &amp; <b><a href="qvectoriterator.html#next">next</a></b> ()</li>
 
34
<li><div class="fn"/>const T &amp; <b><a href="qvectoriterator.html#peekNext">peekNext</a></b> () const</li>
 
35
<li><div class="fn"/>const T &amp; <b><a href="qvectoriterator.html#peekPrevious">peekPrevious</a></b> () const</li>
 
36
<li><div class="fn"/>const T &amp; <b><a href="qvectoriterator.html#previous">previous</a></b> ()</li>
 
37
<li><div class="fn"/>void <b><a href="qvectoriterator.html#toBack">toBack</a></b> ()</li>
 
38
<li><div class="fn"/>void <b><a href="qvectoriterator.html#toFront">toFront</a></b> ()</li>
 
39
<li><div class="fn"/>QVectorIterator &amp; <b><a href="qvectoriterator.html#operator-eq">operator=</a></b> ( const QVector&lt;T&gt; &amp; <i>vector</i> )</li>
 
40
</ul>
 
41
<a name="details"></a>
 
42
<hr />
 
43
<h2>Detailed Description</h2>
 
44
<p>The QVectorIterator class provides a Java-style const iterator for <a href="qvector.html">QVector</a> and <a href="qstack.html">QStack</a>.</p>
 
45
<p><a href="qvector.html">QVector</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>
 
46
<p>An alternative to using iterators is to use index positions. Most <a href="qvector.html">QVector</a> member functions take an index as their first parameter, making it possible to access, insert, and remove items without using iterators.</p>
 
47
<p>QVectorIterator&lt;T&gt; allows you to iterate over a <a href="qvector.html">QVector</a>&lt;T&gt; (or a <a href="qstack.html">QStack</a>&lt;T&gt;). If you want to modify the vector as you iterate over it, use <a href="qmutablevectoriterator.html">QMutableVectorIterator</a>&lt;T&gt; instead.</p>
 
48
<p>The QVectorIterator constructor takes a <a href="qvector.html">QVector</a> as argument. After construction, the iterator is located at the very beginning of the vector (before the first item). Here's how to iterate over all the elements sequentially:</p>
 
49
<pre>&nbsp;   QVector&lt;float&gt; vector;
 
50
    ...
 
51
    QVectorIterator&lt;float&gt; i(vector);
 
52
    while (i.hasNext())
 
53
        cout &lt;&lt; i.next() &lt;&lt; endl;</pre>
 
54
<p>The <a href="qvectoriterator.html#next">next</a>() function returns the next item in the vector 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="qvectoriterator.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="qvectoriterator.html#next">next</a>() advances the iterator to the position between the second and third item, returning the second item; and so on.</p>
 
55
<center><img src="images/javaiterators1.png" /></center><p>Here's how to iterate over the elements in reverse order:</p>
 
56
<pre>&nbsp;   QVectorIterator&lt;float&gt; i(vector);
 
57
    i.toBack();
 
58
    while (i.hasPrevious())
 
59
        cout &lt;&lt; i.previous() &lt;&lt; endl;</pre>
 
60
<p>If you want to find all occurrences of a particular value, use <a href="qvectoriterator.html#findNext">findNext</a>() or <a href="qvectoriterator.html#findPrevious">findPrevious</a>() in a loop.</p>
 
61
<p>Multiple iterators can be used on the same vector. If the vector is modified while a QVectorIterator is active, the QVectorIterator will continue iterating over the original vector, ignoring the modified copy.</p>
 
62
<p>See also <a href="qmutablevectoriterator.html">QMutableVectorIterator</a> and <a href="qvector.html#const_iterator-typedef">QVector::const_iterator</a>.</p>
 
63
<hr />
 
64
<h2>Member Function Documentation</h2>
 
65
<h3 class="fn"><a name="QVectorIterator"></a>QVectorIterator::QVectorIterator ( const <a href="qvector.html">QVector</a>&lt;T&gt; &amp; <i>vector</i> )</h3>
 
66
<p>Constructs an iterator for traversing <i>vector</i>. The iterator is set to be at the front of the vector (before the first item).</p>
 
67
<p>See also <a href="qvectoriterator.html#operator-eq">operator=</a>().</p>
 
68
<h3 class="fn"><a name="findNext"></a>bool QVectorIterator::findNext ( const T &amp; <i>value</i> )</h3>
 
69
<p>Searches for <i>value</i> starting from the current iterator position forward. Returns true if <i>value</i> is found; otherwise returns false.</p>
 
70
<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>
 
71
<p>See also <a href="qvectoriterator.html#findPrevious">findPrevious</a>().</p>
 
72
<h3 class="fn"><a name="findPrevious"></a>bool QVectorIterator::findPrevious ( const T &amp; <i>value</i> )</h3>
 
73
<p>Searches for <i>value</i> starting from the current iterator position backward. Returns true if <i>value</i> is found; otherwise returns false.</p>
 
74
<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>
 
75
<p>See also <a href="qvectoriterator.html#findNext">findNext</a>().</p>
 
76
<h3 class="fn"><a name="hasNext"></a>bool QVectorIterator::hasNext () const</h3>
 
77
<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>
 
78
<p>See also <a href="qvectoriterator.html#hasPrevious">hasPrevious</a>() and <a href="qvectoriterator.html#next">next</a>().</p>
 
79
<h3 class="fn"><a name="hasPrevious"></a>bool QVectorIterator::hasPrevious () const</h3>
 
80
<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>
 
81
<p>See also <a href="qvectoriterator.html#hasNext">hasNext</a>() and <a href="qvectoriterator.html#previous">previous</a>().</p>
 
82
<h3 class="fn"><a name="next"></a>const T &amp; QVectorIterator::next ()</h3>
 
83
<p>Returns the next item and advances the iterator by one position.</p>
 
84
<p>Calling this function on an iterator located at the back of the container leads to undefined results.</p>
 
85
<p>See also <a href="qvectoriterator.html#hasNext">hasNext</a>(), <a href="qvectoriterator.html#peekNext">peekNext</a>(), and <a href="qvectoriterator.html#previous">previous</a>().</p>
 
86
<h3 class="fn"><a name="peekNext"></a>const T &amp; QVectorIterator::peekNext () const</h3>
 
87
<p>Returns the next item without moving the iterator.</p>
 
88
<p>Calling this function on an iterator located at the back of the container leads to undefined results.</p>
 
89
<p>See also <a href="qvectoriterator.html#hasNext">hasNext</a>(), <a href="qvectoriterator.html#next">next</a>(), and <a href="qvectoriterator.html#peekPrevious">peekPrevious</a>().</p>
 
90
<h3 class="fn"><a name="peekPrevious"></a>const T &amp; QVectorIterator::peekPrevious () const</h3>
 
91
<p>Returns the previous item without moving the iterator.</p>
 
92
<p>Calling this function on an iterator located at the front of the container leads to undefined results.</p>
 
93
<p>See also <a href="qvectoriterator.html#hasPrevious">hasPrevious</a>(), <a href="qvectoriterator.html#previous">previous</a>(), and <a href="qvectoriterator.html#peekNext">peekNext</a>().</p>
 
94
<h3 class="fn"><a name="previous"></a>const T &amp; QVectorIterator::previous ()</h3>
 
95
<p>Returns the previous item and moves the iterator back by one position.</p>
 
96
<p>Calling this function on an iterator located at the front of the container leads to undefined results.</p>
 
97
<p>See also <a href="qvectoriterator.html#hasPrevious">hasPrevious</a>(), <a href="qvectoriterator.html#peekPrevious">peekPrevious</a>(), and <a href="qvectoriterator.html#next">next</a>().</p>
 
98
<h3 class="fn"><a name="toBack"></a>void QVectorIterator::toBack ()</h3>
 
99
<p>Moves the iterator to the back of the container (after the last item).</p>
 
100
<p>See also <a href="qvectoriterator.html#toFront">toFront</a>() and <a href="qvectoriterator.html#previous">previous</a>().</p>
 
101
<h3 class="fn"><a name="toFront"></a>void QVectorIterator::toFront ()</h3>
 
102
<p>Moves the iterator to the front of the container (before the first item).</p>
 
103
<p>See also <a href="qvectoriterator.html#toBack">toBack</a>() and <a href="qvectoriterator.html#next">next</a>().</p>
 
104
<h3 class="fn"><a name="operator-eq"></a>QVectorIterator &amp; QVectorIterator::operator= ( const <a href="qvector.html">QVector</a>&lt;T&gt; &amp; <i>vector</i> )</h3>
 
105
<p>Makes the iterator operate on <i>vector</i>. The iterator is set to be at the front of the vector (before the first item).</p>
 
106
<p>See also <a href="qvectoriterator.html#toFront">toFront</a>() and <a href="qvectoriterator.html#toBack">toBack</a>().</p>
 
107
<p /><address><hr /><div align="center">
 
108
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
109
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
110
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
111
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
112
</tr></table></div></address></body>
 
113
</html>