OgreIteratorWrapper.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Ogre_Iterator_Wrapper_H__
#define __Ogre_Iterator_Wrapper_H__
#include "OgreHeaderPrefix.h"
namespace Ogre{
template <typename T, typename IteratorType, typename ValType>
class IteratorWrapper
{
private:
IteratorWrapper();
protected:
IteratorType mBegin;
IteratorType mCurrent;
IteratorType mEnd;
public:
typedef ValType ValueType;
typedef ValType* PointerType;
typedef IteratorType iterator;
typedef IteratorType const_iterator;
IteratorWrapper ( IteratorType start, IteratorType last )
: mBegin( start ), mCurrent ( start ), mEnd ( last )
{
}
bool hasMoreElements ( ) const
{
return mCurrent != mEnd;
}
void moveNext ( )
{
++mCurrent;
}
const IteratorType& begin() {return mBegin;}
IteratorType& current(){return mCurrent;}
const IteratorType& end() {return mEnd;}
};
template <typename T, typename IteratorType>
class VectorIteratorWrapper : public IteratorWrapper<T, IteratorType, typename T::value_type>
{
public:
typedef typename IteratorWrapper<T, IteratorType, typename T::value_type>::ValueType ValueType ;
typedef typename IteratorWrapper<T, IteratorType, typename T::value_type>::PointerType PointerType ;
VectorIteratorWrapper ( IteratorType start, IteratorType last )
: IteratorWrapper<T, IteratorType, typename T::value_type>( start, last )
{
}
ValueType peekNext ( ) const
{
return *(this->mCurrent);
}
PointerType peekNextPtr ( ) const
{
return &(*(this->mCurrent) );
}
ValueType getNext ( )
{
return *(this->mCurrent++);
}
};
template <typename T>
class VectorIterator : public VectorIteratorWrapper<T, typename T::iterator>{
public:
VectorIterator( typename T::iterator start, typename T::iterator last )
: VectorIteratorWrapper<T, typename T::iterator>(start , last )
{
}
explicit VectorIterator( T& c )
: VectorIteratorWrapper<T, typename T::iterator> ( c.begin(), c.end() )
{
}
};
template <typename T>
class ConstVectorIterator : public VectorIteratorWrapper<T, typename T::const_iterator>{
public:
ConstVectorIterator( typename T::const_iterator start, typename T::const_iterator last )
: VectorIteratorWrapper<T, typename T::const_iterator> (start , last )
{
}
explicit ConstVectorIterator ( const T& c )
: VectorIteratorWrapper<T, typename T::const_iterator> (c.begin() , c.end() )
{
}
};
template <typename T, typename IteratorType>
class MapIteratorWrapper : public IteratorWrapper<T, IteratorType, typename T::mapped_type>
{
public:
typedef typename IteratorWrapper<T, IteratorType, typename T::mapped_type>::ValueType ValueType ;
typedef typename IteratorWrapper<T, IteratorType, typename T::mapped_type>::PointerType PointerType ;
typedef typename T::value_type PairType ;
typedef typename T::key_type KeyType;
MapIteratorWrapper ( IteratorType start, IteratorType last )
: IteratorWrapper<T, IteratorType, typename T::mapped_type>( start, last )
{
}
KeyType peekNextKey(void) const
{
return this->mCurrent->first;
}
ValueType peekNextValue ( ) const
{
return this->mCurrent->second;
}
const PointerType peekNextValuePtr ( ) const
{
return &(this->mCurrent->second);
}
ValueType getNext()
{
return ((this->mCurrent++)->second) ;
}
};
template <typename T>
class MapIterator : public MapIteratorWrapper<T, typename T::iterator>{
public:
MapIterator( typename T::iterator start, typename T::iterator last )
: MapIteratorWrapper<T, typename T::iterator>(start , last )
{
}
explicit MapIterator( T& c )
: MapIteratorWrapper<T, typename T::iterator> ( c.begin(), c.end() )
{
}
};
template <typename T>
class ConstMapIterator : public MapIteratorWrapper<T, typename T::const_iterator>{
public:
ConstMapIterator( typename T::const_iterator start, typename T::const_iterator last )
: MapIteratorWrapper<T, typename T::const_iterator> (start , last )
{
}
explicit ConstMapIterator ( const T& c )
: MapIteratorWrapper<T, typename T::const_iterator> (c.begin() , c.end() )
{
}
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::ConstMapIterator::ConstMapIterator
ConstMapIterator(const T &c)
Constructor.
Definition: OgreIteratorWrapper.h:368
Ogre::VectorIterator
Concrete IteratorWrapper for nonconst access to the underlying container.
Definition: OgreIteratorWrapper.h:186
Ogre::IteratorWrapper::moveNext
void moveNext()
Moves the iterator on one element.
Definition: OgreIteratorWrapper.h:104
Ogre::IteratorWrapper::current
IteratorType & current()
Full access to the current iterator.
Definition: OgreIteratorWrapper.h:114
Ogre::MapIteratorWrapper::getNext
ValueType getNext()
Returns the next(=current) value element in the collection, and advances to the next.
Definition: OgreIteratorWrapper.h:299
Ogre::VectorIterator::VectorIterator
VectorIterator(typename T::iterator start, typename T::iterator last)
Constructor.
Definition: OgreIteratorWrapper.h:192
Ogre::VectorIteratorWrapper::peekNext
ValueType peekNext() const
Returns the next(=current) element in the collection, without advancing to the next.
Definition: OgreIteratorWrapper.h:158
Ogre::ConstMapIterator::ConstMapIterator
ConstMapIterator(typename T::const_iterator start, typename T::const_iterator last)
Constructor.
Definition: OgreIteratorWrapper.h:359
Ogre::MapIterator
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:319
Ogre::ConstMapIterator
Concrete IteratorWrapper for const access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:352
Ogre::IteratorWrapper::const_iterator
IteratorType const_iterator
Typedef to fulfill container interface.
Definition: OgreIteratorWrapper.h:83
Ogre::MapIterator::MapIterator
MapIterator(typename T::iterator start, typename T::iterator last)
Constructor.
Definition: OgreIteratorWrapper.h:326
Ogre::VectorIteratorWrapper::PointerType
IteratorWrapper< T, IteratorType, typename T::value_type >::PointerType PointerType
Definition: OgreIteratorWrapper.h:140
Ogre::IteratorWrapper::iterator
IteratorType iterator
Typedef to fulfill container interface.
Definition: OgreIteratorWrapper.h:74
Ogre::MapIteratorWrapper::peekNextKey
KeyType peekNextKey(void) const
Returns the next(=current) key element in the collection, without advancing to the next...
Definition: OgreIteratorWrapper.h:277
Ogre::VectorIterator::VectorIterator
VectorIterator(T &c)
Constructor.
Definition: OgreIteratorWrapper.h:201
Ogre::MapIterator::MapIterator
MapIterator(T &c)
Constructor.
Definition: OgreIteratorWrapper.h:335
Ogre::IteratorWrapper
Basefunctionality for IteratorWrappers.
Definition: OgreIteratorWrapper.h:47
Ogre::ConstVectorIterator::ConstVectorIterator
ConstVectorIterator(const T &c)
Constructor.
Definition: OgreIteratorWrapper.h:232
Ogre::IteratorWrapper::end
const IteratorType & end()
Bookmark to the end (one behind the last element) of the underlying collection.
Definition: OgreIteratorWrapper.h:117
Ogre::IteratorWrapper::IteratorWrapper
IteratorWrapper(IteratorType start, IteratorType last)
Constructor.
Definition: OgreIteratorWrapper.h:90
Ogre::IteratorWrapper::mEnd
IteratorType mEnd
Definition: OgreIteratorWrapper.h:57
Ogre::MapIteratorWrapper::KeyType
T::key_type KeyType
Type you expect to get by funktions like peekNextKey.
Definition: OgreIteratorWrapper.h:265
Ogre::VectorIteratorWrapper
Prepared IteratorWrapper for container like std::vector.
Definition: OgreIteratorWrapper.h:135
Ogre::MapIteratorWrapper::MapIteratorWrapper
MapIteratorWrapper(IteratorType start, IteratorType last)
Constructor.
Definition: OgreIteratorWrapper.h:271
OgreHeaderSuffix.h
Ogre::MapIteratorWrapper::peekNextValue
ValueType peekNextValue() const
Returns the next(=current) value element in the collection, without advancing to the next...
Definition: OgreIteratorWrapper.h:284
Ogre::MapIteratorWrapper
Prepared IteratorWrapper for key-value container.
Definition: OgreIteratorWrapper.h:253
Ogre::MapIteratorWrapper::ValueType
IteratorWrapper< T, IteratorType, typename T::mapped_type >::ValueType ValueType
Redefined ValueType for a map/set.
Definition: OgreIteratorWrapper.h:258
Ogre::MapIteratorWrapper::peekNextValuePtr
const PointerType peekNextValuePtr() const
Returns a pointer to the next/current value element in the collection, without advancing to the next ...
Definition: OgreIteratorWrapper.h:292
Ogre::IteratorWrapper::IteratorWrapper
IteratorWrapper()
Private constructor since only the parameterised constructor should be used.
Ogre::MapIteratorWrapper::PointerType
IteratorWrapper< T, IteratorType, typename T::mapped_type >::PointerType PointerType
Redefined PointerType for a map/set.
Definition: OgreIteratorWrapper.h:260
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::IteratorWrapper::mBegin
IteratorType mBegin
Definition: OgreIteratorWrapper.h:55
Ogre::IteratorWrapper::begin
const IteratorType & begin()
Bookmark to the begin of the underlying collection.
Definition: OgreIteratorWrapper.h:110
Ogre::VectorIteratorWrapper::getNext
ValueType getNext()
Returns the next(=current) value element in the collection, and advances to the next.
Definition: OgreIteratorWrapper.h:170
Ogre::MapIteratorWrapper::PairType
T::value_type PairType
Unused, just to make it clear that map/set::value_type is not a ValueType.
Definition: OgreIteratorWrapper.h:263
Ogre::ConstVectorIterator
Concrete IteratorWrapper for const access to the underlying container.
Definition: OgreIteratorWrapper.h:217
OgreHeaderPrefix.h
Ogre::IteratorWrapper::PointerType
ValType * PointerType
Type you expect to get by funktions like peekNext(Value)Ptr.
Definition: OgreIteratorWrapper.h:65
Ogre::VectorIteratorWrapper::ValueType
IteratorWrapper< T, IteratorType, typename T::value_type >::ValueType ValueType
Definition: OgreIteratorWrapper.h:139
Ogre::IteratorWrapper::ValueType
ValType ValueType
Type you expect to get by funktions like peekNext(Value)
Definition: OgreIteratorWrapper.h:63
Ogre::IteratorWrapper::hasMoreElements
bool hasMoreElements() const
Returns true if there are more items in the collection.
Definition: OgreIteratorWrapper.h:97
Ogre::VectorIteratorWrapper::peekNextPtr
PointerType peekNextPtr() const
Returns a pointer to the next(=current) element in the collection, without advancing to the next afte...
Definition: OgreIteratorWrapper.h:164
Ogre::ConstVectorIterator::ConstVectorIterator
ConstVectorIterator(typename T::const_iterator start, typename T::const_iterator last)
Constructor.
Definition: OgreIteratorWrapper.h:223
Ogre::VectorIteratorWrapper::VectorIteratorWrapper
VectorIteratorWrapper(IteratorType start, IteratorType last)
c&#39;tor
Definition: OgreIteratorWrapper.h:151
Ogre::IteratorWrapper::mCurrent
IteratorType mCurrent
Definition: OgreIteratorWrapper.h:56

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.