Crazy Eddies GUI System  0.7.0
CEGUIIteratorBase.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 "CEGUIBase.h"
37 
38 
39 // Start of CEGUI namespace section
40 namespace CEGUI
41 {
46 template<class T>
48 {
49 public:
50 #if defined(_MSC_VER) && (_MSC_VER <= 1200) && !defined(_STLPORT_VERSION)
51  typedef typename T::referent_type mapped_type;
52 #else
53  typedef typename T::mapped_type mapped_type;
54 #endif
55 
66  ConstBaseIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
67  d_currIter(start_iter),
68  d_startIter(start_iter),
69  d_endIter(end_iter)
70  {
71  }
72 
73 
79  {
80  }
81 
82 
88  d_currIter(org.d_currIter),
89  d_startIter(org.d_startIter),
90  d_endIter(org.d_endIter)
91  {
92  }
93 
94 
100  {
101  d_currIter = rhs.d_currIter;
102  d_startIter = rhs.d_startIter;
103  d_endIter = rhs.d_endIter;
104 
105  return *this;
106  }
107 
108 
113  typename T::key_type getCurrentKey(void) const
114  {
115  return d_currIter->first;
116  }
117 
118 
123  mapped_type getCurrentValue(void) const
124  {
125  return d_currIter->second;
126  }
127 
128 
133  bool isAtEnd(void) const
134  {
135  return d_currIter == d_endIter;
136  }
137 
138 
143  bool isAtStart(void) const
144  {
145  return d_currIter == d_startIter;
146  }
147 
148 
157  {
158  if (d_currIter != d_endIter)
159  ++d_currIter;
160 
161  return *this;
162  }
163 
164 
173  {
174  ConstBaseIterator<T> tmp = *this;
175  ++*this;
176 
177  return tmp;
178  }
179 
180 
189  {
190  if (d_currIter != d_startIter)
191  --d_currIter;
192 
193  return *this;
194  }
195 
196 
205  {
206  ConstBaseIterator<T> tmp = *this;
207  --*this;
208 
209  return tmp;
210  }
211 
212 
217  bool operator==(const ConstBaseIterator<T>& rhs) const
218  {
219  return d_currIter == rhs.d_currIter;
220  }
221 
222 
227  bool operator!=(const ConstBaseIterator<T>& rhs) const
228  {
229  return !this == rhs;
230  }
231 
232 
237  mapped_type operator*() const
238  {
239  return d_currIter->second;
240  }
241 
242 
247  void toStart(void)
248  {
249  d_currIter = d_startIter;
250  }
251 
252 
257  void toEnd(void)
258  {
259  d_currIter = d_endIter;
260  }
261 
262 
263 private:
264  /*************************************************************************
265  No default construction available
266  *************************************************************************/
267  ConstBaseIterator(void) {}
268 
269  /*************************************************************************
270  Implementation Data
271  *************************************************************************/
272  typename T::const_iterator d_currIter;
273  typename T::const_iterator d_startIter;
274  typename T::const_iterator d_endIter;
275 };
276 
277 } // End of CEGUI namespace section
278 
279 
280 #endif // end of guard _CEGUIIteratorBase_h_