OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreIteratorWrapper.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-2011 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_Wrapper_H__
29 #define __Ogre_Iterator_Wrapper_H__
30 
31 
32 namespace Ogre{
33 
45 template <typename T, typename IteratorType, typename ValType>
47 {
48 
49  private:
52 
53  protected:
54  IteratorType mBegin;
55  IteratorType mCurrent;
56  IteratorType mEnd;
57 
58 
59  public:
60 
62  typedef ValType ValueType;
64  typedef ValType* PointerType;
65 
73  typedef IteratorType iterator;
74 
82  typedef IteratorType const_iterator;
83 
84 
85 
86 
87 
92  IteratorWrapper ( IteratorType start, IteratorType last )
93  : mBegin( start ), mCurrent ( start ), mEnd ( last )
94  {
95  }
96 
97 
99  bool hasMoreElements ( ) const
100  {
101  return mCurrent != mEnd;
102  }
103 
104 
106  void moveNext ( )
107  {
108  ++mCurrent;
109  }
110 
112  const IteratorType& begin() {return mBegin;}
113 
114 
116  IteratorType& current(){return mCurrent;}
117 
119  const IteratorType& end() {return mEnd;}
120 
121 
122 };
123 
124 
125 
136 template <typename T, typename IteratorType>
137 class VectorIteratorWrapper : public IteratorWrapper<T, IteratorType, typename T::value_type>
138 {
139 
140  public:
143 
144 
153  VectorIteratorWrapper ( IteratorType start, IteratorType last )
154  : IteratorWrapper<T, IteratorType, typename T::value_type>( start, last )
155  {
156  }
157 
158 
160  ValueType peekNext ( ) const
161  {
162  return *(this->mCurrent);
163  }
164 
167  {
168  return &(*(this->mCurrent) );
169  }
170 
173  {
174  return *(this->mCurrent++);
175  }
176 
177 };
178 
179 
187 template <typename T>
188 class VectorIterator : public VectorIteratorWrapper<T, typename T::iterator>{
189  public:
194  VectorIterator( typename T::iterator start, typename T::iterator last )
195  : VectorIteratorWrapper<T, typename T::iterator>(start , last )
196  {
197  }
198 
203  explicit VectorIterator( T& c )
204  : VectorIteratorWrapper<T, typename T::iterator> ( c.begin(), c.end() )
205  {
206  }
207 
208 };
209 
218 template <typename T>
219 class ConstVectorIterator : public VectorIteratorWrapper<T, typename T::const_iterator>{
220  public:
225  ConstVectorIterator( typename T::const_iterator start, typename T::const_iterator last )
226  : VectorIteratorWrapper<T, typename T::const_iterator> (start , last )
227  {
228  }
229 
234  explicit ConstVectorIterator ( const T& c )
235  : VectorIteratorWrapper<T, typename T::const_iterator> (c.begin() , c.end() )
236  {
237  }
238 };
239 
240 
241 
242 
243 
254 template <typename T, typename IteratorType>
255 class MapIteratorWrapper : public IteratorWrapper<T, IteratorType, typename T::mapped_type>
256 {
257 
258  public:
263 
265  typedef typename T::value_type PairType ;
267  typedef typename T::key_type KeyType;
268 
273  MapIteratorWrapper ( IteratorType start, IteratorType last )
274  : IteratorWrapper<T, IteratorType, typename T::mapped_type>( start, last )
275  {
276  }
277 
279  KeyType peekNextKey(void) const
280  {
281  return this->mCurrent->first;
282  }
283 
284 
287  {
288  return this->mCurrent->second;
289  }
290 
291 
295  {
296  return &(this->mCurrent->second);
297  }
298 
299 
302  {
303  return ((this->mCurrent++)->second) ;
304  }
305 
306 
307 };
308 
309 
310 
311 
320 template <typename T>
321 class MapIterator : public MapIteratorWrapper<T, typename T::iterator>{
322  public:
323 
328  MapIterator( typename T::iterator start, typename T::iterator last )
329  : MapIteratorWrapper<T, typename T::iterator>(start , last )
330  {
331  }
332 
337  explicit MapIterator( T& c )
338  : MapIteratorWrapper<T, typename T::iterator> ( c.begin(), c.end() )
339  {
340  }
341 
342 };
343 
344 
353 template <typename T>
354 class ConstMapIterator : public MapIteratorWrapper<T, typename T::const_iterator>{
355  public:
356 
361  ConstMapIterator( typename T::const_iterator start, typename T::const_iterator last )
362  : MapIteratorWrapper<T, typename T::const_iterator> (start , last )
363  {
364  }
365 
370  explicit ConstMapIterator ( const T& c )
371  : MapIteratorWrapper<T, typename T::const_iterator> (c.begin() , c.end() )
372  {
373  }
374 };
375 
376 
377 
378 
379 }
380 
381 
382 
383 #endif
Basefunctionality for IteratorWrappers.
ValueType getNext()
Returns the next(=current) value element in the collection, and advances to the next.
IteratorWrapper< T, IteratorType, typename T::mapped_type >::ValueType ValueType
redefined ValueType for a map/set
const IteratorType & begin()
bookmark to the begin of the underlying collection
const PointerType peekNextValuePtr() const
Returns a pointer to the next/current value element in the collection, without advancing to the next ...
T::value_type PairType
unused, just to make it clear that map/set::value_type is not a ValueType
IteratorType const_iterator
typedef to fulfill container interface
const IteratorType & end()
bookmark to the end (one behind the last element) of the underlying collection
IteratorWrapper< T, IteratorType, typename T::value_type >::PointerType PointerType
IteratorType iterator
typedef to fulfill container interface
ValueType peekNext() const
Returns the next(=current) element in the collection, without advancing to the next.
Prepiared IteratorWrapper for container like std::vector.
IteratorWrapper()
Private constructor since only the parameterised constructor should be used.
IteratorWrapper< T, IteratorType, typename T::value_type >::ValueType ValueType
IteratorType & current()
full access to the current iterator
ConstVectorIterator(const T &c)
Constructor.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
bool hasMoreElements() const
Returns true if there are more items in the collection.
PointerType peekNextPtr() const
Returns a pointer to the next(=current) element in the collection, without advancing to the next afte...
MapIteratorWrapper(IteratorType start, IteratorType last)
Constructor.
T::key_type KeyType
type you expect to get by funktions like peekNextKey
MapIterator(typename T::iterator start, typename T::iterator last)
Constructor.
IteratorWrapper(IteratorType start, IteratorType last)
Constructor.
KeyType peekNextKey(void) const
Returns the next(=current) key element in the collection, without advancing to the next...
Concrete IteratorWrapper for const access to the underlying container.
VectorIteratorWrapper(IteratorType start, IteratorType last)
c'tor
IteratorWrapper< T, IteratorType, typename T::mapped_type >::PointerType PointerType
redefined PointerType for a map/set
VectorIterator(typename T::iterator start, typename T::iterator last)
Constructor.
ValueType peekNextValue() const
Returns the next(=current) value element in the collection, without advancing to the next...
VectorIterator(T &c)
Constructor.
void moveNext()
Moves the iterator on one element.
Concrete IteratorWrapper for const access to the underlying key-value container.
ConstVectorIterator(typename T::const_iterator start, typename T::const_iterator last)
Constructor.
ValType * PointerType
type you expect to get by funktions like peekNext(Value)Ptr
ValueType getNext()
Returns the next(=current) value element in the collection, and advances to the next.
ValType ValueType
type you expect to get by funktions like peekNext(Value)
Concrete IteratorWrapper for nonconst access to the underlying container.
ConstMapIterator(typename T::const_iterator start, typename T::const_iterator last)
Constructor.
Prepiared IteratorWrapper for key-value container.
ConstMapIterator(const T &c)
Constructor.
MapIterator(T &c)
Constructor.