source: OGRE/trunk/ogre_dependencies/Dependencies/include/CEGUI/CEGUIIteratorBase.h @ 692

Revision 692, 6.7 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
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    Crazy Eddie's GUI System (http://www.cegui.org.uk)
10    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
11
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2.1 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25*************************************************************************/
26/*************************************************************************
27        This is based somewhat on MapIterator in the Ogre library (www.ogre3d.org)
28*************************************************************************/
29#ifndef _CEGUIIteratorBase_h_
30#define _CEGUIIteratorBase_h_
31
32#include "CEGUIBase.h"
33
34
35// Start of CEGUI namespace section
36namespace CEGUI
37{
38/*!
39\brief
40        Base class constant iterator used to offer iteration over various collections within the system.
41*/
42template<class T>
43class ConstBaseIterator
44{
45public:
46#if defined(_MSC_VER) && (_MSC_VER <= 1200) && !defined(_STLPORT_VERSION)
47        typedef typename T::referent_type       mapped_type;
48#else
49        typedef typename T::mapped_type         mapped_type;
50#endif
51
52        /*!
53        \brief
54                ConstBaseIterator constructor
55
56        \param start_iter
57                'real' iterator that will be the start of the range to be iterated over by this iterator.
58
59        \param end_iter
60                'real' iterator that will be the end of the range to be iterated over by this iterator.
61        */
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       
70        /*!
71        \brief
72                ConstBaseIterator destructor
73        */
74        ~ConstBaseIterator(void)
75        {
76        }
77
78
79        /*!
80        \brief
81                ConstBaseIterator copy constructor
82        */
83        ConstBaseIterator(const ConstBaseIterator<T>& org) :
84                d_currIter(org.d_currIter),
85                d_startIter(org.d_startIter),
86                d_endIter(org.d_endIter)
87        {
88        }
89
90
91        /*!
92        \brief
93                ConstBaseIterator assignment operator
94        */
95        ConstBaseIterator<T>&   operator=(const ConstBaseIterator<T>& rhs)
96        {
97                d_currIter      = rhs.d_currIter;
98                d_startIter     = rhs.d_startIter;
99                d_endIter       = rhs.d_endIter;
100
101                return *this;
102        }
103
104
105        /*!
106        \brief
107                Return the key for the item at the current iterator position.
108        */
109        typename T::key_type    getCurrentKey(void) const
110        {
111                return d_currIter->first;
112        }
113
114
115        /*!
116        \brief
117                Return the value for the item at the current iterator position.
118        */
119        mapped_type     getCurrentValue(void) const
120        {
121                return d_currIter->second;
122        }
123
124
125        /*!
126        \brief
127                Return whether the current iterator position is at the end of the iterators range.
128        */
129        bool    isAtEnd(void) const
130        {
131                return d_currIter == d_endIter;
132        }
133
134
135        /*!
136        \brief
137                Return whether the current iterator position is at the start of the iterators range.
138        */
139        bool    isAtStart(void) const
140        {
141                return d_currIter == d_startIter;
142        }
143
144
145        /*!
146        \brief
147                Increase the iterator position (prefix increment).
148
149        \note
150                The iterator is checked, and this call will always succeed, so do not rely on some exception to exit a loop.
151        */
152        ConstBaseIterator<T>&   operator++()
153        {
154                if (d_currIter != d_endIter)
155                        ++d_currIter;
156
157                return *this;
158        }
159
160
161        /*!
162        \brief
163                Increase the iterator position (postfix increment).
164
165        \note
166                The iterator is checked, and this call will always succeed, so do not rely on some exception to exit a loop.
167        */
168        ConstBaseIterator<T>    operator++(int)
169        {
170                ConstBaseIterator<T> tmp = *this;
171                ++*this;
172
173                return tmp;
174        }
175
176
177        /*!
178        \brief
179                Decrease the iterator position (prefix decrement).
180
181        \note
182                The iterator is checked, and this call will always succeed, so do not rely on some exception to exit a loop.
183        */
184        ConstBaseIterator<T>&   operator--()
185        {
186                if (d_currIter != d_startIter)
187                        --d_currIter;
188
189                return *this;
190        }
191
192
193        /*!
194        \brief
195                Decrease the iterator position (postfix decrement).
196
197        \note
198                The iterator is checked, and this call will always succeed, so do not rely on some exception to exit a loop.
199        */
200        ConstBaseIterator<T>    operator--(int)
201        {
202                ConstBaseIterator<T> tmp = *this;
203                --*this;
204
205                return tmp;
206        }
207
208
209        /*!
210        \brief
211                Compares two iterators.  Return true if the current position of both iterators are equivalent.
212        */
213        bool    operator==(const ConstBaseIterator<T>& rhs) const
214        {
215                return d_currIter == rhs.d_currIter;
216        }
217
218
219        /*!
220        \brief
221                Compares two iterators.  Return true if the current position of the iterators are different.
222        */
223        bool    operator!=(const ConstBaseIterator<T>& rhs) const
224        {
225                return !this == rhs;
226        }
227
228
229        /*!
230        \brief
231                Return the value for the current iterator position.
232        */
233        mapped_type     operator*() const
234        {
235                return d_currIter->second;
236        }
237
238
239        /*!
240        \brief
241                Set the iterator current position to the start position.
242        */
243        void    toStart(void)
244        {
245                d_currIter = d_startIter;
246        }
247
248
249        /*!
250        \brief
251                Set the iterator current position to the end position.
252        */
253        void    toEnd(void)
254        {
255                d_currIter = d_endIter;
256        }
257
258
259private:
260        /*************************************************************************
261                No default construction available
262        *************************************************************************/
263        ConstBaseIterator(void) {}
264
265        /*************************************************************************
266                Implementation Data
267        *************************************************************************/
268        typename T::const_iterator      d_currIter;             //!< 'real' iterator describing the current position within the collection.
269        typename T::const_iterator      d_startIter;    //!< 'real' iterator describing the start position within the collection (or what we were told was the start).
270        typename T::const_iterator      d_endIter;              //!< 'real' iterator describing the end position within the collection (or what we were told was the end).
271};
272
273} // End of  CEGUI namespace section
274
275
276#endif  // end of guard _CEGUIIteratorBase_h_
Note: See TracBrowser for help on using the repository browser.