Crazy Eddie's GUI System 0.8.7
IteratorBase.h
1/***********************************************************************
2 created: 26/7/2004
3 author: Paul D Turner
4
5 purpose: Defines interface for base iterator class
6*************************************************************************/
7/***************************************************************************
8 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29/*************************************************************************
30 This is based somewhat on MapIterator in the Ogre library (www.ogre3d.org)
31*************************************************************************/
32#ifndef _CEGUIIteratorBase_h_
33#define _CEGUIIteratorBase_h_
34
35#include "CEGUI/Base.h"
36
37
38// Start of CEGUI namespace section
39namespace CEGUI
40{
45template<typename T, typename V = typename T::value_type>
47{
48public:
49 typedef V value_type;
50
61 ConstBaseIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
62 d_currIter(start_iter),
63 d_startIter(start_iter),
64 d_endIter(end_iter)
65 {
66 }
67
68
73 virtual ~ConstBaseIterator(void)
74 {
75 }
76
77
86 {
87 }
88
89
95 {
98 d_endIter = rhs.d_endIter;
99
100 return *this;
101 }
102
103
108 virtual value_type getCurrentValue(void) const = 0;
109
110
115 bool isAtEnd(void) const
116 {
117 return d_currIter == d_endIter;
118 }
119
120
125 bool isAtStart(void) const
126 {
127 return d_currIter == d_startIter;
128 }
129
134 bool operator==(const ConstBaseIterator<T, V>& rhs) const
135 {
136 return d_currIter == rhs.d_currIter;
137 }
138
139
144 bool operator!=(const ConstBaseIterator<T, V>& rhs) const
145 {
146 return !operator==(rhs);
147 }
148
149
154 value_type operator*() const
155 {
156 return getCurrentValue();
157 }
158
159
164 void toStart(void)
165 {
167 }
168
169
174 void toEnd(void)
175 {
177 }
178
179
180protected:
181 /*************************************************************************
182 No default construction available
183 *************************************************************************/
184 ConstBaseIterator(void) {}
185
186 /*************************************************************************
187 Implementation Data
188 *************************************************************************/
189 typename T::const_iterator d_currIter;
190 typename T::const_iterator d_startIter;
191 typename T::const_iterator d_endIter;
192};
193
195template<class T>
196class ConstMapIterator : public ConstBaseIterator<T, typename T::mapped_type>
197{
198public:
199 ConstMapIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
201 {}
202
203 typename ConstBaseIterator<T, typename T::mapped_type>::value_type
205 {
206 return this->d_currIter->second;
207 }
208
213 typename T::key_type getCurrentKey() const
214 {
215 return this->d_currIter->first;
216 }
217
226 {
229
230 return *this;
231 }
232
241 {
244
245 return *this;
246 }
247
256 {
257 ConstMapIterator<T> tmp = *this;
258 ++*this;
259
260 return tmp;
261 }
262
271 {
272 ConstMapIterator<T> tmp = *this;
273 --*this;
274
275 return tmp;
276 }
277
278protected:
279 /*************************************************************************
280 No default construction available
281 *************************************************************************/
282 ConstMapIterator(void) {}
283};
284
286template<class T>
288{
289public:
290 ConstVectorIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
291 ConstBaseIterator<T>(start_iter, end_iter)
292 {}
293
294 typename ConstBaseIterator<T>::value_type
296 {
297 return *this->d_currIter;
298 }
299
308 {
311
312 return *this;
313 }
314
323 {
326
327 return *this;
328 }
329
338 {
339 ConstVectorIterator<T> tmp = *this;
340 ++*this;
341
342 return tmp;
343 }
344
353 {
354 ConstVectorIterator<T> tmp = *this;
355 --*this;
356
357 return tmp;
358 }
359
360protected:
361 /*************************************************************************
362 No default construction available
363 *************************************************************************/
364 ConstVectorIterator(void) {}
365};
366
367} // End of CEGUI namespace section
368
369
370#endif // end of guard _CEGUIIteratorBase_h_
Base class constant iterator used to offer iteration over various collections within the system.
Definition: IteratorBase.h:47
virtual value_type getCurrentValue(void) const =0
Return the value for the item at the current iterator position.
void toStart(void)
Set the iterator current position to the start position.
Definition: IteratorBase.h:164
bool operator==(const ConstBaseIterator< T, V > &rhs) const
Compares two iterators. Return true if the current position of both iterators are equivalent.
Definition: IteratorBase.h:134
virtual ~ConstBaseIterator(void)
ConstBaseIterator destructor.
Definition: IteratorBase.h:73
bool operator!=(const ConstBaseIterator< T, V > &rhs) const
Compares two iterators. Return true if the current position of the iterators are different.
Definition: IteratorBase.h:144
ConstBaseIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter)
ConstBaseIterator constructor.
Definition: IteratorBase.h:61
ConstBaseIterator(const ConstBaseIterator< T, V > &org)
ConstBaseIterator copy constructor.
Definition: IteratorBase.h:82
ConstBaseIterator< T, V > & operator=(const ConstBaseIterator< T, V > &rhs)
ConstBaseIterator assignment operator.
Definition: IteratorBase.h:94
void toEnd(void)
Set the iterator current position to the end position.
Definition: IteratorBase.h:174
bool isAtEnd(void) const
Return whether the current iterator position is at the end of the iterators range.
Definition: IteratorBase.h:115
T::const_iterator d_startIter
'real' iterator describing the start position within the collection (or what we were told was the sta...
Definition: IteratorBase.h:190
T::const_iterator d_currIter
'real' iterator describing the current position within the collection.
Definition: IteratorBase.h:189
value_type operator*() const
Return the value for the current iterator position.
Definition: IteratorBase.h:154
T::const_iterator d_endIter
'real' iterator describing the end position within the collection (or what we were told was the end).
Definition: IteratorBase.h:191
bool isAtStart(void) const
Return whether the current iterator position is at the start of the iterators range.
Definition: IteratorBase.h:125
iterator class for maps
Definition: IteratorBase.h:197
ConstMapIterator< T > & operator++()
Increase the iterator position (prefix increment).
Definition: IteratorBase.h:225
ConstMapIterator< T > operator++(int)
Increase the iterator position (postfix increment).
Definition: IteratorBase.h:255
T::key_type getCurrentKey() const
Return the key for the item at the current iterator position.
Definition: IteratorBase.h:213
ConstMapIterator< T > & operator--()
Decrease the iterator position (prefix decrement).
Definition: IteratorBase.h:240
ConstBaseIterator< T, typenameT::mapped_type >::value_type getCurrentValue() const
Return the value for the item at the current iterator position.
Definition: IteratorBase.h:204
ConstMapIterator< T > operator--(int)
Decrease the iterator position (postfix decrement).
Definition: IteratorBase.h:270
iterator for vectors
Definition: IteratorBase.h:288
ConstVectorIterator< T > operator--(int)
Decrease the iterator position (postfix decrement).
Definition: IteratorBase.h:352
ConstVectorIterator< T > & operator--()
Decrease the iterator position (prefix decrement).
Definition: IteratorBase.h:322
ConstVectorIterator< T > operator++(int)
Increase the iterator position (postfix increment).
Definition: IteratorBase.h:337
ConstVectorIterator< T > & operator++()
Increase the iterator position (prefix increment).
Definition: IteratorBase.h:307
ConstBaseIterator< T >::value_type getCurrentValue() const
Return the value for the item at the current iterator position.
Definition: IteratorBase.h:295
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1