Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OgreIteratorWrappers.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef __IteratorWrappers_H__
00026 #define __IteratorWrappers_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 
00030 namespace Ogre {
00031 
00046     template <class T>
00047     class VectorIterator
00048     {
00049     private:
00050         typename T::iterator mCurrent;
00051         typename T::iterator mEnd;
00053         VectorIterator() {};
00054     public:
00055         typedef typename T::value_type ValueType;
00056 
00061         VectorIterator(typename T::iterator start, typename T::iterator end)
00062             : mCurrent(start), mEnd(end)
00063         {
00064         }
00065 
00070         explicit VectorIterator(T& c)
00071             : mCurrent(c.begin()), mEnd(c.end())
00072         {
00073         }
00074 
00076         bool hasMoreElements(void) const
00077         {
00078             return mCurrent != mEnd;
00079         }
00080 
00082         typename T::value_type getNext(void)
00083         {
00084             return *mCurrent++;
00085         }
00087         typename T::value_type peekNext(void)
00088         {
00089             return *mCurrent;
00090         }
00092         typename T::pointer peekNextPtr(void)
00093         {
00094             return &(*mCurrent);
00095         }
00097         void moveNext(void)
00098         {
00099             ++mCurrent;
00100         }
00101 
00102 
00103 
00104     };
00105 
00120     template <class T>
00121     class MapIterator
00122     {
00123     private:
00124         typename T::iterator mCurrent;
00125         typename T::iterator mEnd;
00127         MapIterator() {};
00128     public:
00129         typedef typename T::mapped_type MappedType;
00130         typedef typename T::key_type KeyType;
00131 
00136         MapIterator(typename T::iterator start, typename T::iterator end)
00137             : mCurrent(start), mEnd(end)
00138         {
00139         }
00140 
00145         explicit MapIterator(T& c)
00146             : mCurrent(c.begin()), mEnd(c.end())
00147         {
00148         }
00149 
00151         bool hasMoreElements(void) const
00152         {
00153             return mCurrent != mEnd;
00154         }
00155 
00157         typename T::mapped_type getNext(void)
00158         {
00159             return (mCurrent++)->second;
00160         }
00162         typename T::mapped_type peekNextValue(void)
00163         {
00164             return mCurrent->second;
00165         }
00167         typename T::key_type peekNextKey(void)
00168         {
00169             return mCurrent->first;
00170         }
00172         MapIterator<T> & operator=( MapIterator<T> &rhs )
00173         {
00174             mCurrent = rhs.mCurrent;
00175             mEnd = rhs.mEnd;
00176             return *this;
00177         }
00180         typename T::mapped_type* peekNextValuePtr(void)
00181         {
00182             return &(mCurrent->second);
00183         }
00185         void moveNext(void)
00186         {
00187             ++mCurrent;
00188         }
00189 
00190 
00191 
00192     };
00207     template <class T>
00208     class ConstVectorIterator
00209     {
00210     private:
00211         mutable typename T::const_iterator mCurrent;
00212         typename T::const_iterator mEnd;
00214         ConstVectorIterator() {};
00215     public:
00216         typedef typename T::value_type ValueType;
00217 
00222         ConstVectorIterator(typename T::const_iterator start, typename T::const_iterator end)
00223             : mCurrent(start), mEnd(end)
00224         {
00225         }
00226 
00231         explicit ConstVectorIterator(const T& c)
00232             : mCurrent(c.begin()), mEnd(c.end())
00233         {
00234         }
00235 
00237         bool hasMoreElements(void) const
00238         {
00239             return mCurrent != mEnd;
00240         }
00241 
00243         typename T::value_type getNext(void)
00244         {
00245             return *mCurrent++;
00246         }
00248         typename T::value_type peekNext(void) const
00249         {
00250             return *mCurrent;
00251         }
00253         typename T::const_pointer peekNextPtr(void) const
00254         {
00255             return &(*mCurrent);
00256         }
00258         void moveNext(void) const
00259         {
00260             ++mCurrent;
00261         }
00262 
00263 
00264 
00265     };
00266 
00281     template <class T>
00282     class ConstMapIterator
00283     {
00284     private:
00285         mutable typename T::const_iterator mCurrent;
00286         typename T::const_iterator mEnd;
00288         ConstMapIterator() {};
00289     public:
00290         typedef typename T::mapped_type MappedType;
00291         typedef typename T::key_type KeyType;
00292 
00297         ConstMapIterator(typename T::const_iterator start, typename T::const_iterator end)
00298             : mCurrent(start), mEnd(end)
00299         {
00300         }
00301 
00306         explicit ConstMapIterator(const T& c)
00307             : mCurrent(c.begin()), mEnd(c.end())
00308         {
00309         }
00310 
00312         bool hasMoreElements(void) const
00313         {
00314             return mCurrent != mEnd;
00315         }
00316 
00318         typename T::mapped_type getNext(void)
00319         {
00320             return (mCurrent++)->second;
00321         }
00323         typename T::mapped_type peekNextValue(void) const
00324         {
00325             return mCurrent->second;
00326         }
00328         typename T::key_type peekNextKey(void) const
00329         {
00330             return mCurrent->first;
00331         }
00333         MapIterator<T> & operator=( MapIterator<T> &rhs )
00334         {
00335             mCurrent = rhs.mCurrent;
00336             mEnd = rhs.mEnd;
00337             return *this;
00338         }
00341         const typename T::mapped_type* peekNextValuePtr(void) const
00342         {
00343             return &(mCurrent->second);
00344         }
00346         void moveNext(void) const
00347         {
00348             ++mCurrent;
00349         }
00350 
00351 
00352 
00353     };
00354 }
00355 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Nov 12 10:50:11 2006