OgreIteratorRange.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-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_Range_H__
00029 #define __Ogre_Iterator_Range_H__
00030 
00031 #include "OgreHeaderPrefix.h"
00032 
00033 #if OGRE_USE_BOOST
00034 #   if OGRE_COMPILER == OGRE_COMPILER_CLANG || OGRE_COMPILER == OGRE_COMPILER_GNUC
00035 #       pragma GCC diagnostic push
00036 #if OGRE_COMPILER == OGRE_COMPILER_GNUC
00037 #       pragma GCC diagnostic ignored "-Wpragmas"
00038 #elif OGRE_COMPILER == OGRE_COMPILER_CLANG
00039 #       pragma GCC diagnostic ignored "-Wdocumentation"
00040 #endif
00041 #       pragma GCC diagnostic ignored "-Wshadow"
00042 #       pragma GCC diagnostic ignored "-Wpadded"
00043 #       pragma GCC diagnostic ignored "-Wweak-vtables"
00044 #       pragma GCC diagnostic ignored "-Wall"
00045 #       pragma GCC diagnostic ignored "-Wundef"
00046 #   endif
00047 
00048 #   include <boost/range.hpp>
00049 
00050 #   if OGRE_COMPILER == OGRE_COMPILER_CLANG || OGRE_COMPILER == OGRE_COMPILER_GNUC
00051 #       pragma GCC diagnostic pop
00052 #   endif
00053 #endif
00054 
00055 namespace Ogre {
00056 
00068 template <typename T>
00069 class iterator_range{
00070 
00071 #if !OGRE_USE_BOOST
00072     
00073     T mBegin, mEnd;
00074     
00075     public : 
00076     
00081         iterator_range( T b , T e ) : mBegin(b) , mEnd(e){}
00082 
00084         T begin() const { return mBegin; }
00085         
00087         T end() const   { return mEnd;  }   
00088 
00090         bool empty() const { return mBegin = mEnd ; }
00091 
00093         bool equal( const iterator_range& other ) const  
00094         {return mBegin == other.mBegin && mEnd == other.mEnd;}
00095 
00097         bool operator==( const iterator_range& rhs ) const
00098         {return equal( rhs ) ;}
00099     
00101         bool operator!=( const iterator_range& rhs ) const { return !operator==(rhs); }
00102 
00109         typedef T iterator;
00110         
00117         typedef T const_iterator;
00118         
00120 
00124         typedef iterator_range<T> type;
00125 #else
00126 
00127         public: typedef boost::iterator_range<T> type ;
00128 
00129 #endif
00130 }; 
00131 
00132 
00141 template<typename T>
00142 struct VectorRange : public iterator_range<typename T::iterator>::type
00143 {
00144 
00149     VectorRange( T& c )
00150     : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
00151     {}
00152 
00157     VectorRange( typename T::iterator b, typename T::iterator e )
00158     : iterator_range<typename T::iterator>::type( b, e )
00159     {}
00160 
00162     bool operator==( const VectorRange& rhs ) const { return equal( rhs) ; }
00164     bool operator!=( const VectorRange& rhs ) const { return !equal( rhs) ; }
00165 
00166 
00167 #ifdef __Ogre_Iterator_Wrapper_H__
00168 
00169     operator VectorIterator<T>(){return VectorIterator<T>( this->begin(), this->end());}
00171     operator ConstVectorIterator<T>(){return ConstVectorIterator<T>( this->begin(), this->end());}
00172 #endif
00173     
00174 };
00175 
00184 template<typename T>
00185 struct ConstVectorRange : public iterator_range<typename T::const_iterator>::type
00186 {
00187 
00192     ConstVectorRange( const T& c )
00193     : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
00194     {}
00195 
00200     ConstVectorRange( typename T::iterator b, typename T::iterator e )
00201     : iterator_range<typename T::const_iterator>::type( b, e )
00202     {}
00203 
00208     ConstVectorRange( typename T::const_iterator b, typename T::const_iterator e )
00209     : iterator_range<typename T::const_iterator>::type( b, e )
00210     {}
00211 
00216     ConstVectorRange( const VectorRange<T>& rhs  )
00217     : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
00218     {}
00219 
00221     bool operator==( const ConstVectorRange& rhs ) const { return equal( rhs) ; }
00223     bool operator!=( const ConstVectorRange& rhs ) const { return !equal( rhs) ; }
00224     
00225     
00226 
00227 
00228 #ifdef __Ogre_Iterator_Wrapper_H__
00229 
00230     operator ConstVectorIterator<T>(){return  ConstVectorIterator<T>( this->begin(),this->end());}
00231 #endif
00232     
00233 };
00234 
00235 
00236 
00245 template<typename T>
00246 struct MapRange : public iterator_range<typename T::iterator>::type
00247 {
00252     MapRange( T& c )
00253     : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
00254     {}
00255 
00260     MapRange( typename T::iterator b, typename T::iterator e )
00261     : iterator_range<typename T::iterator>::type( b, e )
00262     {}
00263 
00265     bool operator==( const MapRange& rhs ) const { return equal( rhs) ; }
00267     bool operator!=( const MapRange& rhs ) const { return !equal( rhs) ; }
00268 
00269 
00270 #ifdef __Ogre_Iterator_Wrapper_H__
00271 
00272     operator MapIterator<T>(){return MapIterator<T>( this->begin(), this->end());}
00274     operator ConstMapIterator<T>(){return ConstMapIterator<T>( this->begin(), this->end());}
00275 #endif
00276     
00277 };
00278 
00287 template<typename T>
00288 struct ConstMapRange : public iterator_range<typename T::const_iterator>::type
00289 {
00290 
00295     ConstMapRange( const T& c )
00296     : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
00297     {}
00298 
00303     ConstMapRange( typename T::iterator b, typename T::iterator e )
00304     : iterator_range<typename T::const_iterator>::type( b, e )
00305     {}
00306     
00311     ConstMapRange( typename T::const_iterator b, typename T::const_iterator e )
00312     : iterator_range<typename T::const_iterator>::type( b, e )
00313     {}
00314 
00319     ConstMapRange( const MapRange<T>& rhs  )
00320     : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
00321     {}
00322     
00324     bool operator==( const ConstMapRange& rhs ) const { return equal( rhs) ; }
00326     bool operator!=( const ConstMapRange& rhs ) const { return !equal( rhs) ; }
00327 
00328 
00329 #ifdef __Ogre_Iterator_Wrapper_H__
00330 
00331     operator ConstMapIterator<T>(){return  ConstMapIterator<T>( this->begin(),this->end());}
00332 #endif
00333     
00334 };
00335 
00336 #include "OgreHeaderSuffix.h"
00337 
00338 }
00339 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:43