Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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
39 namespace CEGUI
40 {
45 template<typename T, typename V = typename T::value_type>
47 {
48 public:
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 
85  d_endIter(org.d_endIter)
86  {
87  }
88 
89 
95  {
96  d_currIter = rhs.d_currIter;
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 
180 protected:
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 
195 template<class T>
196 class ConstMapIterator : public ConstBaseIterator<T, typename T::mapped_type>
197 {
198 public:
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 
278 protected:
279  /*************************************************************************
280  No default construction available
281  *************************************************************************/
282  ConstMapIterator(void) {}
283 };
284 
286 template<class T>
288 {
289 public:
290  ConstVectorIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
291  ConstBaseIterator<T>(start_iter, end_iter)
292  {}
293 
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 
360 protected:
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_