OgreIteratorRange.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Ogre_Iterator_Range_H__
29 #define __Ogre_Iterator_Range_H__
30 
31 #include "OgreHeaderPrefix.h"
32 
33 #if OGRE_USE_BOOST
34 # if OGRE_COMPILER == OGRE_COMPILER_CLANG || OGRE_COMPILER == OGRE_COMPILER_GCC
35 # pragma GCC diagnostic push
36 # pragma GCC diagnostic ignored "-Wshadow"
37 # pragma GCC diagnostic ignored "-Wpadded"
38 # pragma GCC diagnostic ignored "-Wweak-vtables"
39 # pragma GCC diagnostic ignored "-Wall"
40 # endif
41 
42 # include <boost/range.hpp>
43 
44 # if OGRE_COMPILER == OGRE_COMPILER_CLANG || OGRE_COMPILER == OGRE_COMPILER_GCC
45 # pragma GCC diagnostic pop
46 # endif
47 #endif
48 
49 namespace Ogre {
50 
62 template <typename T>
64 
65 #if !OGRE_USE_BOOST
66 
68 
69  public :
70 
75  iterator_range( T b , T e ) : mBegin(b) , mEnd(e){}
76 
78  T begin() const { return mBegin; }
79 
81  T end() const { return mEnd; }
82 
84  bool empty() const { return mBegin = mEnd ; }
85 
87  bool equal( const iterator_range& other ) const
88  {return mBegin == other.mBegin && mEnd == other.mEnd;}
89 
91  bool operator==( const iterator_range& rhs ) const
92  {return equal( rhs ) ;}
93 
95  bool operator!=( const iterator_range& rhs ) const { return !operator==(rhs); }
96 
103  typedef T iterator;
104 
111  typedef T const_iterator;
112 
114 
119 #else
120  public: typedef boost::iterator_range<T> type ;
122 
123 #endif
124 };
125 
126 
135 template<typename T>
136 struct VectorRange : public iterator_range<typename T::iterator>::type
137 {
138 
143  VectorRange( T& c )
144  : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
145  {}
146 
151  VectorRange( typename T::iterator b, typename T::iterator e )
152  : iterator_range<typename T::iterator>::type( b, e )
153  {}
154 
156  bool operator==( const VectorRange& rhs ) const { return equal( rhs) ; }
158  bool operator!=( const VectorRange& rhs ) const { return !equal( rhs) ; }
159 
160 
161 #ifdef __Ogre_Iterator_Wrapper_H__
162  operator VectorIterator<T>(){return VectorIterator<T>( this->begin(), this->end());}
165  operator ConstVectorIterator<T>(){return ConstVectorIterator<T>( this->begin(), this->end());}
166 #endif
167 
168 };
169 
178 template<typename T>
179 struct ConstVectorRange : public iterator_range<typename T::const_iterator>::type
180 {
181 
186  ConstVectorRange( const T& c )
187  : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
188  {}
189 
194  ConstVectorRange( typename T::iterator b, typename T::iterator e )
195  : iterator_range<typename T::const_iterator>::type( b, e )
196  {}
197 
202  ConstVectorRange( typename T::const_iterator b, typename T::const_iterator e )
203  : iterator_range<typename T::const_iterator>::type( b, e )
204  {}
205 
211  : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
212  {}
213 
215  bool operator==( const ConstVectorRange& rhs ) const { return equal( rhs) ; }
217  bool operator!=( const ConstVectorRange& rhs ) const { return !equal( rhs) ; }
218 
219 
220 
221 
222 #ifdef __Ogre_Iterator_Wrapper_H__
223  operator ConstVectorIterator<T>(){return ConstVectorIterator<T>( this->begin(),this->end());}
225 #endif
226 
227 };
228 
229 
230 
239 template<typename T>
240 struct MapRange : public iterator_range<typename T::iterator>::type
241 {
246  MapRange( T& c )
247  : iterator_range<typename T::iterator>::type( c.begin(), c.end() )
248  {}
249 
254  MapRange( typename T::iterator b, typename T::iterator e )
255  : iterator_range<typename T::iterator>::type( b, e )
256  {}
257 
259  bool operator==( const MapRange& rhs ) const { return equal( rhs) ; }
261  bool operator!=( const MapRange& rhs ) const { return !equal( rhs) ; }
262 
263 
264 #ifdef __Ogre_Iterator_Wrapper_H__
265  operator MapIterator<T>(){return MapIterator<T>( this->begin(), this->end());}
268  operator ConstMapIterator<T>(){return ConstMapIterator<T>( this->begin(), this->end());}
269 #endif
270 
271 };
272 
281 template<typename T>
282 struct ConstMapRange : public iterator_range<typename T::const_iterator>::type
283 {
284 
289  ConstMapRange( const T& c )
290  : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() )
291  {}
292 
297  ConstMapRange( typename T::iterator b, typename T::iterator e )
298  : iterator_range<typename T::const_iterator>::type( b, e )
299  {}
300 
305  ConstMapRange( typename T::const_iterator b, typename T::const_iterator e )
306  : iterator_range<typename T::const_iterator>::type( b, e )
307  {}
308 
314  : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() )
315  {}
316 
318  bool operator==( const ConstMapRange& rhs ) const { return equal( rhs) ; }
320  bool operator!=( const ConstMapRange& rhs ) const { return !equal( rhs) ; }
321 
322 
323 #ifdef __Ogre_Iterator_Wrapper_H__
324  operator ConstMapIterator<T>(){return ConstMapIterator<T>( this->begin(),this->end());}
326 #endif
327 
328 };
329 
330 #include "OgreHeaderSuffix.h"
331 
332 }
333 #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 Wed Oct 16 2013 14:35:42