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/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-09 21:30:06 +00:00
|
|
|
#ifndef id873715F57B504CCF8227CE03EA28CAFA
|
|
|
|
#define id873715F57B504CCF8227CE03EA28CAFA
|
|
|
|
|
2015-01-06 15:38:52 +00:00
|
|
|
#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"
|
2015-08-18 22:15:31 +00:00
|
|
|
#include "doorkeeper/components/tile.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-30 16:53:15 +00:00
|
|
|
#include <type_traits>
|
2015-01-08 11:20:17 +00:00
|
|
|
#include <cstdint>
|
2015-08-16 18:33:44 +00:00
|
|
|
#include <utility>
|
2015-08-24 22:30:33 +00:00
|
|
|
#include <limits>
|
2014-12-09 21:30:06 +00:00
|
|
|
|
|
|
|
namespace dk {
|
2015-05-24 15:17:53 +00:00
|
|
|
template <typename T, uint32_t D, typename T1>
|
|
|
|
class TileIterator;
|
|
|
|
|
2014-12-12 19:04:48 +00:00
|
|
|
namespace implem {
|
2014-12-30 16:53:15 +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
|
|
|
} //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.
|
2015-01-08 11:20:17 +00:00
|
|
|
template <typename T, uint32_t D, typename T1=typename std::remove_cv<T>::type>
|
2015-08-18 22:15:31 +00:00
|
|
|
class TileIterator : public boost::iterator_facade<TileIterator<T, D>, T, boost::random_access_traversal_tag, Tile<T, D>, CoordinateDistType> {
|
2014-12-09 21:30:06 +00:00
|
|
|
friend class boost::iterator_core_access;
|
2014-12-30 16:53:15 +00:00
|
|
|
typedef std::vector<T1> vector_type;
|
|
|
|
typedef typename implem::TypeWithQualifiers<T, vector_type>::result qualif_vector_type;
|
2015-08-18 22:15:31 +00:00
|
|
|
typedef boost::iterator_facade<TileIterator<T, D>, T, boost::random_access_traversal_tag, Tile<T, D>, CoordinateDistType> base_class;
|
2014-12-09 21:30:06 +00:00
|
|
|
public:
|
2015-08-16 18:33:44 +00:00
|
|
|
typedef TileCoords<D> TileCoordsType;
|
|
|
|
typedef typename TileCoordsType::coords coords;
|
2015-08-18 22:15:31 +00:00
|
|
|
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;
|
2014-12-09 21:30:06 +00:00
|
|
|
|
2015-08-16 18:33:44 +00:00
|
|
|
TileIterator ( void ) = default;
|
2014-12-09 21:30:06 +00:00
|
|
|
TileIterator ( const TileIterator& parOther ) = default;
|
2014-12-30 16:53:15 +00:00
|
|
|
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 );
|
2014-12-09 21:30:06 +00:00
|
|
|
~TileIterator ( void ) = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void increment ( void );
|
|
|
|
void decrement ( void );
|
|
|
|
void advance ( size_t parAdvance );
|
2015-08-18 22:15:31 +00:00
|
|
|
difference_type distance_to ( const TileIterator& parOther );
|
2014-12-12 19:04:48 +00:00
|
|
|
bool equal ( const TileIterator& parOther ) const;
|
2015-08-18 22:15:31 +00:00
|
|
|
reference dereference ( void ) const;
|
2014-12-09 21:30:06 +00:00
|
|
|
|
2015-08-16 18:33:44 +00:00
|
|
|
TileCoordsType m_tile_range;;
|
2014-12-30 16:53:15 +00:00
|
|
|
qualif_vector_type* m_data;
|
2015-08-17 22:03:27 +00:00
|
|
|
const PixelConv<D>& m_pixel_conv;
|
2014-12-09 21:30:06 +00:00
|
|
|
};
|
2015-08-16 22:41:21 +00:00
|
|
|
|
|
|
|
template <uint32_t D>
|
|
|
|
Vector<D> make_past_end_coords ( const Vector<D>& parTo ) a_pure;
|
2014-12-09 21:30:06 +00:00
|
|
|
} //namespace dk
|
|
|
|
|
2015-01-06 15:38:52 +00:00
|
|
|
#include "doorkeeper/implem/tileiterator.inl"
|
2014-12-09 21:30:06 +00:00
|
|
|
|
|
|
|
#endif
|