DoorKeeper/include/doorkeeper/components/tileiterator.hpp

88 lines
3.4 KiB
C++
Raw Normal View History

#ifndef id873715F57B504CCF8227CE03EA28CAFA
#define id873715F57B504CCF8227CE03EA28CAFA
#include "doorkeeper/primitivetypes.hpp"
#include "doorkeeper/implem/helpers.hpp"
#include <boost/iterator/iterator_facade.hpp>
#include <iterator>
#include <vector>
#include <type_traits>
#include <cstdint>
#include <cassert>
namespace dk {
template <typename T, uint32_t D, typename T1>
class TileIterator;
2014-12-12 19:04:48 +00:00
namespace implem {
template <uint32_t D>
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
template <typename I, typename O>
struct TypeWithQualifiers {
typedef typename std::conditional<std::is_volatile<I>::value && std::is_const<I>::value,
typename std::add_cv<O>::type,
typename std::conditional<std::is_volatile<I>::value,
typename std::add_volatile<typename std::remove_cv<O>::type>::type,
typename std::conditional<std::is_const<I>::value,
typename std::add_const<typename std::remove_cv<O>::type>::type,
typename std::remove_cv<O>::type
>::type
>::type
>::type result;
};
2014-12-12 19:04:48 +00:00
#if defined(NDEBUG)
template <>
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
template <uint32_t D>
Vector<CoordinateScalarType, D> buildPastEndCoordinate ( const Vector<CoordinateScalarType, D>& parFrom, const Vector<CoordinateScalarType, D>& parTo ) a_pure;
template <typename T, uint32_t D, typename T1>
const Vector<CoordinateScalarType, D>& get_from_from_iterator ( const TileIterator<T, D, T1>& parIterator );
2014-12-12 19:04:48 +00:00
} //namespace implem
template <typename T, uint32_t D, typename T1=typename std::remove_cv<T>::type>
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;
friend const Vector<CoordinateScalarType, D>& implem::get_from_from_iterator<> ( const TileIterator& parIterator );
typedef std::vector<T1> vector_type;
typedef typename implem::TypeWithQualifiers<T, vector_type>::result qualif_vector_type;
public:
typedef Vector<CoordinateScalarType, D> coords;
TileIterator ( void );
TileIterator ( const TileIterator& parOther ) = default;
TileIterator ( TileIterator&& parOther ) = default;
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo );
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo );
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parSubdiv );
~TileIterator ( void ) = default;
const coords& abs_position ( void ) const { return m_pos; }
2014-12-12 19:04:48 +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;
size_t get_current_index ( void ) const { return implem::get_index_from_pos<D>(m_pos, m_subdivareasize) + m_subindex; }
coords m_pos;
coords m_from;
coords m_to;
coords m_subdivareasize;
qualif_vector_type* m_data;
CoordinateScalarType m_subindex;
CoordinateScalarType m_maxsubindex;
};
} //namespace dk
#include "doorkeeper/implem/tileiterator.inl"
#endif