Crazy Eddies GUI System: CEGUIIteratorBase.h Source File

Crazy Eddies GUI System 0.7.6

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
    00010  *
    00011  *   Permission is hereby granted, free of charge, to any person obtaining
    00012  *   a copy of this software and associated documentation files (the
    00013  *   "Software"), to deal in the Software without restriction, including
    00014  *   without limitation the rights to use, copy, modify, merge, publish,
    00015  *   distribute, sublicense, and/or sell copies of the Software, and to
    00016  *   permit persons to whom the Software is furnished to do so, subject to
    00017  *   the following conditions:
    00018  *
    00019  *   The above copyright notice and this permission notice shall be
    00020  *   included in all copies or substantial portions of the Software.
    00021  *
    00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    00028  *   OTHER DEALINGS IN THE SOFTWARE.
    00029  ***************************************************************************/
    00030 /*************************************************************************
    00031         This is based somewhat on MapIterator in the Ogre library (www.ogre3d.org)
    00032 *************************************************************************/
    00033 #ifndef _CEGUIIteratorBase_h_
    00034 #define _CEGUIIteratorBase_h_
    00035
    00036 #include "CEGUIBase.h"
    00037
    00038
    00039 // Start of CEGUI namespace section
    00040 namespace CEGUI
    00041 {
    00046 template<class T>
    00047 class ConstBaseIterator
    00048 {
    00049 public:
    00050 #if defined(_MSC_VER) && (_MSC_VER <= 1200) && !defined(_STLPORT_VERSION)
    00051         typedef typename T::referent_type       mapped_type;
    00052 #else
    00053         typedef typename T::mapped_type         mapped_type;
    00054 #endif
    00055
    00066         ConstBaseIterator(typename T::const_iterator start_iter, typename T::const_iterator end_iter) :
    00067                 d_currIter(start_iter),
    00068                 d_startIter(start_iter),
    00069                 d_endIter(end_iter)
    00070         {
    00071         }
    00072
    00073
    00078         ~ConstBaseIterator(void)
    00079         {
    00080         }
    00081
    00082
    00087         ConstBaseIterator(const ConstBaseIterator<T>& org) :
    00088                 d_currIter(org.d_currIter),
    00089                 d_startIter(org.d_startIter),
    00090                 d_endIter(org.d_endIter)
    00091         {
    00092         }
    00093
    00094
    00099         ConstBaseIterator<T>&   operator=(const ConstBaseIterator<T>& rhs)
    00100         {
    00101                 d_currIter      = rhs.d_currIter;
    00102                 d_startIter     = rhs.d_startIter;
    00103                 d_endIter       = rhs.d_endIter;
    00104
    00105                 return *this;
    00106         }
    00107
    00108
    00113         typename T::key_type    getCurrentKey(void) const
    00114         {
    00115                 return d_currIter->first;
    00116         }
    00117
    00118
    00123         mapped_type     getCurrentValue(void) const
    00124         {
    00125                 return d_currIter->second;
    00126         }
    00127
    00128
    00133         bool    isAtEnd(void) const
    00134         {
    00135                 return d_currIter == d_endIter;
    00136         }
    00137
    00138
    00143         bool    isAtStart(void) const
    00144         {
    00145                 return d_currIter == d_startIter;
    00146         }
    00147
    00148
    00156         ConstBaseIterator<T>&   operator++()
    00157         {
    00158                 if (d_currIter != d_endIter)
    00159                         ++d_currIter;
    00160
    00161                 return *this;
    00162         }
    00163
    00164
    00172         ConstBaseIterator<T>    operator++(int)
    00173         {
    00174                 ConstBaseIterator<T> tmp = *this;
    00175                 ++*this;
    00176
    00177                 return tmp;
    00178         }
    00179
    00180
    00188         ConstBaseIterator<T>&   operator--()
    00189         {
    00190                 if (d_currIter != d_startIter)
    00191                         --d_currIter;
    00192
    00193                 return *this;
    00194         }
    00195
    00196
    00204         ConstBaseIterator<T>    operator--(int)
    00205         {
    00206                 ConstBaseIterator<T> tmp = *this;
    00207                 --*this;
    00208
    00209                 return tmp;
    00210         }
    00211
    00212
    00217         bool    operator==(const ConstBaseIterator<T>& rhs) const
    00218         {
    00219                 return d_currIter == rhs.d_currIter;
    00220         }
    00221
    00222
    00227         bool    operator!=(const ConstBaseIterator<T>& rhs) const
    00228         {
    00229                 return !operator==(rhs);
    00230         }
    00231
    00232
    00237         mapped_type     operator*() const
    00238         {
    00239                 return d_currIter->second;
    00240         }
    00241
    00242
    00247         void    toStart(void)
    00248         {
    00249                 d_currIter = d_startIter;
    00250         }
    00251
    00252
    00257         void    toEnd(void)
    00258         {
    00259                 d_currIter = d_endIter;
    00260         }
    00261
    00262
    00263 private:
    00264         /*************************************************************************
    00265                 No default construction available
    00266         *************************************************************************/
    00267         ConstBaseIterator(void) {}
    00268
    00269         /*************************************************************************
    00270                 Implementation Data
    00271         *************************************************************************/
    00272         typename T::const_iterator      d_currIter;
    00273         typename T::const_iterator      d_startIter;
    00274         typename T::const_iterator      d_endIter;
    00275 };
    00276
    00277 } // End of  CEGUI namespace section
    00278
    00279
    00280 #endif  // end of guard _CEGUIIteratorBase_h_