2014-12-09 21:30:06 +00:00
|
|
|
#ifndef id873715F57B504CCF8227CE03EA28CAFA
|
|
|
|
#define id873715F57B504CCF8227CE03EA28CAFA
|
|
|
|
|
2014-12-11 22:58:52 +00:00
|
|
|
#include "primitivetypes.hpp"
|
2014-12-09 21:30:06 +00:00
|
|
|
#include <boost/iterator/iterator_facade.hpp>
|
|
|
|
#include <iterator>
|
2014-12-11 22:58:52 +00:00
|
|
|
#include <vector>
|
2014-12-09 21:30:06 +00:00
|
|
|
|
|
|
|
namespace dk {
|
2014-12-12 19:04:48 +00:00
|
|
|
namespace implem {
|
|
|
|
template <size_t D>
|
2014-12-14 12:13:10 +00:00
|
|
|
size_t get_index_from_pos ( const Vector<CoordinateScalarType, D>& parPos, const Vector<CoordinateScalarType, D>& parSize ) a_pure;
|
2014-12-12 19:04:48 +00:00
|
|
|
|
|
|
|
#if defined(NDEBUG)
|
|
|
|
template <>
|
2014-12-14 12:13:10 +00:00
|
|
|
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
|
2014-12-14 12:13:10 +00:00
|
|
|
|
|
|
|
template <size_t D>
|
|
|
|
Vector<CoordinateScalarType, D> buildPastEndCoordinate ( const Vector<CoordinateScalarType, D>& parFrom, const Vector<CoordinateScalarType, D>& parTo ) a_pure;
|
2014-12-12 19:04:48 +00:00
|
|
|
} //namespace implem
|
|
|
|
|
2014-12-09 21:30:06 +00:00
|
|
|
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> {
|
2014-12-09 21:30:06 +00:00
|
|
|
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 );
|
2014-12-14 12:13:10 +00:00
|
|
|
TileIterator ( std::vector<T>* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo );
|
2014-12-09 21:30:06 +00:00
|
|
|
~TileIterator ( void ) = default;
|
|
|
|
|
2014-12-12 19:04:48 +00:00
|
|
|
const coords& position ( void ) const { return m_pos; }
|
|
|
|
|
2014-12-09 21:30:06 +00:00
|
|
|
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-14 12:13:10 +00:00
|
|
|
size_t get_current_index ( void ) const { return implem::get_index_from_pos<D>(m_pos, m_areato - m_areafrom); }
|
2014-12-09 21:30:06 +00:00
|
|
|
|
|
|
|
coords m_pos;
|
|
|
|
coords m_from;
|
|
|
|
coords m_to;
|
|
|
|
coords m_areafrom;
|
|
|
|
coords m_areato;
|
2014-12-11 22:58:52 +00:00
|
|
|
std::vector<T>* m_data;
|
2014-12-09 21:30:06 +00:00
|
|
|
};
|
|
|
|
} //namespace dk
|
|
|
|
|
|
|
|
#include "implem/tileiterator.inl"
|
|
|
|
|
|
|
|
#endif
|