DoorKeeper/include/components/tileiterator.hpp

56 lines
1.8 KiB
C++
Raw Normal View History

#ifndef id873715F57B504CCF8227CE03EA28CAFA
#define id873715F57B504CCF8227CE03EA28CAFA
#include "primitivetypes.hpp"
#include <boost/iterator/iterator_facade.hpp>
#include <iterator>
#include <vector>
namespace dk {
2014-12-12 19:04:48 +00:00
namespace implem {
template <size_t D>
inline size_t get_index_from_pos ( const Vector<CoordinateScalarType, D>& parPos, const Vector<CoordinateScalarType, D>& parSize ) a_pure;
#if defined(NDEBUG)
template <>
2014-12-12 23:22:50 +00:00
inline size_t get_index_from_pos<2> ( const Vector<CoordinateScalarType, 2>& parPos, const Vector<CoordinateScalarType, 2>& parSize ) a_pure;
2014-12-12 19:04:48 +00:00
#endif
} //namespace implem
template <typename T, size_t D>
2014-12-12 19:04:48 +00:00
class TileIterator : public boost::iterator_facade<TileIterator<T, D>, T, boost::bidirectional_traversal_tag> {
friend class boost::iterator_core_access;
public:
typedef Vector<CoordinateScalarType, D> coords;
TileIterator ( void );
TileIterator ( const TileIterator& parOther ) = default;
2014-12-12 19:04:48 +00:00
TileIterator ( std::vector<T>* parData, const coords& parFrom, const coords& parTo );
TileIterator ( std::vector<T>* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parTotal );
~TileIterator ( void ) = default;
2014-12-12 19:04:48 +00:00
const coords& position ( void ) const { return m_pos; }
private:
void increment ( void );
void decrement ( void );
void advance ( size_t parAdvance );
2014-12-12 19:04:48 +00:00
ptrdiff_t distance_to ( const TileIterator& parOther );
bool equal ( const TileIterator& parOther ) const;
T& dereference ( void ) const { return (*m_data)[get_current_index()]; }
2014-12-12 23:22:50 +00:00
size_t get_current_index ( void ) const { return implem::get_index_from_pos<D>(m_pos, m_total); }
coords m_pos;
coords m_from;
coords m_to;
coords m_areafrom;
coords m_areato;
coords m_total;
std::vector<T>* m_data;
};
} //namespace dk
#include "implem/tileiterator.inl"
#endif