# CEGUIIteratorBase.h

    00001 /************************************************************************
    00002         filename:       CEGUIIteratorBase.h
    00003         created:        26/7/2004
    00004         author:         Paul D Turner
    00005
    00006         purpose:        Defines interface for base iterator class
    00007 *************************************************************************/
    00008 /*************************************************************************
    00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
    00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
    00011
    00012     This library is free software; you can redistribute it and/or
    00013     modify it under the terms of the GNU Lesser General Public
    00014     License as published by the Free Software Foundation; either
    00015     version 2.1 of the License, or (at your option) any later version.
    00016
    00017     This library is distributed in the hope that it will be useful,
    00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00020     Lesser General Public License for more details.
    00021
    00022     You should have received a copy of the GNU Lesser General Public
    00023     License along with this library; if not, write to the Free Software
    00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00025 *************************************************************************/
    00026 /*************************************************************************
    00027         This is based somewhat on MapIterator in the Ogre library (www.ogre3d.org)
    00028 *************************************************************************/
    00029 #ifndef _CEGUIIteratorBase_h_
    00030 #define _CEGUIIteratorBase_h_
    00031
    00032 #include "CEGUIBase.h"
    00033
    00034
    00035 // Start of CEGUI namespace section
    00036 namespace CEGUI
    00037 {
    00042 template<class T>
    00043 class ConstBaseIterator
    00044 {
    00045 public:
    00046 #if defined(_MSC_VER) && (_MSC_VER <= 1200) && !defined(_STLPORT_VERSION)
    00047         typedef typename T::referent_type       mapped_type;
    00048 #else
    00049         typedef typename T::mapped_type         mapped_type;
    00050 #endif
    00051
    00062         ConstBaseIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
    00063                 d_currIter(start_iter),
    00064                 d_startIter(start_iter),
    00065                 d_endIter(end_iter)
    00066         {
    00067         }
    00068
    00069
    00074         ~ConstBaseIterator(void)
    00075         {
    00076         }
    00077
    00078
    00083         ConstBaseIterator(const ConstBaseIterator<T>& org) :
    00084                 d_currIter(org.d_currIter),
    00085                 d_startIter(org.d_startIter),
    00086                 d_endIter(org.d_endIter)
    00087         {
    00088         }
    00089
    00090
    00095         ConstBaseIterator<T>&   operator=(const ConstBaseIterator<T>& rhs)
    00096         {
    00097                 d_currIter      = rhs.d_currIter;
    00098                 d_startIter     = rhs.d_startIter;
    00099                 d_endIter       = rhs.d_endIter;
    00100
    00101                 return *this;
    00102         }
    00103
    00104
    00109         typename T::key_type    getCurrentKey(void) const
    00110         {
    00111                 return d_currIter->first;
    00112         }
    00113
    00114
    00119         mapped_type     getCurrentValue(void) const
    00120         {
    00121                 return d_currIter->second;
    00122         }
    00123
    00124
    00129         bool    isAtEnd(void) const
    00130         {
    00131                 return d_currIter == d_endIter;
    00132         }
    00133
    00134
    00139         bool    isAtStart(void) const
    00140         {
    00141                 return d_currIter == d_startIter;
    00142         }
    00143
    00144
    00152         ConstBaseIterator<T>&   operator++()
    00153         {
    00154                 if (d_currIter != d_endIter)
    00155                         ++d_currIter;
    00156
    00157                 return *this;
    00158         }
    00159
    00160
    00168         ConstBaseIterator<T>    operator++(int)
    00169         {
    00170                 ConstBaseIterator<T> tmp = *this;
    00171                 ++*this;
    00172
    00173                 return tmp;
    00174         }
    00175
    00176
    00184         ConstBaseIterator<T>&   operator--()
    00185         {
    00186                 if (d_currIter != d_startIter)
    00187                         --d_currIter;
    00188
    00189                 return *this;
    00190         }
    00191
    00192
    00200         ConstBaseIterator<T>    operator--(int)
    00201         {
    00202                 ConstBaseIterator<T> tmp = *this;
    00203                 --*this;
    00204
    00205                 return tmp;
    00206         }
    00207
    00208
    00213         bool    operator==(const ConstBaseIterator<T>& rhs) const
    00214         {
    00215                 return d_currIter == rhs.d_currIter;
    00216         }
    00217
    00218
    00223         bool    operator!=(const ConstBaseIterator<T>& rhs) const
    00224         {
    00225                 return !this == rhs;
    00226         }
    00227
    00228
    00233         mapped_type     operator*() const
    00234         {
    00235                 return d_currIter->second;
    00236         }
    00237
    00238
    00243         void    toStart(void)
    00244         {
    00245                 d_currIter = d_startIter;
    00246         }
    00247
    00248
    00253         void    toEnd(void)
    00254         {
    00255                 d_currIter = d_endIter;
    00256         }
    00257
    00258
    00259 private:
    00260         /*************************************************************************
    00261                 No default construction available
    00262         *************************************************************************/
    00263         ConstBaseIterator(void) {}
    00264
    00265         /*************************************************************************
    00266                 Implementation Data
    00267         *************************************************************************/
    00268         typename T::const_iterator      d_currIter;
    00269         typename T::const_iterator      d_startIter;
    00270         typename T::const_iterator      d_endIter;
    00271 };
    00272
    00273 } // End of  CEGUI namespace section
    00274
    00275
    00276 #endif  // end of guard _CEGUIIteratorBase_h_