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-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Ogre_Iterator_Wrapper_H__ 00029 #define __Ogre_Iterator_Wrapper_H__ 00030 00031 #include "OgreHeaderPrefix.h" 00032 00033 namespace Ogre{ 00034 00046 template <typename T, typename IteratorType, typename ValType> 00047 class IteratorWrapper 00048 { 00049 00050 private: 00052 IteratorWrapper(); 00053 00054 protected: 00055 IteratorType mBegin; 00056 IteratorType mCurrent; 00057 IteratorType mEnd; 00058 00059 00060 public: 00061 00063 typedef ValType ValueType; 00065 typedef ValType* PointerType; 00066 00074 typedef IteratorType iterator; 00075 00083 typedef IteratorType const_iterator; 00084 00085 00090 IteratorWrapper ( IteratorType start, IteratorType last ) 00091 : mBegin( start ), mCurrent ( start ), mEnd ( last ) 00092 { 00093 } 00094 00095 00097 bool hasMoreElements ( ) const 00098 { 00099 return mCurrent != mEnd; 00100 } 00101 00102 00104 void moveNext ( ) 00105 { 00106 ++mCurrent; 00107 } 00108 00110 const IteratorType& begin() {return mBegin;} 00111 00112 00114 IteratorType& current(){return mCurrent;} 00115 00117 const IteratorType& end() {return mEnd;} 00118 00119 00120 }; 00121 00122 00123 00134 template <typename T, typename IteratorType> 00135 class VectorIteratorWrapper : public IteratorWrapper<T, IteratorType, typename T::value_type> 00136 { 00137 00138 public: 00139 typedef typename IteratorWrapper<T, IteratorType, typename T::value_type>::ValueType ValueType ; 00140 typedef typename IteratorWrapper<T, IteratorType, typename T::value_type>::PointerType PointerType ; 00141 00142 00151 VectorIteratorWrapper ( IteratorType start, IteratorType last ) 00152 : IteratorWrapper<T, IteratorType, typename T::value_type>( start, last ) 00153 { 00154 } 00155 00156 00158 ValueType peekNext ( ) const 00159 { 00160 return *(this->mCurrent); 00161 } 00162 00164 PointerType peekNextPtr ( ) const 00165 { 00166 return &(*(this->mCurrent) ); 00167 } 00168 00170 ValueType getNext ( ) 00171 { 00172 return *(this->mCurrent++); 00173 } 00174 00175 }; 00176 00177 00185 template <typename T> 00186 class VectorIterator : public VectorIteratorWrapper<T, typename T::iterator>{ 00187 public: 00192 VectorIterator( typename T::iterator start, typename T::iterator last ) 00193 : VectorIteratorWrapper<T, typename T::iterator>(start , last ) 00194 { 00195 } 00196 00201 explicit VectorIterator( T& c ) 00202 : VectorIteratorWrapper<T, typename T::iterator> ( c.begin(), c.end() ) 00203 { 00204 } 00205 00206 }; 00207 00216 template <typename T> 00217 class ConstVectorIterator : public VectorIteratorWrapper<T, typename T::const_iterator>{ 00218 public: 00223 ConstVectorIterator( typename T::const_iterator start, typename T::const_iterator last ) 00224 : VectorIteratorWrapper<T, typename T::const_iterator> (start , last ) 00225 { 00226 } 00227 00232 explicit ConstVectorIterator ( const T& c ) 00233 : VectorIteratorWrapper<T, typename T::const_iterator> (c.begin() , c.end() ) 00234 { 00235 } 00236 }; 00237 00238 00239 00240 00241 00252 template <typename T, typename IteratorType> 00253 class MapIteratorWrapper : public IteratorWrapper<T, IteratorType, typename T::mapped_type> 00254 { 00255 00256 public: 00258 typedef typename IteratorWrapper<T, IteratorType, typename T::mapped_type>::ValueType ValueType ; 00260 typedef typename IteratorWrapper<T, IteratorType, typename T::mapped_type>::PointerType PointerType ; 00261 00263 typedef typename T::value_type PairType ; 00265 typedef typename T::key_type KeyType; 00266 00271 MapIteratorWrapper ( IteratorType start, IteratorType last ) 00272 : IteratorWrapper<T, IteratorType, typename T::mapped_type>( start, last ) 00273 { 00274 } 00275 00277 KeyType peekNextKey(void) const 00278 { 00279 return this->mCurrent->first; 00280 } 00281 00282 00284 ValueType peekNextValue ( ) const 00285 { 00286 return this->mCurrent->second; 00287 } 00288 00289 00292 const PointerType peekNextValuePtr ( ) const 00293 { 00294 return &(this->mCurrent->second); 00295 } 00296 00297 00299 ValueType getNext() 00300 { 00301 return ((this->mCurrent++)->second) ; 00302 } 00303 00304 00305 }; 00306 00307 00308 00309 00318 template <typename T> 00319 class MapIterator : public MapIteratorWrapper<T, typename T::iterator>{ 00320 public: 00321 00326 MapIterator( typename T::iterator start, typename T::iterator last ) 00327 : MapIteratorWrapper<T, typename T::iterator>(start , last ) 00328 { 00329 } 00330 00335 explicit MapIterator( T& c ) 00336 : MapIteratorWrapper<T, typename T::iterator> ( c.begin(), c.end() ) 00337 { 00338 } 00339 00340 }; 00341 00342 00351 template <typename T> 00352 class ConstMapIterator : public MapIteratorWrapper<T, typename T::const_iterator>{ 00353 public: 00354 00359 ConstMapIterator( typename T::const_iterator start, typename T::const_iterator last ) 00360 : MapIteratorWrapper<T, typename T::const_iterator> (start , last ) 00361 { 00362 } 00363 00368 explicit ConstMapIterator ( const T& c ) 00369 : MapIteratorWrapper<T, typename T::const_iterator> (c.begin() , c.end() ) 00370 { 00371 } 00372 }; 00373 00374 00375 00376 00377 } 00378 00379 #include "OgreHeaderSuffix.h" 00380 00381 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:43