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 #if OGRE_USE_BOOST
    00033 #   if OGRE_COMPILER == OGRE_COMPILER_CLANG || OGRE_COMPILER == OGRE_COMPILER_GCC
    00034 #       pragma GCC diagnostic push
    00035 #       pragma GCC diagnostic ignored "-Wshadow"
    00036 #       pragma GCC diagnostic ignored "-Wpadded"
    00037 #       pragma GCC diagnostic ignored "-Wweak-vtables"
    00038 #       pragma GCC diagnostic ignored "-Wall"
    00039 #   endif
    00040
    00041 #   include <boost/range.hpp>
    00042
    00043 #   if OGRE_COMPILER == OGRE_COMPILER_CLANG || OGRE_COMPILER == OGRE_COMPILER_GCC
    00044 #       pragma GCC diagnostic pop
    00045 #   endif
    00046 #endif
    00047
    00048 namespace Ogre {
    00049
    00061 template <typename T>
    00062 class iterator_range{
    00063
    00064 #if !OGRE_USE_BOOST
    00065
    00066     T mBegin, mEnd;
    00067
    00068     public :
    00069
    00074         iterator_range( T b , T e ) : mBegin(b) , mEnd(e){}
    00075
    00077         T begin() const { return mBegin; }
    00078
    00080         T end() const   { return mEnd;  }
    00081
    00083         bool empty() const { return mBegin = mEnd ; }
    00084
    00086         bool equal( const iterator_range& other ) const
    00087         {return mBegin == other.mBegin && mEnd == other.mEnd;}
    00088
    00090         bool operator==( const iterator_range& rhs ) const
    00091         {return equal( rhs ) ;}
    00092
    00094         bool operator!=( const iterator_range& rhs ) const { return !operator==(rhs); }
    00095
    00102         typedef T iterator;
    00103
    00110         typedef T const_iterator;
    00111
    00113
    00117         typedef iterator_range<T> type;
    00118 #else
    00119
    00120         public: typedef boost::iterator_range<T> type ;
    00121
    00122 #endif
    00123 };
    00124
    00125
    00134 template<typename T>
    00135 struct VectorRange : public iterator_range<typename T::iterator>::type
    00136 {
    00137
    00142     VectorRange( T& c )
    00143     : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
    00144     {}
    00145
    00150     VectorRange( typename T::iterator b, typename T::iterator e )
    00151     : iterator_range<typename T::iterator>::type( b, e )
    00152     {}
    00153
    00155     bool operator==( const VectorRange& rhs ) const { return equal( rhs) ; }
    00157     bool operator!=( const VectorRange& rhs ) const { return !equal( rhs) ; }
    00158
    00159
    00160 #ifdef __Ogre_Iterator_Wrapper_H__
    00161
    00162     operator VectorIterator<T>(){return VectorIterator<T>( this->begin(), this->end());}
    00164     operator ConstVectorIterator<T>(){return ConstVectorIterator<T>( this->begin(), this->end());}
    00165 #endif
    00166
    00167 };
    00168
    00177 template<typename T>
    00178 struct ConstVectorRange : public iterator_range<typename T::const_iterator>::type
    00179 {
    00180
    00185     ConstVectorRange( const T& c )
    00186     : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
    00187     {}
    00188
    00193     ConstVectorRange( typename T::iterator b, typename T::iterator e )
    00194     : iterator_range<typename T::const_iterator>::type( b, e )
    00195     {}
    00196
    00201     ConstVectorRange( typename T::const_iterator b, typename T::const_iterator e )
    00202     : iterator_range<typename T::const_iterator>::type( b, e )
    00203     {}
    00204
    00209     ConstVectorRange( const VectorRange<T>& rhs  )
    00210     : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
    00211     {}
    00212
    00214     bool operator==( const ConstVectorRange& rhs ) const { return equal( rhs) ; }
    00216     bool operator!=( const ConstVectorRange& rhs ) const { return !equal( rhs) ; }
    00217
    00218
    00219
    00220
    00221 #ifdef __Ogre_Iterator_Wrapper_H__
    00222
    00223     operator ConstVectorIterator<T>(){return  ConstVectorIterator<T>( this->begin(),this->end());}
    00224 #endif
    00225
    00226 };
    00227
    00228
    00229
    00238 template<typename T>
    00239 struct MapRange : public iterator_range<typename T::iterator>::type
    00240 {
    00245     MapRange( T& c )
    00246     : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
    00247     {}
    00248
    00253     MapRange( typename T::iterator b, typename T::iterator e )
    00254     : iterator_range<typename T::iterator>::type( b, e )
    00255     {}
    00256
    00258     bool operator==( const MapRange& rhs ) const { return equal( rhs) ; }
    00260     bool operator!=( const MapRange& rhs ) const { return !equal( rhs) ; }
    00261
    00262
    00263 #ifdef __Ogre_Iterator_Wrapper_H__
    00264
    00265     operator MapIterator<T>(){return MapIterator<T>( this->begin(), this->end());}
    00267     operator ConstMapIterator<T>(){return ConstMapIterator<T>( this->begin(), this->end());}
    00268 #endif
    00269
    00270 };
    00271
    00280 template<typename T>
    00281 struct ConstMapRange : public iterator_range<typename T::const_iterator>::type
    00282 {
    00283
    00288     ConstMapRange( const T& c )
    00289     : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
    00290     {}
    00291
    00296     ConstMapRange( typename T::iterator b, typename T::iterator e )
    00297     : iterator_range<typename T::const_iterator>::type( b, e )
    00298     {}
    00299
    00304     ConstMapRange( typename T::const_iterator b, typename T::const_iterator e )
    00305     : iterator_range<typename T::const_iterator>::type( b, e )
    00306     {}
    00307
    00312     ConstMapRange( const MapRange<T>& rhs  )
    00313     : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
    00314     {}
    00315
    00317     bool operator==( const ConstMapRange& rhs ) const { return equal( rhs) ; }
    00319     bool operator!=( const ConstMapRange& rhs ) const { return !equal( rhs) ; }
    00320
    00321
    00322 #ifdef __Ogre_Iterator_Wrapper_H__
    00323
    00324     operator ConstMapIterator<T>(){return  ConstMapIterator<T>( this->begin(),this->end());}
    00325 #endif
    00326
    00327 };
    00328
    00329
    00330
    00331 }
    00332 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:22