DoorKeeper/include/doorkeeper/components/tileiterator.hpp

102 lines
4 KiB
C++
Raw Normal View History

2015-08-19 19:06:58 +00:00
/* Copyright 2015, Michele Santullo
* This file is part of DoorKeeper.
*
* DoorKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DoorKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
#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"
2015-08-17 22:03:27 +00:00
#include "doorkeeper/components/pixelconv.hpp"
#include "doorkeeper/components/tile.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>
2015-08-24 22:30:33 +00:00
#include <limits>
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
2015-08-24 22:30:33 +00:00
//TODO: replace with a custom iterator rewrite, not using iterator_facade.
//The idea is to have operator* return a Tile<>, which is heavy to
//construct but it's unlikely to be called very often, and then have
//operator-> return a TileHandle<> object that only wraps a pointer to
//the iterator's current state, so it's much more lightweight and it's not
//expected to be kept around by client code.
template <typename T, uint32_t D, typename T1=typename std::remove_cv<T>::type>
class TileIterator : public boost::iterator_facade<TileIterator<T, D>, T, boost::random_access_traversal_tag, Tile<T, D>, CoordinateDistType> {
friend class boost::iterator_core_access;
typedef std::vector<T1> vector_type;
typedef typename implem::TypeWithQualifiers<T, vector_type>::result qualif_vector_type;
typedef boost::iterator_facade<TileIterator<T, D>, T, boost::random_access_traversal_tag, Tile<T, D>, CoordinateDistType> base_class;
public:
2015-08-16 18:33:44 +00:00
typedef TileCoords<D> TileCoordsType;
typedef typename TileCoordsType::coords coords;
typedef typename base_class::difference_type difference_type;
typedef typename base_class::value_type value_type;
typedef typename base_class::pointer pointer;
typedef typename base_class::reference reference;
typedef typename base_class::iterator_category iterator_category;
2015-08-16 18:33:44 +00:00
TileIterator ( void ) = default;
TileIterator ( const TileIterator& parOther ) = default;
TileIterator ( TileIterator&& parOther ) = default;
2015-08-17 22:03:27 +00:00
TileIterator ( qualif_vector_type* parData, const PixelConv<D>& parPixConv, const coords& parArea );
TileIterator ( qualif_vector_type* parData, const PixelConv<D>& parPixConv, const coords& parStart, const coords& parArea );
~TileIterator ( void ) = default;
private:
void increment ( void );
void decrement ( void );
void advance ( size_t parAdvance );
difference_type distance_to ( const TileIterator& parOther );
2014-12-12 19:04:48 +00:00
bool equal ( const TileIterator& parOther ) const;
reference dereference ( void ) const;
2015-08-16 18:33:44 +00:00
TileCoordsType m_tile_range;;
qualif_vector_type* m_data;
2015-08-17 22:03:27 +00:00
const PixelConv<D>& m_pixel_conv;
};
template <uint32_t D>
Vector<D> make_past_end_coords ( const Vector<D>& parTo ) a_pure;
} //namespace dk
#include "doorkeeper/implem/tileiterator.inl"
#endif