DoorKeeper/include/doorkeeper/components/tileiterator.hpp

69 lines
2.3 KiB
C++
Raw Normal View History

#ifndef id873715F57B504CCF8227CE03EA28CAFA
#define id873715F57B504CCF8227CE03EA28CAFA
#include "doorkeeper/primitivetypes.hpp"
#include "doorkeeper/implem/helpers.hpp"
2015-08-16 18:33:44 +00:00
#include "doorkeeper/components/tilecoords.hpp"
#include <boost/iterator/iterator_facade.hpp>
#include <iterator>
#include <vector>
#include <type_traits>
#include <cstdint>
2015-08-16 18:33:44 +00:00
#include <utility>
namespace dk {
template <typename T, uint32_t D, typename T1>
class TileIterator;
2014-12-12 19:04:48 +00:00
namespace implem {
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
} //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;
typedef std::vector<T1> vector_type;
typedef typename implem::TypeWithQualifiers<T, vector_type>::result qualif_vector_type;
public:
2015-08-16 18:33:44 +00:00
typedef TileCoords<D> TileCoordsType;
typedef typename TileCoordsType::coords coords;
2015-08-16 18:33:44 +00:00
TileIterator ( void ) = default;
TileIterator ( const TileIterator& parOther ) = default;
TileIterator ( TileIterator&& parOther ) = default;
2015-08-16 18:33:44 +00:00
TileIterator ( qualif_vector_type* parData, const coords& parArea );
TileIterator ( qualif_vector_type* parData, const coords& parStart, const coords& parArea );
~TileIterator ( void ) = default;
2015-08-16 18:33:44 +00:00
const TileCoordsType& raw_coords ( void ) const;
const coords& position ( void ) const;
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;
2015-08-16 18:33:44 +00:00
TileCoordsType m_tile_range;;
qualif_vector_type* m_data;
};
} //namespace dk
#include "doorkeeper/implem/tileiterator.inl"
#endif