Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
IteratorBase.h
1 /***********************************************************************
2  filename: CEGUIIteratorBase.h
3  created: 26/7/2004
4  author: Paul D Turner
5 
6  purpose: Defines interface for base iterator class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 /*************************************************************************
31  This is based somewhat on MapIterator in the Ogre library (www.ogre3d.org)
32 *************************************************************************/
33 #ifndef _CEGUIIteratorBase_h_
34 #define _CEGUIIteratorBase_h_
35 
36 #include "CEGUI/Base.h"
37 
38 
39 // Start of CEGUI namespace section
40 namespace CEGUI
41 {
46 template<typename T, typename V = typename T::value_type>
48 {
49 public:
50  typedef V value_type;
51 
62  ConstBaseIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
63  d_currIter(start_iter),
64  d_startIter(start_iter),
65  d_endIter(end_iter)
66  {
67  }
68 
69 
74  virtual ~ConstBaseIterator(void)
75  {
76  }
77 
78 
86  d_endIter(org.d_endIter)
87  {
88  }
89 
90 
96  {
97  d_currIter = rhs.d_currIter;
99  d_endIter = rhs.d_endIter;
100 
101  return *this;
102  }
103 
104 
109  virtual value_type getCurrentValue(void) const = 0;
110 
111 
116  bool isAtEnd(void) const
117  {
118  return d_currIter == d_endIter;
119  }
120 
121 
126  bool isAtStart(void) const
127  {
128  return d_currIter == d_startIter;
129  }
130 
135  bool operator==(const ConstBaseIterator<T, V>& rhs) const
136  {
137  return d_currIter == rhs.d_currIter;
138  }
139 
140 
145  bool operator!=(const ConstBaseIterator<T, V>& rhs) const
146  {
147  return !operator==(rhs);
148  }
149 
150 
155  value_type operator*() const
156  {
157  return getCurrentValue();
158  }
159 
160 
165  void toStart(void)
166  {
168  }
169 
170 
175  void toEnd(void)
176  {
178  }
179 
180 
181 protected:
182  /*************************************************************************
183  No default construction available
184  *************************************************************************/
185  ConstBaseIterator(void) {}
186 
187  /*************************************************************************
188  Implementation Data
189  *************************************************************************/
190  typename T::const_iterator d_currIter;
191  typename T::const_iterator d_startIter;
192  typename T::const_iterator d_endIter;
193 };
194 
196 template<class T>
197 class ConstMapIterator : public ConstBaseIterator<T, typename T::mapped_type>
198 {
199 public:
200  ConstMapIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
202  {}
203 
204  typename ConstBaseIterator<T, typename T::mapped_type>::value_type
206  {
207  return this->d_currIter->second;
208  }
209 
214  typename T::key_type getCurrentKey() const
215  {
216  return this->d_currIter->first;
217  }
218 
227  {
230 
231  return *this;
232  }
233 
242  {
245 
246  return *this;
247  }
248 
257  {
258  ConstMapIterator<T> tmp = *this;
259  ++*this;
260 
261  return tmp;
262  }
263 
272  {
273  ConstMapIterator<T> tmp = *this;
274  --*this;
275 
276  return tmp;
277  }
278 
279 };
280 
282 template<class T>
284 {
285 public:
286  ConstVectorIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
287  ConstBaseIterator<T>(start_iter, end_iter)
288  {}
289 
292  {
293  return *this->d_currIter;
294  }
295 
304  {
307 
308  return *this;
309  }
310 
319  {
322 
323  return *this;
324  }
325 
334  {
335  ConstVectorIterator<T> tmp = *this;
336  ++*this;
337 
338  return tmp;
339  }
340 
349  {
350  ConstVectorIterator<T> tmp = *this;
351  --*this;
352 
353  return tmp;
354  }
355 };
356 
357 } // End of CEGUI namespace section
358 
359 
360 #endif // end of guard _CEGUIIteratorBase_h_