[148] | 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_GNUC |
---|
| 35 | # pragma GCC diagnostic push |
---|
| 36 | #if OGRE_COMPILER == OGRE_COMPILER_GNUC |
---|
| 37 | # pragma GCC diagnostic ignored "-Wpragmas" |
---|
| 38 | #elif OGRE_COMPILER == OGRE_COMPILER_CLANG |
---|
| 39 | # pragma GCC diagnostic ignored "-Wdocumentation" |
---|
| 40 | #endif |
---|
| 41 | # pragma GCC diagnostic ignored "-Wshadow" |
---|
| 42 | # pragma GCC diagnostic ignored "-Wpadded" |
---|
| 43 | # pragma GCC diagnostic ignored "-Wweak-vtables" |
---|
| 44 | # pragma GCC diagnostic ignored "-Wall" |
---|
| 45 | # pragma GCC diagnostic ignored "-Wundef" |
---|
| 46 | # endif |
---|
| 47 | |
---|
| 48 | # include <boost/range.hpp> |
---|
| 49 | |
---|
| 50 | # if OGRE_COMPILER == OGRE_COMPILER_CLANG || OGRE_COMPILER == OGRE_COMPILER_GNUC |
---|
| 51 | # pragma GCC diagnostic pop |
---|
| 52 | # endif |
---|
| 53 | #endif |
---|
| 54 | |
---|
| 55 | namespace Ogre { |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * |
---|
| 59 | * @brief Base for an iterator_range |
---|
| 60 | * |
---|
| 61 | * @tparam T iterator type |
---|
| 62 | * |
---|
| 63 | * This class implements the minimal interface of the (boost::iterator_)range concept |
---|
| 64 | *\n Also it prepairs for direct usage of boost::iterator_range by providing the real used type via iterator_range::type |
---|
| 65 | * so that client code does not have to change when boost::iterator_range will be implemented some day. |
---|
| 66 | *\n see VectorRange MapRange or corresponding Const variants for a sample of concrete usage of the iterator_range::type |
---|
| 67 | */ |
---|
| 68 | template <typename T> |
---|
| 69 | class iterator_range{ |
---|
| 70 | |
---|
| 71 | #if !OGRE_USE_BOOST |
---|
| 72 | |
---|
| 73 | T mBegin, mEnd; |
---|
| 74 | |
---|
| 75 | public : |
---|
| 76 | |
---|
| 77 | /** Constructor. |
---|
| 78 | @remarks |
---|
| 79 | Provide a start and end iterator to initialise. |
---|
| 80 | */ |
---|
| 81 | iterator_range( T b , T e ) : mBegin(b) , mEnd(e){} |
---|
| 82 | |
---|
| 83 | ///access to the begin of the range |
---|
| 84 | T begin() const { return mBegin; } |
---|
| 85 | |
---|
| 86 | ///access to the end of the range |
---|
| 87 | T end() const { return mEnd; } |
---|
| 88 | |
---|
| 89 | ///informs if there are any elements in the range |
---|
| 90 | bool empty() const { return mBegin = mEnd ; } |
---|
| 91 | |
---|
| 92 | ///comparison for equality |
---|
| 93 | bool equal( const iterator_range& other ) const |
---|
| 94 | {return mBegin == other.mBegin && mEnd == other.mEnd;} |
---|
| 95 | |
---|
| 96 | ///comparison operator for equality |
---|
| 97 | bool operator==( const iterator_range& rhs ) const |
---|
| 98 | {return equal( rhs ) ;} |
---|
| 99 | |
---|
| 100 | ///comparison operator for inequality |
---|
| 101 | bool operator!=( const iterator_range& rhs ) const { return !operator==(rhs); } |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | @brief typedef to fulfill container interface |
---|
| 105 | |
---|
| 106 | @note there is no distinction between const_iterator and iterator. |
---|
| 107 | |
---|
| 108 | */ |
---|
| 109 | typedef T iterator; |
---|
| 110 | |
---|
| 111 | /** |
---|
| 112 | @brief typedef to fulfill container interface |
---|
| 113 | |
---|
| 114 | @note there is no distinction between const_iterator and iterator. |
---|
| 115 | |
---|
| 116 | */ |
---|
| 117 | typedef T const_iterator; |
---|
| 118 | |
---|
| 119 | /// defines the real used type |
---|
| 120 | /** |
---|
| 121 | type will be defined as Ogre::iterator_range if not used with boost |
---|
| 122 | \n otherwise the type will be boost::iterator_range |
---|
| 123 | */ |
---|
| 124 | typedef iterator_range<T> type; |
---|
| 125 | #else |
---|
| 126 | /// defines (this) type as boost::iterator_range |
---|
| 127 | public: typedef boost::iterator_range<T> type ; |
---|
| 128 | |
---|
| 129 | #endif |
---|
| 130 | }; |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * |
---|
| 135 | * @brief Predefined type |
---|
| 136 | * |
---|
| 137 | * @tparam T iterator type |
---|
| 138 | * |
---|
| 139 | * compatility class for VectorIterator |
---|
| 140 | */ |
---|
| 141 | template<typename T> |
---|
| 142 | struct VectorRange : public iterator_range<typename T::iterator>::type |
---|
| 143 | { |
---|
| 144 | |
---|
| 145 | /** Constructor. |
---|
| 146 | @remarks |
---|
| 147 | Provide a container to initialise. |
---|
| 148 | */ |
---|
| 149 | VectorRange( T& c ) |
---|
| 150 | : iterator_range<typename T::iterator>::type( c.begin(), c.end() ) |
---|
| 151 | {} |
---|
| 152 | |
---|
| 153 | /** Constructor. |
---|
| 154 | @remarks |
---|
| 155 | Provide a start and end iterator to initialise. |
---|
| 156 | */ |
---|
| 157 | VectorRange( typename T::iterator b, typename T::iterator e ) |
---|
| 158 | : iterator_range<typename T::iterator>::type( b, e ) |
---|
| 159 | {} |
---|
| 160 | |
---|
| 161 | ///comparison operator for equality |
---|
| 162 | bool operator==( const VectorRange& rhs ) const { return equal( rhs) ; } |
---|
| 163 | ///comparison operator for inequality |
---|
| 164 | bool operator!=( const VectorRange& rhs ) const { return !equal( rhs) ; } |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | #ifdef __Ogre_Iterator_Wrapper_H__ |
---|
| 168 | ///cast operator to a VectorIterator |
---|
| 169 | operator VectorIterator<T>(){return VectorIterator<T>( this->begin(), this->end());} |
---|
| 170 | ///cast operator to a ConstVectorIterator |
---|
| 171 | operator ConstVectorIterator<T>(){return ConstVectorIterator<T>( this->begin(), this->end());} |
---|
| 172 | #endif |
---|
| 173 | |
---|
| 174 | }; |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * |
---|
| 178 | * @brief Predefined type |
---|
| 179 | * |
---|
| 180 | * @tparam T iterator type |
---|
| 181 | * |
---|
| 182 | * compatility class for ConstVectorIterator |
---|
| 183 | */ |
---|
| 184 | template<typename T> |
---|
| 185 | struct ConstVectorRange : public iterator_range<typename T::const_iterator>::type |
---|
| 186 | { |
---|
| 187 | |
---|
| 188 | /** Constructor. |
---|
| 189 | @remarks |
---|
| 190 | Provide a container to initialise. |
---|
| 191 | */ |
---|
| 192 | ConstVectorRange( const T& c ) |
---|
| 193 | : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() ) |
---|
| 194 | {} |
---|
| 195 | |
---|
| 196 | /** Constructor. |
---|
| 197 | @remarks |
---|
| 198 | Provide a start and end iterator to initialise. |
---|
| 199 | */ |
---|
| 200 | ConstVectorRange( typename T::iterator b, typename T::iterator e ) |
---|
| 201 | : iterator_range<typename T::const_iterator>::type( b, e ) |
---|
| 202 | {} |
---|
| 203 | |
---|
| 204 | /** Constructor. |
---|
| 205 | @remarks |
---|
| 206 | Provide a start and end const_iterator to initialise. |
---|
| 207 | */ |
---|
| 208 | ConstVectorRange( typename T::const_iterator b, typename T::const_iterator e ) |
---|
| 209 | : iterator_range<typename T::const_iterator>::type( b, e ) |
---|
| 210 | {} |
---|
| 211 | |
---|
| 212 | /** Constructor. |
---|
| 213 | @remarks |
---|
| 214 | Provide a VectorRange to initialise. |
---|
| 215 | */ |
---|
| 216 | ConstVectorRange( const VectorRange<T>& rhs ) |
---|
| 217 | : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() ) |
---|
| 218 | {} |
---|
| 219 | |
---|
| 220 | ///comparison operator for equality |
---|
| 221 | bool operator==( const ConstVectorRange& rhs ) const { return equal( rhs) ; } |
---|
| 222 | ///comparison operator for inequality |
---|
| 223 | bool operator!=( const ConstVectorRange& rhs ) const { return !equal( rhs) ; } |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | #ifdef __Ogre_Iterator_Wrapper_H__ |
---|
| 229 | ///cast operator to a ConstVectorIterator |
---|
| 230 | operator ConstVectorIterator<T>(){return ConstVectorIterator<T>( this->begin(),this->end());} |
---|
| 231 | #endif |
---|
| 232 | |
---|
| 233 | }; |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | |
---|
| 237 | /** |
---|
| 238 | * |
---|
| 239 | * @brief Predefined type |
---|
| 240 | * |
---|
| 241 | * @tparam T iterator type |
---|
| 242 | * |
---|
| 243 | * compatility class for MapIterator |
---|
| 244 | */ |
---|
| 245 | template<typename T> |
---|
| 246 | struct MapRange : public iterator_range<typename T::iterator>::type |
---|
| 247 | { |
---|
| 248 | /** Constructor. |
---|
| 249 | @remarks |
---|
| 250 | Provide a container to initialise. |
---|
| 251 | */ |
---|
| 252 | MapRange( T& c ) |
---|
| 253 | : iterator_range<typename T::iterator>::type( c.begin(), c.end() ) |
---|
| 254 | {} |
---|
| 255 | |
---|
| 256 | /** Constructor. |
---|
| 257 | @remarks |
---|
| 258 | Provide a start and end iterator to initialise. |
---|
| 259 | */ |
---|
| 260 | MapRange( typename T::iterator b, typename T::iterator e ) |
---|
| 261 | : iterator_range<typename T::iterator>::type( b, e ) |
---|
| 262 | {} |
---|
| 263 | |
---|
| 264 | ///comparison operator for equality |
---|
| 265 | bool operator==( const MapRange& rhs ) const { return equal( rhs) ; } |
---|
| 266 | ///comparison operator for inequality |
---|
| 267 | bool operator!=( const MapRange& rhs ) const { return !equal( rhs) ; } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | #ifdef __Ogre_Iterator_Wrapper_H__ |
---|
| 271 | ///cast operator to a MapIterator |
---|
| 272 | operator MapIterator<T>(){return MapIterator<T>( this->begin(), this->end());} |
---|
| 273 | ///cast operator to a ConstMapIterator |
---|
| 274 | operator ConstMapIterator<T>(){return ConstMapIterator<T>( this->begin(), this->end());} |
---|
| 275 | #endif |
---|
| 276 | |
---|
| 277 | }; |
---|
| 278 | |
---|
| 279 | /** |
---|
| 280 | * |
---|
| 281 | * @brief Predefined type |
---|
| 282 | * |
---|
| 283 | * @tparam T iterator type |
---|
| 284 | * |
---|
| 285 | * compatility class for ConstMapIterator |
---|
| 286 | */ |
---|
| 287 | template<typename T> |
---|
| 288 | struct ConstMapRange : public iterator_range<typename T::const_iterator>::type |
---|
| 289 | { |
---|
| 290 | |
---|
| 291 | /** Constructor. |
---|
| 292 | @remarks |
---|
| 293 | Provide a container to initialise. |
---|
| 294 | */ |
---|
| 295 | ConstMapRange( const T& c ) |
---|
| 296 | : iterator_range<typename T::const_iterator>::type( c.begin(), c.end() ) |
---|
| 297 | {} |
---|
| 298 | |
---|
| 299 | /** Constructor. |
---|
| 300 | @remarks |
---|
| 301 | Provide a start and end iterator to initialise. |
---|
| 302 | */ |
---|
| 303 | ConstMapRange( typename T::iterator b, typename T::iterator e ) |
---|
| 304 | : iterator_range<typename T::const_iterator>::type( b, e ) |
---|
| 305 | {} |
---|
| 306 | |
---|
| 307 | /** Constructor. |
---|
| 308 | @remarks |
---|
| 309 | Provide a start and end const_iterator to initialise. |
---|
| 310 | */ |
---|
| 311 | ConstMapRange( typename T::const_iterator b, typename T::const_iterator e ) |
---|
| 312 | : iterator_range<typename T::const_iterator>::type( b, e ) |
---|
| 313 | {} |
---|
| 314 | |
---|
| 315 | /** Constructor. |
---|
| 316 | @remarks |
---|
| 317 | Provide a MapRange to initialise. |
---|
| 318 | */ |
---|
| 319 | ConstMapRange( const MapRange<T>& rhs ) |
---|
| 320 | : iterator_range<typename T::const_iterator>::type( rhs.begin(), rhs.end() ) |
---|
| 321 | {} |
---|
| 322 | |
---|
| 323 | ///comparison operator for equality |
---|
| 324 | bool operator==( const ConstMapRange& rhs ) const { return equal( rhs) ; } |
---|
| 325 | ///comparison operator for inequality |
---|
| 326 | bool operator!=( const ConstMapRange& rhs ) const { return !equal( rhs) ; } |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | #ifdef __Ogre_Iterator_Wrapper_H__ |
---|
| 330 | ///cast operator to a ConstMapIterator |
---|
| 331 | operator ConstMapIterator<T>(){return ConstMapIterator<T>( this->begin(),this->end());} |
---|
| 332 | #endif |
---|
| 333 | |
---|
| 334 | }; |
---|
| 335 | |
---|
| 336 | #include "OgreHeaderSuffix.h" |
---|
| 337 | |
---|
| 338 | } |
---|
| 339 | #endif |
---|