# OgreIteratorWrapper.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-2009 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
    00032 namespace Ogre{
    00033
    00045 template <typename T, typename IteratorType, typename ValType>
    00046 class IteratorWrapper
    00047 {
    00048
    00049     private:
    00051         IteratorWrapper();
    00052
    00053     protected:
    00054         IteratorType mBegin;
    00055         IteratorType mCurrent;
    00056         IteratorType mEnd;
    00057
    00058
    00059     public:
    00060
    00062         typedef ValType ValueType;
    00064         typedef ValType* PointerType;
    00065
    00073         typedef IteratorType iterator;
    00074
    00082         typedef IteratorType const_iterator;
    00083
    00084
    00085
    00086
    00087
    00092         IteratorWrapper ( IteratorType start, IteratorType last )
    00093         : mBegin( start ), mCurrent ( start ), mEnd ( last )
    00094         {
    00095         }
    00096
    00097
    00099         bool hasMoreElements ( ) const
    00100         {
    00101             return mCurrent != mEnd;
    00102         }
    00103
    00104
    00106         void moveNext (  )
    00107         {
    00108             ++mCurrent;
    00109         }
    00110
    00112         const IteratorType& begin() {return mBegin;}
    00113
    00114
    00116         IteratorType& current(){return mCurrent;}
    00117
    00119         const IteratorType& end() {return mEnd;}
    00120
    00121
    00122 };
    00123
    00124
    00125
    00136 template <typename T, typename IteratorType>
    00137 class VectorIteratorWrapper : public IteratorWrapper<T, IteratorType, typename  T::value_type>
    00138 {
    00139
    00140     public:
    00141         typedef typename IteratorWrapper<T, IteratorType, typename  T::value_type>::ValueType ValueType ;
    00142         typedef typename IteratorWrapper<T, IteratorType, typename  T::value_type>::PointerType PointerType ;
    00143
    00144
    00153         VectorIteratorWrapper ( IteratorType start, IteratorType last )
    00154         : IteratorWrapper<T, IteratorType, typename T::value_type>( start, last )
    00155         {
    00156         }
    00157
    00158
    00160         ValueType peekNext (  ) const
    00161         {
    00162             return *(this->mCurrent);
    00163         }
    00164
    00166         PointerType peekNextPtr (  )  const
    00167         {
    00168             return &(*(this->mCurrent) );
    00169         }
    00170
    00172         ValueType getNext (  )
    00173         {
    00174             return *(this->mCurrent++);
    00175         }
    00176
    00177 };
    00178
    00179
    00187 template <typename T>
    00188 class VectorIterator : public VectorIteratorWrapper<T,  typename T::iterator>{
    00189     public:
    00194         VectorIterator( typename T::iterator start, typename T::iterator last )
    00195         : VectorIteratorWrapper<T,  typename T::iterator>(start , last )
    00196         {
    00197         }
    00198
    00203         explicit VectorIterator( T& c )
    00204         : VectorIteratorWrapper<T,  typename T::iterator> ( c.begin(), c.end() )
    00205         {
    00206         }
    00207
    00208 };
    00209
    00218 template <typename T>
    00219 class ConstVectorIterator : public VectorIteratorWrapper<T,  typename T::const_iterator>{
    00220     public:
    00225         ConstVectorIterator( typename T::const_iterator start, typename T::const_iterator last )
    00226         : VectorIteratorWrapper<T,  typename T::const_iterator> (start , last )
    00227         {
    00228         }
    00229
    00234         explicit ConstVectorIterator ( const T& c )
    00235          : VectorIteratorWrapper<T,  typename T::const_iterator> (c.begin() , c.end() )
    00236         {
    00237         }
    00238 };
    00239
    00240
    00241
    00242
    00243
    00254 template <typename T, typename IteratorType>
    00255 class MapIteratorWrapper  : public IteratorWrapper<T, IteratorType, typename T::mapped_type>
    00256 {
    00257
    00258     public:
    00260         typedef typename IteratorWrapper<T, IteratorType, typename  T::mapped_type>::ValueType ValueType ;
    00262         typedef typename IteratorWrapper<T, IteratorType, typename  T::mapped_type>::PointerType PointerType ;
    00263
    00265         typedef typename T::value_type PairType ;
    00267         typedef typename T::key_type KeyType;
    00268
    00273         MapIteratorWrapper ( IteratorType start, IteratorType last )
    00274         : IteratorWrapper<T, IteratorType, typename T::mapped_type>( start, last )
    00275         {
    00276         }
    00277
    00279         KeyType peekNextKey(void) const
    00280         {
    00281             return this->mCurrent->first;
    00282         }
    00283
    00284
    00286         ValueType peekNextValue (  ) const
    00287         {
    00288             return this->mCurrent->second;
    00289         }
    00290
    00291
    00294         const PointerType peekNextValuePtr (  )  const
    00295         {
    00296             return &(this->mCurrent->second);
    00297         }
    00298
    00299
    00301         ValueType getNext()
    00302         {
    00303             return ((this->mCurrent++)->second) ;
    00304         }
    00305
    00306
    00307 };
    00308
    00309
    00310
    00311
    00320 template <typename T>
    00321 class MapIterator : public MapIteratorWrapper<T,  typename T::iterator>{
    00322     public:
    00323
    00328         MapIterator( typename T::iterator start, typename T::iterator last )
    00329         : MapIteratorWrapper<T,  typename T::iterator>(start , last )
    00330         {
    00331         }
    00332
    00337         explicit MapIterator( T& c )
    00338         : MapIteratorWrapper<T,  typename T::iterator> ( c.begin(), c.end() )
    00339         {
    00340         }
    00341
    00342 };
    00343
    00344
    00353 template <typename T>
    00354 class ConstMapIterator : public MapIteratorWrapper<T,  typename T::const_iterator>{
    00355     public:
    00356
    00361         ConstMapIterator( typename T::const_iterator start, typename T::const_iterator last )
    00362         : MapIteratorWrapper<T,  typename T::const_iterator> (start , last )
    00363         {
    00364         }
    00365
    00370         explicit ConstMapIterator ( const T& c )
    00371          : MapIteratorWrapper<T,  typename T::const_iterator> (c.begin() , c.end() )
    00372         {
    00373         }
    00374 };
    00375
    00376
    00377
    00378
    00379 }
    00380
    00381
    00382
    00383 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:08