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-2012 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 
00032 //#define OGRE_USE_BOOST 1 - picked up by CMake
00033 #if OGRE_USE_BOOST
00034 #include <boost/range.hpp>
00035 #endif
00036 
00037 namespace Ogre {
00038 
00050 template <typename T>
00051 class iterator_range{
00052 
00053 #if !OGRE_USE_BOOST
00054     
00055     T mBegin, mEnd;
00056     
00057     public : 
00058     
00063         iterator_range( T b , T e ) : mBegin(b) , mEnd(e){}
00064 
00066         T begin() const { return mBegin; }
00067         
00069         T end() const   { return mEnd;  }   
00070 
00072         bool empty() const { return mBegin = mEnd ; }
00073 
00075         bool equal( const iterator_range& other ) const  
00076         {return mBegin == other.mBegin && mEnd == other.mEnd;}
00077 
00079         bool operator==( const iterator_range& rhs ) const
00080         {return equal( rhs ) ;}
00081     
00083         bool operator!=( const iterator_range& rhs ) const { return !operator==(rhs); }
00084 
00091         typedef T iterator;
00092         
00099         typedef T const_iterator;
00100         
00102 
00106         typedef iterator_range<T> type;
00107 #else
00109         public: typedef boost::iterator_range<T> type ;
00110 
00111 #endif
00112 }; 
00113 
00114 
00123 template<typename T>
00124 struct VectorRange : public iterator_range<typename T::iterator>::type
00125 {
00126 
00131     VectorRange( T& c )
00132     : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
00133     {}
00134 
00139     VectorRange( typename T::iterator b, typename T::iterator e )
00140     : iterator_range<typename T::iterator>::type( b, e )
00141     {}
00142 
00144     bool operator==( const VectorRange& rhs ) const { return equal( rhs) ; }
00146     bool operator!=( const VectorRange& rhs ) const { return !equal( rhs) ; }
00147 
00148 
00149 #ifdef __Ogre_Iterator_Wrapper_H__
00151     operator VectorIterator<T>(){return VectorIterator<T>( this->begin(), this->end());}
00153     operator ConstVectorIterator<T>(){return ConstVectorIterator<T>( this->begin(), this->end());}
00154 #endif
00155     
00156 };
00157 
00166 template<typename T>
00167 struct ConstVectorRange : public iterator_range<typename T::const_iterator>::type
00168 {
00169 
00174     ConstVectorRange( const T& c )
00175     : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
00176     {}
00177 
00182     ConstVectorRange( typename T::iterator b, typename T::iterator e )
00183     : iterator_range<typename T::const_iterator>::type( b, e )
00184     {}
00185 
00190     ConstVectorRange( typename T::const_iterator b, typename T::const_iterator e )
00191     : iterator_range<typename T::const_iterator>::type( b, e )
00192     {}
00193 
00198     ConstVectorRange( const VectorRange<T>& rhs  )
00199     : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
00200     {}
00201 
00203     bool operator==( const ConstVectorRange& rhs ) const { return equal( rhs) ; }
00205     bool operator!=( const ConstVectorRange& rhs ) const { return !equal( rhs) ; }
00206     
00207     
00208 
00209 
00210 #ifdef __Ogre_Iterator_Wrapper_H__
00212     operator ConstVectorIterator<T>(){return  ConstVectorIterator<T>( this->begin(),this->end());}
00213 #endif
00214     
00215 };
00216 
00217 
00218 
00227 template<typename T>
00228 struct MapRange : public iterator_range<typename T::iterator>::type
00229 {
00234     MapRange( T& c )
00235     : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
00236     {}
00237 
00242     MapRange( typename T::iterator b, typename T::iterator e )
00243     : iterator_range<typename T::iterator>::type( b, e )
00244     {}
00245 
00247     bool operator==( const MapRange& rhs ) const { return equal( rhs) ; }
00249     bool operator!=( const MapRange& rhs ) const { return !equal( rhs) ; }
00250 
00251 
00252 #ifdef __Ogre_Iterator_Wrapper_H__
00254     operator MapIterator<T>(){return MapIterator<T>( this->begin(), this->end());}
00256     operator ConstMapIterator<T>(){return ConstMapIterator<T>( this->begin(), this->end());}
00257 #endif
00258     
00259 };
00260 
00269 template<typename T>
00270 struct ConstMapRange : public iterator_range<typename T::const_iterator>::type
00271 {
00272 
00277     ConstMapRange( const T& c )
00278     : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
00279     {}
00280 
00285     ConstMapRange( typename T::iterator b, typename T::iterator e )
00286     : iterator_range<typename T::const_iterator>::type( b, e )
00287     {}
00288     
00293     ConstMapRange( typename T::const_iterator b, typename T::const_iterator e )
00294     : iterator_range<typename T::const_iterator>::type( b, e )
00295     {}
00296 
00301     ConstMapRange( const MapRange<T>& rhs  )
00302     : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
00303     {}
00304     
00306     bool operator==( const ConstMapRange& rhs ) const { return equal( rhs) ; }
00308     bool operator!=( const ConstMapRange& rhs ) const { return !equal( rhs) ; }
00309 
00310 
00311 #ifdef __Ogre_Iterator_Wrapper_H__
00313     operator ConstMapIterator<T>(){return  ConstMapIterator<T>( this->begin(),this->end());}
00314 #endif
00315     
00316 };
00317 
00318 
00319 
00320 }
00321 #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 Fri May 25 23:36:24 2012