File indexing completed on 2024-11-15 09:12:42
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_GIL_POSITION_ITERATOR_HPP
0009 #define BOOST_GIL_POSITION_ITERATOR_HPP
0010
0011 #include <boost/gil/locator.hpp>
0012
0013 #include <boost/iterator/iterator_facade.hpp>
0014
0015 #include <type_traits>
0016
0017 namespace boost { namespace gil {
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 template <typename Deref, int Dim>
0031 struct position_iterator : public iterator_facade<position_iterator<Deref,Dim>,
0032 typename Deref::value_type,
0033 std::random_access_iterator_tag,
0034 typename Deref::reference,
0035 typename Deref::argument_type::template axis<Dim>::coord_t> {
0036 using parent_t = iterator_facade<position_iterator<Deref,Dim>,
0037 typename Deref::value_type,
0038 std::random_access_iterator_tag,
0039 typename Deref::reference,
0040 typename Deref::argument_type::template axis<Dim>::coord_t>;
0041 using difference_type = typename parent_t::difference_type;
0042 using reference = typename parent_t::reference;
0043 using point_t = typename Deref::argument_type;
0044
0045 position_iterator() {}
0046 position_iterator(point_t const& p, point_t const& step, Deref const& d) : _p(p), _step(step), _d(d) {}
0047
0048 position_iterator(position_iterator const& p) : _p(p._p), _step(p._step), _d(p._d) {}
0049
0050 template <typename D>
0051 position_iterator(position_iterator<D,Dim> const& p) : _p(p._p), _step(p._step), _d(p._d) {}
0052
0053 auto operator=(position_iterator const& p) -> position_iterator&
0054 {
0055 _p=p._p;
0056 _d=p._d;
0057 _step=p._step;
0058 return *this;
0059 }
0060
0061 auto pos() const -> point_t const& { return _p; }
0062 auto step() const -> point_t const& { return _step; }
0063 auto deref_fn() const -> Deref const& { return _d; }
0064
0065 void set_step(difference_type s) { _step[Dim]=s; }
0066
0067
0068 auto operator[](difference_type d) const -> reference
0069 {
0070 point_t p=_p;
0071 p[Dim]+=d*_step[Dim];
0072 return _d(p);
0073 }
0074
0075 private:
0076 point_t _p, _step;
0077 Deref _d;
0078
0079 template <typename DE, int DI> friend struct position_iterator;
0080 friend class boost::iterator_core_access;
0081 reference dereference() const { return _d(_p); }
0082 void increment() { _p[Dim]+=_step[Dim]; }
0083 void decrement() { _p[Dim]-=_step[Dim]; }
0084 void advance(difference_type d) { _p[Dim]+=d*_step[Dim]; }
0085
0086 difference_type distance_to(const position_iterator& it) const { return (it._p[Dim]-_p[Dim])/_step[Dim]; }
0087 bool equal(const position_iterator& it) const { return _p==it._p; }
0088 };
0089
0090 template <typename Deref,int Dim>
0091 struct const_iterator_type<position_iterator<Deref,Dim> > {
0092 using type = position_iterator<typename Deref::const_t,Dim>;
0093 };
0094
0095 template <typename Deref, int Dim>
0096 struct iterator_is_mutable<position_iterator<Deref, Dim>>
0097 : std::integral_constant<bool, Deref::is_mutable>
0098 {
0099 };
0100
0101
0102
0103
0104
0105 template <typename Deref,int Dim>
0106 struct color_space_type<position_iterator<Deref,Dim> > : public color_space_type<typename Deref::value_type> {};
0107
0108 template <typename Deref,int Dim>
0109 struct channel_mapping_type<position_iterator<Deref,Dim> > : public channel_mapping_type<typename Deref::value_type> {};
0110
0111 template <typename Deref,int Dim>
0112 struct is_planar<position_iterator<Deref, Dim>> : std::false_type {};
0113
0114 template <typename Deref,int Dim>
0115 struct channel_type<position_iterator<Deref,Dim> > : public channel_type<typename Deref::value_type> {};
0116
0117
0118
0119
0120
0121 template <typename Deref,int Dim>
0122 struct dynamic_x_step_type<position_iterator<Deref,Dim> > {
0123 using type = position_iterator<Deref,Dim>;
0124 };
0125
0126 } }
0127
0128 #endif