Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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 
00067         bool hasMoreElements(void) const
00068         {
00069             return mCurrent != mEnd;
00070         }
00071 
00073         typename T::value_type getNext(void)
00074         {
00075             return *mCurrent++;
00076         }
00078         typename T::value_type peekNext(void)
00079         {
00080             return *mCurrent;
00081         }
00083         typename T::pointer peekNextPtr(void)
00084         {
00085             return &(*mCurrent);
00086         }
00088         void moveNext(void)
00089         {
00090             mCurrent++;
00091         }
00092 
00093 
00094 
00095     };
00096 
00111     template <class T>
00112     class MapIterator
00113     {
00114     private:
00115         typename T::iterator mCurrent;
00116         typename T::iterator mEnd;
00118         MapIterator() {};
00119     public:
00120         typedef typename T::mapped_type MappedType;
00121         typedef typename T::key_type KeyType;
00122 
00127         MapIterator(typename T::iterator start, typename T::iterator end)
00128             : mCurrent(start), mEnd(end)
00129         {
00130         }
00131 
00133         bool hasMoreElements(void) const
00134         {
00135             return mCurrent != mEnd;
00136         }
00137 
00139         typename T::mapped_type getNext(void)
00140         {
00141             return (mCurrent++)->second;
00142         }
00144         typename T::mapped_type peekNextValue(void)
00145         {
00146             return mCurrent->second;
00147         }
00149         typename T::key_type peekNextKey(void)
00150         {
00151             return mCurrent->first;
00152         }
00154         MapIterator<T> & operator=( MapIterator<T> &rhs )
00155         {
00156             mCurrent = rhs.mCurrent;
00157             mEnd = rhs.mEnd;
00158             return *this;
00159         }
00162         typename T::pointer peekNextValuePtr(void)
00163         {
00164             return &(mCurrent->second);
00165         }
00167         void moveNext(void)
00168         {
00169             mCurrent++;
00170         }
00171 
00172 
00173 
00174     };
00189     template <class T>
00190     class ConstVectorIterator
00191     {
00192     private:
00193         mutable typename T::const_iterator mCurrent;
00194         typename T::const_iterator mEnd;
00196         ConstVectorIterator() {};
00197     public:
00198         typedef typename T::value_type ValueType;
00199 
00204         ConstVectorIterator(typename T::const_iterator start, typename T::const_iterator end)
00205             : mCurrent(start), mEnd(end)
00206         {
00207         }
00208 
00210         bool hasMoreElements(void) const
00211         {
00212             return mCurrent != mEnd;
00213         }
00214 
00216         typename T::value_type getNext(void)
00217         {
00218             return *mCurrent++;
00219         }
00221         typename T::value_type peekNext(void) const
00222         {
00223             return *mCurrent;
00224         }
00226         typename T::const_pointer peekNextPtr(void) const
00227         {
00228             return &(*mCurrent);
00229         }
00231         void moveNext(void) const
00232         {
00233             mCurrent++;
00234         }
00235 
00236 
00237 
00238     };
00239 
00254     template <class T>
00255     class ConstMapIterator
00256     {
00257     private:
00258         mutable typename T::const_iterator mCurrent;
00259         typename T::const_iterator mEnd;
00261         ConstMapIterator() {};
00262     public:
00263         typedef typename T::mapped_type MappedType;
00264         typedef typename T::key_type KeyType;
00265 
00270         ConstMapIterator(typename T::const_iterator start, typename T::const_iterator end)
00271             : mCurrent(start), mEnd(end)
00272         {
00273         }
00274 
00276         bool hasMoreElements(void) const
00277         {
00278             return mCurrent != mEnd;
00279         }
00280 
00282         typename T::mapped_type getNext(void)
00283         {
00284             return (mCurrent++)->second;
00285         }
00287         typename T::mapped_type peekNextValue(void) const
00288         {
00289             return mCurrent->second;
00290         }
00292         typename T::key_type peekNextKey(void) const
00293         {
00294             return mCurrent->first;
00295         }
00297         MapIterator<T> & operator=( MapIterator<T> &rhs )
00298         {
00299             mCurrent = rhs.mCurrent;
00300             mEnd = rhs.mEnd;
00301             return *this;
00302         }
00305         typename T::const_pointer peekNextValuePtr(void) const
00306         {
00307             return &(mCurrent->second);
00308         }
00310         void moveNext(void) const
00311         {
00312             mCurrent++;
00313         }
00314 
00315 
00316 
00317     };
00318 }
00319 #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 Feb 12 12:59:47 2006