summaryrefslogtreecommitdiff
path: root/doc/html/eof_iterator.html
blob: f078ddd1492ded0c5641fc1b0f1a2789d0ebef3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Class template eof_iterator</title>
<link rel="stylesheet" href="boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="index.html" title="The Boost C++ Libraries">
<link rel="up" href="program_options/reference.html#id2338601" title="Header &lt;boost/program_options/eof_iterator.hpp&gt;">
<link rel="prev" href="environment_iterator.html" title="Class environment_iterator">
<link rel="next" href="error.html" title="Class error">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%">
<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td>
<td align="center"><a href="../../index.htm">Home</a></td>
<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="../../people/people.htm">People</a></td>
<td align="center"><a href="../../more/faq.htm">FAQ</a></td>
<td align="center"><a href="../../more/index.htm">More</a></td>
</table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="environment_iterator.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="program_options/reference.html#id2338601"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="error.html"><img src="images/next.png" alt="Next"></a>
</div>
<div class="refentry" lang="en">
<a name="eof_iterator"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template eof_iterator</span></h2>
<p>boost::eof_iterator &#8212; </p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Derived, <span class="bold"><strong>typename</strong></span> ValueType&gt; 
<span class="bold"><strong>class</strong></span> eof_iterator {
<span class="bold"><strong>public</strong></span>:
  <span class="emphasis"><em>// <a href="eof_iterator.html#eof_iteratorconstruct-copy-destruct">construct/copy/destruct</a></em></span>
  <a href="eof_iterator.html#id2380484-bb">eof_iterator</a>();

  <span class="emphasis"><em>// <a href="eof_iterator.html#id2380480-bb">public member functions</a></em></span>

  <span class="emphasis"><em>// <a href="eof_iterator.html#id2380486-bb">protected member functions</a></em></span>
  <span class="type">ValueType &amp;</span> <a href="eof_iterator.html#id2401200-bb">value</a>() ;
  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="eof_iterator.html#id2360641-bb">found_eof</a>() ;

  <span class="emphasis"><em>// <a href="eof_iterator.html#id2354668-bb">private member functions</a></em></span>
  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="eof_iterator.html#id2354672-bb">increment</a>() ;
  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="eof_iterator.html#id2479389-bb">equal</a>(<span class="bold"><strong>const</strong></span> <a href="eof_iterator.html" title="Class template eof_iterator">eof_iterator</a> &amp;) <span class="bold"><strong>const</strong></span>;
  <span class="type"><span class="bold"><strong>const</strong></span> ValueType &amp;</span> <a href="eof_iterator.html#id2351288-bb">dereference</a>() <span class="bold"><strong>const</strong></span>;
};</pre></div>
<div class="refsect1" lang="en">
<a name="id2717617"></a><h2>Description</h2>
<p>The 'eof_iterator' class is useful for constructing forward iterators in cases where iterator extract data from some source and it's easy to detect 'eof' -- i.e. the situation where there's no data. One apparent example is reading lines from a file.</p>
<p>Implementing such iterators using 'iterator_facade' directly would require to create class with three core operation, a couple of constructors. When using 'eof_iterator', the derived class should define only one method to get new value, plus a couple of constructors.</p>
<p>The basic idea is that iterator has 'eof' bit. Two iterators are equal only if both have their 'eof' bits set. The 'get' method either obtains the new value or sets the 'eof' bit.</p>
<p>Specifically, derived class should define:</p>
<p>1. A default constructor, which creates iterator with 'eof' bit set. The constructor body should call 'found_eof' method defined here. 2. Some other constructor. It should initialize some 'data pointer' used in iterator operation and then call 'get'. 3. The 'get' method. It should operate this way:</p>
<div class="itemizedlist"><ul type="disc">
<li><p>look at some 'data pointer' to see if new element is available; if not, it should call 'found_eof'.</p></li>
<li><p>extract new element and store it at location returned by the 'value' method.</p></li>
<li><p>advance the data pointer.</p></li>
</ul></div>
<p>Essentially, the 'get' method has the functionality of both 'increment' and 'dereference'. It's very good for the cases where data extraction implicitly moves data pointer, like for stream operation. </p>
<div class="refsect2" lang="en">
<a name="id2717669"></a><h3>
<a name="eof_iteratorconstruct-copy-destruct"></a><code class="computeroutput">eof_iterator</code> construct/copy/destruct</h3>
<div class="orderedlist"><ol type="1"><li><pre class="literallayout"><a name="id2380484-bb"></a>eof_iterator();</pre></li></ol></div>
</div>
<div class="refsect2" lang="en">
<a name="id2717701"></a><h3>
<a name="id2380480-bb"></a><code class="computeroutput">eof_iterator</code> public member functions</h3>
<div class="orderedlist"><ol type="1"></ol></div>
</div>
<div class="refsect2" lang="en">
<a name="id2717720"></a><h3>
<a name="id2380486-bb"></a><code class="computeroutput">eof_iterator</code> protected member functions</h3>
<div class="orderedlist"><ol type="1">
<li>
<pre class="literallayout"><span class="type">ValueType &amp;</span> <a name="id2401200-bb"></a>value() ;</pre>
<p>Returns the reference which should be used by derived class to store the next value. </p>
</li>
<li>
<pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2360641-bb"></a>found_eof() ;</pre>
<p>Should be called by derived class to indicate that it can't produce next element. </p>
</li>
</ol></div>
</div>
<div class="refsect2" lang="en">
<a name="id2717784"></a><h3>
<a name="id2354668-bb"></a><code class="computeroutput">eof_iterator</code> private member functions</h3>
<div class="orderedlist"><ol type="1">
<li><pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2354672-bb"></a>increment() ;</pre></li>
<li><pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2479389-bb"></a>equal(<span class="bold"><strong>const</strong></span> <a href="eof_iterator.html" title="Class template eof_iterator">eof_iterator</a> &amp; other) <span class="bold"><strong>const</strong></span>;</pre></li>
<li><pre class="literallayout"><span class="type"><span class="bold"><strong>const</strong></span> ValueType &amp;</span> <a name="id2351288-bb"></a>dereference() <span class="bold"><strong>const</strong></span>;</pre></li>
</ol></div>
</div>
</div>
</div>
<table width="100%"><tr>
<td align="left"></td>
<td align="right"><small>Copyright © 2002-2004 Vladimir Prus</small></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="environment_iterator.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="program_options/reference.html#id2338601"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="error.html"><img src="images/next.png" alt="Next"></a>
</div>
</body>
</html>