Updated documentation
[libs.git] / docs / html / _iterator_8h-source.html
blobf90854d86ab1c9d7c4dcf42a4c1a262198f2d0ff
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3 <title>LibSylph: Sylph/Core/Iterator.h Source File</title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.5.8 -->
7 <div class="navigation" id="top">
8 <div class="tabs">
9 <ul>
10 <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
11 <li><a href="namespaces.html"><span>Namespaces</span></a></li>
12 <li><a href="classes.html"><span>Classes</span></a></li>
13 <li class="current"><a href="files.html"><span>Files</span></a></li>
14 <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
15 </ul>
16 </div>
17 <div class="tabs">
18 <ul>
19 <li><a href="files.html"><span>File&nbsp;List</span></a></li>
20 </ul>
21 </div>
22 <h1>Sylph/Core/Iterator.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
23 <a name="l00002"></a>00002 <span class="comment"> * LibSylph Class Library</span>
24 <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2009 Frank "SeySayux" Erens &lt;seysayux@gmail.com&gt;</span>
25 <a name="l00004"></a>00004 <span class="comment"> *</span>
26 <a name="l00005"></a>00005 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
27 <a name="l00006"></a>00006 <span class="comment"> * modify it under the terms of the LibSylph Pulbic License as published</span>
28 <a name="l00007"></a>00007 <span class="comment"> * by the LibSylph Developers; either version 1.0 of the License, or</span>
29 <a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
30 <a name="l00009"></a>00009 <span class="comment"> *</span>
31 <a name="l00010"></a>00010 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
32 <a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
33 <a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LibSylph</span>
34 <a name="l00013"></a>00013 <span class="comment"> * Public License for more details.</span>
35 <a name="l00014"></a>00014 <span class="comment"> *</span>
36 <a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the LibSylph Public License</span>
37 <a name="l00016"></a>00016 <span class="comment"> * along with this Library, if not, contact the LibSylph Developers.</span>
38 <a name="l00017"></a>00017 <span class="comment"> * </span>
39 <a name="l00018"></a>00018 <span class="comment"> * Created on 6 december 2008, 17:16</span>
40 <a name="l00019"></a>00019 <span class="comment"> */</span>
41 <a name="l00020"></a>00020
42 <a name="l00021"></a>00021 <span class="preprocessor">#ifndef ITERATOR_H_</span>
43 <a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define ITERATOR_H_</span>
44 <a name="l00023"></a>00023 <span class="preprocessor"></span>
45 <a name="l00024"></a>00024 <span class="preprocessor">#include "Object.h"</span>
46 <a name="l00025"></a>00025 <span class="preprocessor">#include "Exception.h"</span>
47 <a name="l00026"></a>00026 <span class="preprocessor">#include "Iterable.h"</span>
48 <a name="l00027"></a>00027 <span class="preprocessor">#include &lt;iterator&gt;</span>
49 <a name="l00028"></a>00028 <span class="comment">//#include "Foreach.h" -- this line is at the bottom of the file ;)</span>
50 <a name="l00029"></a>00029
51 <a name="l00030"></a>00030 SYLPH_BEGIN_NAMESPACE
52 <a name="l00031"></a>00031 SYLPH_PUBLIC
53 <a name="l00032"></a>00032
54 <a name="l00033"></a>00033 S_CREATE_EXCEPTION(IteratorException);
55 <a name="l00034"></a>00034
56 <a name="l00049"></a>00049 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T, <span class="keyword">class</span> I&gt;
57 <a name="l00050"></a><a class="code" href="class_sylph_1_1_forward_iterator.html">00050</a> <span class="keyword">class </span><a class="code" href="class_sylph_1_1_forward_iterator.html" title="Facade used to simplify usage of forward iterators.">ForwardIterator</a> : <span class="keyword">public</span> <a class="code" href="class_sylph_1_1_object.html" title="The root of all classes.">Object</a> {
58 <a name="l00051"></a>00051 <span class="keyword">public</span>:
59 <a name="l00052"></a>00052 <span class="keyword">typedef</span> std::forward_iterator_tag iterator_category;
60 <a name="l00053"></a>00053 <span class="keyword">typedef</span> T value_type;
61 <a name="l00054"></a>00054 <span class="keyword">typedef</span> ptrdiff_t difference_type;
62 <a name="l00055"></a>00055 <span class="keyword">typedef</span> T* pointer;
63 <a name="l00056"></a>00056 <span class="keyword">typedef</span> T&amp; reference;
64 <a name="l00057"></a>00057 <span class="keyword">typedef</span> <a class="code" href="class_sylph_1_1_forward_iterator.html">ForwardIterator&lt;T, I&gt;</a> <a class="code" href="class_sylph_1_1_forward_iterator.html">self_type</a>;
65 <a name="l00058"></a>00058 <span class="keyword">public</span>:
66 <a name="l00059"></a>00059 <span class="comment">// Implementation of the required functions in terms of the overridable</span>
67 <a name="l00060"></a>00060 <span class="comment">// functions</span>
68 <a name="l00061"></a>00061
69 <a name="l00062"></a>00062 <a class="code" href="class_sylph_1_1_forward_iterator.html" title="Facade used to simplify usage of forward iterators.">ForwardIterator</a>(<span class="keywordtype">bool</span> begin = <span class="keyword">false</span>) : _end_reached_(!begin) {
70 <a name="l00063"></a>00063 }
71 <a name="l00064"></a>00064
72 <a name="l00065"></a>00065 <a class="code" href="class_sylph_1_1_forward_iterator.html" title="Facade used to simplify usage of forward iterators.">ForwardIterator</a>(<span class="keyword">const</span> <a class="code" href="class_sylph_1_1_forward_iterator.html">ForwardIterator&lt;T, I&gt;</a>&amp; other) :
73 <a name="l00066"></a>00066 _end_reached_(other.<a class="code" href="class_sylph_1_1_forward_iterator.html#1448ef46fc3bf3ac2e65ed03eba0cb33" title="Do not use or modify!">_end_reached_</a>) {
74 <a name="l00067"></a>00067 }
75 <a name="l00068"></a>00068
76 <a name="l00069"></a>00069 <span class="keyword">virtual</span> ~<a class="code" href="class_sylph_1_1_forward_iterator.html" title="Facade used to simplify usage of forward iterators.">ForwardIterator</a>() {
77 <a name="l00070"></a>00070 }
78 <a name="l00071"></a>00071
79 <a name="l00072"></a>00072 reference operator*() {
80 <a name="l00073"></a>00073 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException,
81 <a name="l00074"></a>00074 <span class="stringliteral">"Tried to dereference an beyond-end iterator"</span>);
82 <a name="l00075"></a>00075 <span class="keywordflow">return</span> current();
83 <a name="l00076"></a>00076 }
84 <a name="l00077"></a>00077
85 <a name="l00078"></a>00078 <span class="keyword">const</span> reference operator*()<span class="keyword"> const </span>{
86 <a name="l00079"></a>00079 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException,
87 <a name="l00080"></a>00080 <span class="stringliteral">"Tried to dereference an beyond-end iterator"</span>);
88 <a name="l00081"></a>00081 <span class="keywordflow">return</span> current();
89 <a name="l00082"></a>00082 }
90 <a name="l00083"></a>00083
91 <a name="l00084"></a>00084 pointer operator-&gt;() {
92 <a name="l00085"></a>00085 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException,
93 <a name="l00086"></a>00086 <span class="stringliteral">"Tried to dereference an beyond-end iterator"</span>);
94 <a name="l00087"></a>00087 <span class="keywordflow">return</span> &amp;current();
95 <a name="l00088"></a>00088 }
96 <a name="l00089"></a>00089
97 <a name="l00090"></a>00090 <span class="keyword">const</span> pointer operator-&gt;()<span class="keyword"> const </span>{
98 <a name="l00091"></a>00091 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException,
99 <a name="l00092"></a>00092 <span class="stringliteral">"Tried to dereference an beyond-end iterator"</span>);
100 <a name="l00093"></a>00093 <span class="keywordflow">return</span> &amp;current();
101 <a name="l00094"></a>00094 }
102 <a name="l00095"></a>00095
103 <a name="l00096"></a>00096 <span class="keyword">const</span> I &amp; operator++()<span class="keyword"> const </span>{
104 <a name="l00097"></a>00097 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException, <span class="stringliteral">"End of iterator"</span>);
105 <a name="l00098"></a>00098 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasNext()) {
106 <a name="l00099"></a>00099 _end_reached_ = <span class="keyword">true</span>;
107 <a name="l00100"></a>00100 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
108 <a name="l00101"></a>00101 } <span class="keywordflow">else</span> {
109 <a name="l00102"></a>00102 next();
110 <a name="l00103"></a>00103 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
111 <a name="l00104"></a>00104 }
112 <a name="l00105"></a>00105 }
113 <a name="l00106"></a>00106
114 <a name="l00107"></a>00107 I &amp; operator++() {
115 <a name="l00108"></a>00108 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException, <span class="stringliteral">"End of iterator"</span>);
116 <a name="l00109"></a>00109 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasNext()) {
117 <a name="l00110"></a>00110 _end_reached_ = <span class="keyword">true</span>;
118 <a name="l00111"></a>00111 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
119 <a name="l00112"></a>00112 } <span class="keywordflow">else</span> {
120 <a name="l00113"></a>00113 next();
121 <a name="l00114"></a>00114 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
122 <a name="l00115"></a>00115 }
123 <a name="l00116"></a>00116 }
124 <a name="l00117"></a>00117
125 <a name="l00118"></a>00118 <span class="keyword">const</span> I operator++(<span class="keywordtype">int</span>)<span class="keyword"> const </span>{
126 <a name="l00119"></a>00119 I toReturn(*static_cast&lt;I*&gt; (<span class="keyword">this</span>));
127 <a name="l00120"></a>00120 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException, <span class="stringliteral">"End of iterator"</span>);
128 <a name="l00121"></a>00121 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasNext()) {
129 <a name="l00122"></a>00122 _end_reached_ = <span class="keyword">true</span>;
130 <a name="l00123"></a>00123 <span class="keywordflow">return</span> toReturn;
131 <a name="l00124"></a>00124 } <span class="keywordflow">else</span> {
132 <a name="l00125"></a>00125 next();
133 <a name="l00126"></a>00126 <span class="keywordflow">return</span> toReturn;
134 <a name="l00127"></a>00127 }
135 <a name="l00128"></a>00128 }
136 <a name="l00129"></a>00129
137 <a name="l00130"></a>00130 I operator++(<span class="keywordtype">int</span>) {
138 <a name="l00131"></a>00131 I toReturn(*static_cast&lt;I*&gt; (<span class="keyword">this</span>));
139 <a name="l00132"></a>00132 <span class="keywordflow">if</span> (_end_reached_) sthrow(IteratorException, <span class="stringliteral">"End of iterator"</span>);
140 <a name="l00133"></a>00133 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasNext()) {
141 <a name="l00134"></a>00134 _end_reached_ = <span class="keyword">true</span>;
142 <a name="l00135"></a>00135 <span class="keywordflow">return</span> toReturn;
143 <a name="l00136"></a>00136 } <span class="keywordflow">else</span> {
144 <a name="l00137"></a>00137 next();
145 <a name="l00138"></a>00138 <span class="keywordflow">return</span> toReturn;
146 <a name="l00139"></a>00139 }
147 <a name="l00140"></a>00140 }
148 <a name="l00141"></a>00141
149 <a name="l00142"></a>00142 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="namespace_sylph.html#10c329a0349416d794bedf8f67feb25f" title="Compares the two Arrays on equality.">operator==</a>(<span class="keyword">const</span> I&amp; other)<span class="keyword"> const </span>{
150 <a name="l00143"></a>00143 <span class="keywordflow">return</span> (_end_reached_ == other._end_reached_) &amp;&amp; equals(other);
151 <a name="l00144"></a>00144 }
152 <a name="l00145"></a>00145
153 <a name="l00146"></a>00146 <span class="keywordtype">bool</span> operator!=(<span class="keyword">const</span> <a class="code" href="class_sylph_1_1_forward_iterator.html">ForwardIterator&lt;T, I&gt;</a>&amp; other)<span class="keyword"> const </span>{
154 <a name="l00147"></a>00147 <span class="keywordflow">return</span> !(*<span class="keyword">this</span> == other);
155 <a name="l00148"></a>00148 }
156 <a name="l00149"></a>00149 <span class="keywordtype">void</span> construct(<span class="keywordtype">bool</span> begin, <span class="keywordtype">void</span>* obj) {
157 <a name="l00150"></a>00150 construct(begin,obj);
158 <a name="l00151"></a>00151 }
159 <a name="l00152"></a>00152
160 <a name="l00153"></a>00153 <span class="keyword">public</span>:
161 <a name="l00154"></a>00154 <span class="comment">// Overridable functions</span>
162 <a name="l00161"></a>00161 <span class="comment"></span> <span class="keyword">virtual</span> reference current() <span class="keyword">const</span> = 0;
163 <a name="l00167"></a>00167 <span class="keyword">virtual</span> <span class="keywordtype">void</span> next() <span class="keyword">const</span> = 0;
164 <a name="l00175"></a>00175 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> hasNext() <span class="keyword">const</span> = 0;
165 <a name="l00184"></a>00184 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> equals(<span class="keyword">const</span> I&amp; other) <span class="keyword">const</span> = 0;
166 <a name="l00188"></a><a class="code" href="class_sylph_1_1_forward_iterator.html#1448ef46fc3bf3ac2e65ed03eba0cb33">00188</a> <span class="keyword">mutable</span> <span class="keywordtype">bool</span> _end_reached_;
167 <a name="l00189"></a>00189 };
168 <a name="l00190"></a>00190
169 <a name="l00194"></a>00194 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T, <span class="keyword">class</span> I&gt;
170 <a name="l00195"></a><a class="code" href="class_sylph_1_1_bidirectional_iterator.html">00195</a> <span class="keyword">class </span><a class="code" href="class_sylph_1_1_bidirectional_iterator.html">BidirectionalIterator</a> : <span class="keyword">public</span> <a class="code" href="class_sylph_1_1_forward_iterator.html" title="Facade used to simplify usage of forward iterators.">ForwardIterator</a>&lt;T, I&gt; {
171 <a name="l00196"></a>00196 <span class="keyword">public</span>:
172 <a name="l00197"></a>00197 <span class="keyword">typedef</span> std::bidirectional_iterator_tag iterator_category;
173 <a name="l00198"></a>00198 <span class="keyword">typedef</span> <a class="code" href="class_sylph_1_1_forward_iterator.html">ForwardIterator&lt;T, I&gt;</a> <a class="code" href="class_sylph_1_1_forward_iterator.html">super</a>;
174 <a name="l00199"></a>00199 <span class="keyword">typedef</span> <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">BidirectionalIterator&lt;T, I&gt;</a> <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">self_type</a>;
175 <a name="l00200"></a>00200 <span class="keyword">public</span>:
176 <a name="l00201"></a>00201
177 <a name="l00202"></a>00202 <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">BidirectionalIterator</a>(<span class="keywordtype">bool</span> begin = <span class="keyword">false</span>) : <a class="code" href="class_sylph_1_1_forward_iterator.html">super</a>(begin) {
178 <a name="l00203"></a>00203 }
179 <a name="l00204"></a>00204
180 <a name="l00205"></a>00205 <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">BidirectionalIterator</a>(<span class="keyword">const</span> <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">BidirectionalIterator&lt;T, I&gt;</a>&amp; other) :
181 <a name="l00206"></a>00206 <a class="code" href="class_sylph_1_1_forward_iterator.html">ForwardIterator&lt;T, I&gt;</a>(other) {
182 <a name="l00207"></a>00207 }
183 <a name="l00208"></a>00208
184 <a name="l00209"></a>00209 I &amp; operator--() {
185 <a name="l00210"></a>00210 <span class="keywordflow">if</span> (super::_end_reached_) {
186 <a name="l00211"></a>00211 super::_end_reached_ = <span class="keyword">false</span>;
187 <a name="l00212"></a>00212 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
188 <a name="l00213"></a>00213 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasPrevious()) {
189 <a name="l00214"></a>00214 sthrow(IteratorException, <span class="stringliteral">"Begin of iterator"</span>);
190 <a name="l00215"></a>00215 } <span class="keywordflow">else</span> {
191 <a name="l00216"></a>00216 previous();
192 <a name="l00217"></a>00217 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
193 <a name="l00218"></a>00218 }
194 <a name="l00219"></a>00219 }
195 <a name="l00220"></a>00220
196 <a name="l00221"></a>00221 <span class="keyword">const</span> I &amp; operator--()<span class="keyword"> const </span>{
197 <a name="l00222"></a>00222 <span class="keywordflow">if</span> (super::_end_reached_) {
198 <a name="l00223"></a>00223 super::_end_reached_ = <span class="keyword">false</span>;
199 <a name="l00224"></a>00224 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
200 <a name="l00225"></a>00225 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasPrevious()) {
201 <a name="l00226"></a>00226 sthrow(IteratorException, <span class="stringliteral">"Begin of iterator"</span>);
202 <a name="l00227"></a>00227 } <span class="keywordflow">else</span> {
203 <a name="l00228"></a>00228 previous();
204 <a name="l00229"></a>00229 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span> (<span class="keyword">this</span>);
205 <a name="l00230"></a>00230 }
206 <a name="l00231"></a>00231 }
207 <a name="l00232"></a>00232
208 <a name="l00233"></a>00233 I operator--(<span class="keywordtype">int</span>) {
209 <a name="l00234"></a>00234 I toReturn(*static_cast&lt;I*&gt; (<span class="keyword">this</span>));
210 <a name="l00235"></a>00235 <span class="keywordflow">if</span> (super::_end_reached_) {
211 <a name="l00236"></a>00236 super::_end_reached_ = <span class="keyword">false</span>;
212 <a name="l00237"></a>00237 <span class="keywordflow">return</span> toReturn;
213 <a name="l00238"></a>00238 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasPrevious()) {
214 <a name="l00239"></a>00239 sthrow(IteratorException, <span class="stringliteral">"Begin of iterator"</span>);
215 <a name="l00240"></a>00240 } <span class="keywordflow">else</span> {
216 <a name="l00241"></a>00241 previous();
217 <a name="l00242"></a>00242 <span class="keywordflow">return</span> toReturn;
218 <a name="l00243"></a>00243 }
219 <a name="l00244"></a>00244 }
220 <a name="l00245"></a>00245
221 <a name="l00246"></a>00246 <span class="keyword">const</span> I operator--(<span class="keywordtype">int</span>)<span class="keyword"> const </span>{
222 <a name="l00247"></a>00247 I toReturn(*static_cast&lt;I*&gt; (<span class="keyword">this</span>));
223 <a name="l00248"></a>00248 <span class="keywordflow">if</span> (super::_end_reached_) {
224 <a name="l00249"></a>00249 super::_end_reached_ = <span class="keyword">false</span>;
225 <a name="l00250"></a>00250 <span class="keywordflow">return</span> toReturn;
226 <a name="l00251"></a>00251 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!hasPrevious()) {
227 <a name="l00252"></a>00252 sthrow(IteratorException, <span class="stringliteral">"Begin of iterator"</span>);
228 <a name="l00253"></a>00253 } <span class="keywordflow">else</span> {
229 <a name="l00254"></a>00254 previous();
230 <a name="l00255"></a>00255 <span class="keywordflow">return</span> toReturn;
231 <a name="l00256"></a>00256 }
232 <a name="l00257"></a>00257 }
233 <a name="l00258"></a>00258
234 <a name="l00259"></a>00259 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="namespace_sylph.html#10c329a0349416d794bedf8f67feb25f" title="Compares the two Arrays on equality.">operator==</a>(<span class="keyword">const</span> I&amp; other)<span class="keyword"> const </span>{
235 <a name="l00260"></a>00260 <span class="keywordflow">return</span> ((super::_end_reached_ == other._end_reached_) ||
236 <a name="l00261"></a>00261 (hasPrevious() == other.hasPrevious()))
237 <a name="l00262"></a>00262 &amp;&amp; super::operator==(other);
238 <a name="l00263"></a>00263 }
239 <a name="l00264"></a>00264 <span class="keyword">public</span>:
240 <a name="l00265"></a>00265 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> hasPrevious() <span class="keyword">const</span> = 0;
241 <a name="l00266"></a>00266 <span class="keyword">virtual</span> <span class="keywordtype">void</span> previous() <span class="keyword">const</span> = 0;
242 <a name="l00267"></a>00267 };
243 <a name="l00268"></a>00268
244 <a name="l00272"></a>00272 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T, <span class="keyword">class</span> I&gt;
245 <a name="l00273"></a><a class="code" href="class_sylph_1_1_random_access_iterator.html">00273</a> <span class="keyword">class </span><a class="code" href="class_sylph_1_1_random_access_iterator.html">RandomAccessIterator</a> : <span class="keyword">public</span> <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">BidirectionalIterator</a>&lt;T, I&gt; {
246 <a name="l00274"></a>00274 <span class="keyword">public</span>:
247 <a name="l00275"></a>00275 <span class="keyword">typedef</span> std::random_access_iterator_tag iterator_category;
248 <a name="l00276"></a>00276 <span class="keyword">typedef</span> <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">BidirectionalIterator&lt;T, I&gt;</a> <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">super</a>;
249 <a name="l00277"></a>00277 <span class="keyword">typedef</span> <a class="code" href="class_sylph_1_1_random_access_iterator.html">RandomAccessIterator&lt;T, I&gt;</a> <a class="code" href="class_sylph_1_1_random_access_iterator.html">self_type</a>;
250 <a name="l00278"></a>00278 <span class="keyword">public</span>:
251 <a name="l00279"></a>00279
252 <a name="l00280"></a>00280 <a class="code" href="class_sylph_1_1_random_access_iterator.html">RandomAccessIterator</a>(<span class="keywordtype">bool</span> begin = <span class="keyword">false</span>) : <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">super</a>(begin) {}
253 <a name="l00281"></a>00281
254 <a name="l00282"></a>00282 <a class="code" href="class_sylph_1_1_random_access_iterator.html">RandomAccessIterator</a>(<span class="keyword">const</span> <a class="code" href="class_sylph_1_1_random_access_iterator.html">self_type</a>&amp; other) :
255 <a name="l00283"></a>00283 <a class="code" href="class_sylph_1_1_bidirectional_iterator.html">super</a>(other) {
256 <a name="l00284"></a>00284 }
257 <a name="l00285"></a>00285
258 <a name="l00286"></a>00286 I &amp; operator+=(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i) {
259 <a name="l00287"></a>00287 ptrdiff_t diff = i;
260 <a name="l00288"></a>00288 <span class="keywordflow">if</span> (i &gt;= 0) <span class="keywordflow">while</span> (diff--) ++(*this);
261 <a name="l00289"></a>00289 <span class="keywordflow">else</span> <span class="keywordflow">while</span> (diff++) --(*this);
262 <a name="l00290"></a>00290 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span>(<span class="keyword">this</span>);
263 <a name="l00291"></a>00291 }
264 <a name="l00292"></a>00292
265 <a name="l00293"></a>00293 <span class="keyword">const</span> I &amp; operator+=(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i)<span class="keyword"> const </span>{
266 <a name="l00294"></a>00294 ptrdiff_t diff = i;
267 <a name="l00295"></a>00295 <span class="keywordflow">if</span> (i &gt;= 0) <span class="keywordflow">while</span> (diff--) ++(*this);
268 <a name="l00296"></a>00296 <span class="keywordflow">else</span> <span class="keywordflow">while</span> (diff++) --(*this);
269 <a name="l00297"></a>00297 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span><span class="keyword">const </span>I*<span class="keyword">&gt;</span>(<span class="keyword">this</span>);
270 <a name="l00298"></a>00298 }
271 <a name="l00299"></a>00299
272 <a name="l00300"></a>00300 I &amp; operator-=(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i) {
273 <a name="l00301"></a>00301 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span>(&amp;(*<span class="keyword">this</span> += -i));
274 <a name="l00302"></a>00302 }
275 <a name="l00303"></a>00303
276 <a name="l00304"></a>00304 <span class="keyword">const</span> I &amp; operator-=(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i)<span class="keyword"> const </span>{
277 <a name="l00305"></a>00305 <span class="keywordflow">return</span> &amp;*<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span>(&amp;(*<span class="keyword">this</span> += -i));
278 <a name="l00306"></a>00306 }
279 <a name="l00307"></a>00307
280 <a name="l00308"></a>00308 <span class="keyword">const</span> I operator+(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i)<span class="keyword"> const </span>{
281 <a name="l00309"></a>00309 I toReturn(*static_cast&lt;const I*&gt;(<span class="keyword">this</span>));
282 <a name="l00310"></a>00310 <span class="keywordflow">return</span> toReturn += i;
283 <a name="l00311"></a>00311 }
284 <a name="l00312"></a>00312
285 <a name="l00313"></a>00313 I operator-(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i) {
286 <a name="l00314"></a>00314 <span class="keywordflow">return</span> *<span class="keyword">static_cast&lt;</span>I*<span class="keyword">&gt;</span>(&amp;(*<span class="keyword">this</span> + -i));
287 <a name="l00315"></a>00315 }
288 <a name="l00316"></a>00316
289 <a name="l00317"></a>00317 ptrdiff_t operator-(<span class="keyword">const</span> I&amp; other)<span class="keyword"> const </span>{
290 <a name="l00318"></a>00318 <span class="keywordflow">if</span> (*<span class="keyword">this</span> &gt; other) <span class="keywordflow">return</span> this-&gt;currentIndex() - other.currentIndex();
291 <a name="l00319"></a>00319 <span class="keywordflow">else</span> <span class="keywordflow">return</span> other.currentIndex() - this-&gt;currentIndex();
292 <a name="l00320"></a>00320 }
293 <a name="l00321"></a>00321
294 <a name="l00322"></a>00322 <span class="keyword">const</span> <span class="keyword">typename</span> super::reference operator[](<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> offset)<span class="keyword"> const </span>{
295 <a name="l00323"></a>00323 <span class="keywordflow">return</span> *(*<span class="keyword">this</span> +offset);
296 <a name="l00324"></a>00324 }
297 <a name="l00325"></a>00325
298 <a name="l00326"></a>00326 <span class="keyword">typename</span> super::reference operator[](<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> offset) {
299 <a name="l00327"></a>00327 <span class="keywordflow">return</span> *(*<span class="keyword">this</span> +offset);
300 <a name="l00328"></a>00328 }
301 <a name="l00329"></a>00329
302 <a name="l00330"></a>00330 <span class="keywordtype">bool</span> operator&gt;(<span class="keyword">const</span> I&amp; other)<span class="keyword"> const </span>{
303 <a name="l00331"></a>00331 <span class="keywordflow">return</span> this-&gt;currentIndex() &gt; other.currentIndex();
304 <a name="l00332"></a>00332 }
305 <a name="l00333"></a>00333
306 <a name="l00334"></a>00334 <span class="keywordtype">bool</span> <a class="code" href="namespace_sylph.html#049ea1ef37b015ca0292637e6d2e3ffa" title="Compares the two Arrays.">operator&lt;</a>(<span class="keyword">const</span> I&amp; other)<span class="keyword"> const </span>{
307 <a name="l00335"></a>00335 <span class="keywordflow">return</span> this-&gt;currentIndex() &lt; other.currentIndex();
308 <a name="l00336"></a>00336 }
309 <a name="l00337"></a>00337
310 <a name="l00338"></a>00338 <span class="keywordtype">bool</span> operator&gt;=(<span class="keyword">const</span> I&amp; other)<span class="keyword"> const </span>{
311 <a name="l00339"></a>00339
312 <a name="l00340"></a>00340 <span class="keywordflow">return</span> this-&gt;currentIndex() &gt;= other.currentIndex();
313 <a name="l00341"></a>00341 }
314 <a name="l00342"></a>00342
315 <a name="l00343"></a>00343 <span class="keywordtype">bool</span> operator&lt;=(<span class="keyword">const</span> I&amp; other)<span class="keyword"> const </span>{
316 <a name="l00344"></a>00344 <span class="keywordflow">return</span> this-&gt;currentIndex() &lt;= other.currentIndex();
317 <a name="l00345"></a>00345 }
318 <a name="l00346"></a>00346
319 <a name="l00347"></a>00347 <span class="keyword">public</span>:
320 <a name="l00348"></a>00348 <span class="keyword">virtual</span> idx_t currentIndex() <span class="keyword">const</span> = 0;
321 <a name="l00349"></a>00349 <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> length() <span class="keyword">const</span> = 0;
322 <a name="l00350"></a>00350 };
323 <a name="l00351"></a>00351
324 <a name="l00352"></a>00352 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T, <span class="keyword">class</span> I&gt;
325 <a name="l00353"></a>00353 I operator+(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i, <span class="keyword">const</span> I itr) {
326 <a name="l00354"></a>00354 <span class="keywordflow">return</span> itr + i;
327 <a name="l00355"></a>00355 }
328 <a name="l00356"></a>00356
329 <a name="l00363"></a>00363 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Iter&gt;
330 <a name="l00364"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html">00364</a> <span class="keyword">class </span><a class="code" href="class_sylph_1_1_sylph_iterator.html" title="SylphIterator provides a easier-to-use wrapper around STL iterators.">SylphIterator</a> : <span class="keyword">public</span> <span class="keyword">virtual</span> <a class="code" href="class_sylph_1_1_object.html" title="The root of all classes.">Object</a> {
331 <a name="l00365"></a>00365 <span class="keyword">public</span>:
332 <a name="l00366"></a>00366
333 <a name="l00374"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#6f74149cc4a6e7a057f51c33ce26709b">00374</a> <span class="keyword">inline</span> <a class="code" href="class_sylph_1_1_sylph_iterator.html#6f74149cc4a6e7a057f51c33ce26709b" title="Creates a new Iterator from an STL-iterator.">SylphIterator</a>(Iter &amp; it) : itr(it) {
334 <a name="l00375"></a>00375 }
335 <a name="l00376"></a>00376
336 <a name="l00380"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#550c350d2d7744a7fd6af44c716fb846">00380</a> <span class="keyword">inline</span> <span class="keyword">virtual</span> <a class="code" href="class_sylph_1_1_sylph_iterator.html#550c350d2d7744a7fd6af44c716fb846" title="Destructor.">~SylphIterator</a>() {
337 <a name="l00381"></a>00381 }
338 <a name="l00382"></a>00382
339 <a name="l00387"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#24c0cef4d514f69fec6577f55dc93799">00387</a> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="class_sylph_1_1_sylph_iterator.html#24c0cef4d514f69fec6577f55dc93799" title="Checks if this iterator has any more entries in forward direction.">hasNext</a>()<span class="keyword"> const </span>{
340 <a name="l00388"></a>00388 <span class="keywordflow">return</span> itr.hasNext();
341 <a name="l00389"></a>00389 }
342 <a name="l00390"></a>00390
343 <a name="l00397"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#5cafc479cfa2742212ed80b4e1b03a4e">00397</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">typename</span> Iter::reference <a class="code" href="class_sylph_1_1_sylph_iterator.html#5cafc479cfa2742212ed80b4e1b03a4e" title="Returns the next entry in the forward direction and moves the iterator one place...">next</a>()<span class="keyword"> const </span>{
344 <a name="l00398"></a>00398 <span class="keyword">typename</span> Iter::reference toReturn = *itr;
345 <a name="l00399"></a>00399 ++itr;
346 <a name="l00400"></a>00400 <span class="keywordflow">return</span> toReturn;
347 <a name="l00401"></a>00401 }
348 <a name="l00402"></a>00402
349 <a name="l00409"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#42de0477358aa16970ef257d041047e3">00409</a> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="class_sylph_1_1_sylph_iterator.html#42de0477358aa16970ef257d041047e3" title="Checks if this iterator has any more entries in backward direction.">hasPrevious</a>()<span class="keyword"> const </span>{
350 <a name="l00410"></a>00410 <span class="keywordflow">return</span> itr.hasPrevious();
351 <a name="l00411"></a>00411 }
352 <a name="l00412"></a>00412
353 <a name="l00421"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#3277c644458465f50deb6713d308309c">00421</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keyword">typename</span> Iter::reference <a class="code" href="class_sylph_1_1_sylph_iterator.html#3277c644458465f50deb6713d308309c" title="Returns the next entry in the backward direction and moves the iterator one place...">previous</a>()<span class="keyword"> const </span>{
354 <a name="l00422"></a>00422 --itr;
355 <a name="l00423"></a>00423 <span class="keywordflow">return</span> *itr;
356 <a name="l00424"></a>00424 }
357 <a name="l00425"></a>00425
358 <a name="l00433"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#da51b20d4f61fb1728e19100d6da0ba2">00433</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="class_sylph_1_1_sylph_iterator.html#da51b20d4f61fb1728e19100d6da0ba2" title="Moves the Iterator to the place &amp;quot;before&amp;quot; the first item, that is, it gives...">front</a>()<span class="keyword"> const </span>{
359 <a name="l00434"></a>00434 <span class="keywordflow">while</span> (itr.hasPrevious()) --itr;
360 <a name="l00435"></a>00435 }
361 <a name="l00436"></a>00436
362 <a name="l00445"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#70994ef8bc524a231b6852f3ce05b94b">00445</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="class_sylph_1_1_sylph_iterator.html#70994ef8bc524a231b6852f3ce05b94b" title="Moves the Iterator to the place &amp;quot;after&amp;quot; the last item, that is, it gives...">back</a>()<span class="keyword"> const </span>{
363 <a name="l00446"></a>00446 <span class="keywordflow">while</span> (itr.hasNext()) ++itr;
364 <a name="l00447"></a>00447 }
365 <a name="l00448"></a>00448
366 <a name="l00456"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#fe653e20cc020e9fea58b2e0b8be8ab9">00456</a> <span class="keyword">virtual</span> std::idx_t <a class="code" href="class_sylph_1_1_sylph_iterator.html#fe653e20cc020e9fea58b2e0b8be8ab9" title="Returns the next index of the Iterable in the forward direction.">nextIndex</a>()<span class="keyword"> const </span>{
367 <a name="l00457"></a>00457 <span class="keywordflow">return</span> itr.currentIndex();
368 <a name="l00458"></a>00458 }
369 <a name="l00459"></a>00459
370 <a name="l00467"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#9966f87c9c01a9a13523a34568989124">00467</a> <span class="keyword">virtual</span> std::idx_t <a class="code" href="class_sylph_1_1_sylph_iterator.html#9966f87c9c01a9a13523a34568989124" title="Returns the next index of the Iterable in the backward direction.">previousIndex</a>()<span class="keyword"> const </span>{
371 <a name="l00468"></a>00468 <span class="keywordflow">return</span> itr.currentIndex() - 1;
372 <a name="l00469"></a>00469 }
373 <a name="l00470"></a>00470
374 <a name="l00476"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#dea685b03c30249496bdd82f303323d5">00476</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <span class="keyword">set</span>(<span class="keyword">typename</span> Iter::reference t) {
375 <a name="l00477"></a>00477 *itr = t;
376 <a name="l00478"></a>00478 }
377 <a name="l00479"></a>00479
378 <a name="l00483"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#2f46f4a09608eb6d53e4148f23805b6f">00483</a> <span class="keyword">const</span> <span class="keyword">typename</span> Iter::reference <a class="code" href="class_sylph_1_1_sylph_iterator.html#2f46f4a09608eb6d53e4148f23805b6f" title="Synonymous for next().">operator++</a>()<span class="keyword"> const </span>{
379 <a name="l00484"></a>00484 <span class="keywordflow">return</span> next();
380 <a name="l00485"></a>00485 }
381 <a name="l00486"></a>00486
382 <a name="l00490"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#62ec59cb349ca1e92fbcbe75176d5c4f">00490</a> <span class="keyword">const</span> <span class="keyword">typename</span> Iter::reference <a class="code" href="class_sylph_1_1_sylph_iterator.html#62ec59cb349ca1e92fbcbe75176d5c4f" title="Synonymous for previous().">operator--</a>()<span class="keyword"> const </span>{
383 <a name="l00491"></a>00491 <span class="keywordflow">return</span> previous();
384 <a name="l00492"></a>00492 }
385 <a name="l00493"></a>00493
386 <a name="l00498"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#3ea8e165a6e4438fcb82f86117f0b16d">00498</a> <span class="keyword">const</span> <span class="keyword">typename</span> Iter::reference <a class="code" href="class_sylph_1_1_sylph_iterator.html#3ea8e165a6e4438fcb82f86117f0b16d" title="Synoynmous for next().">operator++</a>(<span class="keywordtype">int</span>)<span class="keyword"> const </span>{
387 <a name="l00499"></a>00499 <span class="keywordflow">return</span> next();
388 <a name="l00500"></a>00500 }
389 <a name="l00501"></a>00501
390 <a name="l00506"></a><a class="code" href="class_sylph_1_1_sylph_iterator.html#40260b5a6935ec8b2403680e34e9e91f">00506</a> <span class="keyword">const</span> <span class="keyword">typename</span> Iter::reference <a class="code" href="class_sylph_1_1_sylph_iterator.html#40260b5a6935ec8b2403680e34e9e91f" title="Synonymous for previous().">operator--</a>(<span class="keywordtype">int</span>)<span class="keyword"> const </span>{
391 <a name="l00507"></a>00507 <span class="keywordflow">return</span> previous();
392 <a name="l00508"></a>00508 }
393 <a name="l00509"></a>00509 <span class="keyword">private</span>:
394 <a name="l00510"></a>00510 Iter itr;
395 <a name="l00511"></a>00511 };
396 <a name="l00512"></a>00512
397 <a name="l00513"></a>00513 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Collection&gt;
398 <a name="l00514"></a>00514 <span class="keyword">const</span> SylphIterator&lt;typename Collection::const_iterator&gt; SylphItr(
399 <a name="l00515"></a>00515 <span class="keyword">const</span> Collection&amp; col) {
400 <a name="l00516"></a>00516 <span class="keywordflow">return</span> SylphIterator&lt;typename Collection::const_iterator &gt; (col.begin());
401 <a name="l00517"></a>00517 }
402 <a name="l00518"></a>00518
403 <a name="l00519"></a>00519 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Collection&gt;
404 <a name="l00520"></a>00520 SylphIterator&lt;typename Collection::iterator&gt; SylphMitr(Collection &amp; col) {
405 <a name="l00521"></a>00521 <span class="keywordflow">return</span> SylphIterator&lt;typename Collection::iterator &gt; (col.begin());
406 <a name="l00522"></a>00522 }
407 <a name="l00523"></a>00523
408 <a name="l00524"></a>00524
409 <a name="l00525"></a>00525 SYLPH_END_NAMESPACE
410 <a name="l00526"></a>00526
411 <a name="l00527"></a>00527 <span class="comment">// Previously defined here, now defined elsewhere</span>
412 <a name="l00528"></a>00528 <span class="preprocessor">#include "Foreach.h"</span>
413 <a name="l00529"></a>00529
414 <a name="l00530"></a>00530 <span class="preprocessor">#endif </span><span class="comment">/* ITERATOR_H_ */</span>
415 <a name="l00531"></a>00531
416 </pre></div></div>
417 <hr size="1" class="unhidden"><address style="text-align: right;"><small>
418 Documentation for LibSylph by Doxygen
419 </body>
420 </html>