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-2006 Torus Knot Software Ltd 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 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 #ifndef __IteratorWrappers_H__ 00030 #define __IteratorWrappers_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 00034 namespace Ogre { 00035 00050 template <class T> 00051 class VectorIterator 00052 { 00053 private: 00054 typename T::iterator mCurrent; 00055 typename T::iterator mEnd; 00057 VectorIterator() {}; 00058 public: 00059 typedef typename T::value_type ValueType; 00060 00065 VectorIterator(typename T::iterator start, typename T::iterator end) 00066 : mCurrent(start), mEnd(end) 00067 { 00068 } 00069 00074 explicit VectorIterator(T& c) 00075 : mCurrent(c.begin()), mEnd(c.end()) 00076 { 00077 } 00078 00080 bool hasMoreElements(void) const 00081 { 00082 return mCurrent != mEnd; 00083 } 00084 00086 typename T::value_type getNext(void) 00087 { 00088 return *mCurrent++; 00089 } 00091 typename T::value_type peekNext(void) 00092 { 00093 return *mCurrent; 00094 } 00096 typename T::pointer peekNextPtr(void) 00097 { 00098 return &(*mCurrent); 00099 } 00101 void moveNext(void) 00102 { 00103 ++mCurrent; 00104 } 00105 00106 00107 00108 }; 00109 00124 template <class T> 00125 class MapIterator 00126 { 00127 private: 00128 typename T::iterator mCurrent; 00129 typename T::iterator mEnd; 00131 MapIterator() {}; 00132 public: 00133 typedef typename T::mapped_type MappedType; 00134 typedef typename T::key_type KeyType; 00135 00140 MapIterator(typename T::iterator start, typename T::iterator end) 00141 : mCurrent(start), mEnd(end) 00142 { 00143 } 00144 00149 explicit MapIterator(T& c) 00150 : mCurrent(c.begin()), mEnd(c.end()) 00151 { 00152 } 00153 00155 bool hasMoreElements(void) const 00156 { 00157 return mCurrent != mEnd; 00158 } 00159 00161 typename T::mapped_type getNext(void) 00162 { 00163 return (mCurrent++)->second; 00164 } 00166 typename T::mapped_type peekNextValue(void) 00167 { 00168 return mCurrent->second; 00169 } 00171 typename T::key_type peekNextKey(void) 00172 { 00173 return mCurrent->first; 00174 } 00176 MapIterator<T> & operator=( MapIterator<T> &rhs ) 00177 { 00178 mCurrent = rhs.mCurrent; 00179 mEnd = rhs.mEnd; 00180 return *this; 00181 } 00184 typename T::mapped_type* peekNextValuePtr(void) 00185 { 00186 return &(mCurrent->second); 00187 } 00189 void moveNext(void) 00190 { 00191 ++mCurrent; 00192 } 00193 00194 00195 00196 }; 00211 template <class T> 00212 class ConstVectorIterator 00213 { 00214 private: 00215 mutable typename T::const_iterator mCurrent; 00216 typename T::const_iterator mEnd; 00218 ConstVectorIterator() {}; 00219 public: 00220 typedef typename T::value_type ValueType; 00221 00226 ConstVectorIterator(typename T::const_iterator start, typename T::const_iterator end) 00227 : mCurrent(start), mEnd(end) 00228 { 00229 } 00230 00235 explicit ConstVectorIterator(const T& c) 00236 : mCurrent(c.begin()), mEnd(c.end()) 00237 { 00238 } 00239 00241 bool hasMoreElements(void) const 00242 { 00243 return mCurrent != mEnd; 00244 } 00245 00247 typename T::value_type getNext(void) 00248 { 00249 return *mCurrent++; 00250 } 00252 typename T::value_type peekNext(void) const 00253 { 00254 return *mCurrent; 00255 } 00257 typename T::const_pointer peekNextPtr(void) const 00258 { 00259 return &(*mCurrent); 00260 } 00262 void moveNext(void) const 00263 { 00264 ++mCurrent; 00265 } 00266 00267 00268 00269 }; 00270 00285 template <class T> 00286 class ConstMapIterator 00287 { 00288 private: 00289 mutable typename T::const_iterator mCurrent; 00290 typename T::const_iterator mEnd; 00292 ConstMapIterator() {}; 00293 public: 00294 typedef typename T::mapped_type MappedType; 00295 typedef typename T::key_type KeyType; 00296 00301 ConstMapIterator(typename T::const_iterator start, typename T::const_iterator end) 00302 : mCurrent(start), mEnd(end) 00303 { 00304 } 00305 00310 explicit ConstMapIterator(const T& c) 00311 : mCurrent(c.begin()), mEnd(c.end()) 00312 { 00313 } 00314 00316 bool hasMoreElements(void) const 00317 { 00318 return mCurrent != mEnd; 00319 } 00320 00322 typename T::mapped_type getNext(void) 00323 { 00324 return (mCurrent++)->second; 00325 } 00327 typename T::mapped_type peekNextValue(void) const 00328 { 00329 return mCurrent->second; 00330 } 00332 typename T::key_type peekNextKey(void) const 00333 { 00334 return mCurrent->first; 00335 } 00337 ConstMapIterator<T> & operator=( ConstMapIterator<T> &rhs ) 00338 { 00339 mCurrent = rhs.mCurrent; 00340 mEnd = rhs.mEnd; 00341 return *this; 00342 } 00345 const typename T::mapped_type* peekNextValuePtr(void) const 00346 { 00347 return &(mCurrent->second); 00348 } 00350 void moveNext(void) const 00351 { 00352 ++mCurrent; 00353 } 00354 00355 00356 00357 }; 00358 } 00359 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:23 2009