00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef GIL_POSITION_ITERATOR_HPP
00014 #define GIL_POSITION_ITERATOR_HPP
00015
00024
00025 #include <boost/iterator/iterator_facade.hpp>
00026 #include "locator.hpp"
00027
00028 namespace boost { namespace gil {
00029
00033
00034
00038 template <typename Deref,
00039 int Dim>
00040 struct position_iterator : public iterator_facade<position_iterator<Deref,Dim>,
00041 typename Deref::value_type,
00042 random_access_traversal_tag,
00043 typename Deref::reference,
00044 typename Deref::argument_type::template axis<Dim>::coord_t> {
00045 typedef iterator_facade<position_iterator<Deref,Dim>,
00046 typename Deref::value_type,
00047 random_access_traversal_tag,
00048 typename Deref::reference,
00049 typename Deref::argument_type::template axis<Dim>::coord_t> parent_t;
00050 typedef typename parent_t::difference_type difference_type;
00051 typedef typename parent_t::reference reference;
00052 typedef typename Deref::argument_type point_t;
00053
00054 position_iterator() {}
00055 position_iterator(const point_t& p, const point_t& step, const Deref& d) : _p(p), _step(step), _d(d) {}
00056
00057 position_iterator(const position_iterator& p) : _p(p._p), _step(p._step), _d(p._d) {}
00058 template <typename D> position_iterator(const position_iterator<D,Dim>& p) : _p(p._p), _step(p._step), _d(p._d) {}
00059 position_iterator& operator=(const position_iterator& p) { _p=p._p; _d=p._d; _step=p._step; return *this; }
00060
00061 const point_t& pos() const { return _p; }
00062 const point_t& step() const { return _step; }
00063 const Deref& deref_fn() const { return _d; }
00064
00065 void set_step(difference_type s) { _step[Dim]=s; }
00068 reference operator[](difference_type d) const { point_t p=_p; p[Dim]+=d*_step[Dim]; return _d(p); }
00069
00070 private:
00071 point_t _p, _step;
00072 Deref _d;
00073
00074 template <typename DE, int DI> friend struct position_iterator;
00075 friend class boost::iterator_core_access;
00076 reference dereference() const { return _d(_p); }
00077 void increment() { _p[Dim]+=_step[Dim]; }
00078 void decrement() { _p[Dim]-=_step[Dim]; }
00079 void advance(difference_type d) { _p[Dim]+=d*_step[Dim]; }
00080
00081 difference_type distance_to(const position_iterator& it) const { return (it._p[Dim]-_p[Dim])/_step[Dim]; }
00082 bool equal(const position_iterator& it) const { return _p==it._p; }
00083 };
00084
00085 template <typename Deref,int Dim>
00086 struct const_iterator_type<position_iterator<Deref,Dim> > {
00087 typedef position_iterator<typename Deref::const_t,Dim> type;
00088 };
00089
00090 template <typename Deref,int Dim>
00091 struct iterator_is_mutable<position_iterator<Deref,Dim> > : public mpl::bool_<Deref::is_mutable> {
00092 };
00093
00095
00097
00098 template <typename Deref,int Dim>
00099 struct color_space_type<position_iterator<Deref,Dim> > : public color_space_type<typename Deref::value_type> {};
00100
00101 template <typename Deref,int Dim>
00102 struct channel_mapping_type<position_iterator<Deref,Dim> > : public channel_mapping_type<typename Deref::value_type> {};
00103
00104 template <typename Deref,int Dim>
00105 struct is_planar<position_iterator<Deref,Dim> > : public mpl::false_ {};
00106
00107 template <typename Deref,int Dim>
00108 struct channel_type<position_iterator<Deref,Dim> > : public channel_type<typename Deref::value_type> {};
00109
00111
00113
00114 template <typename Deref,int Dim>
00115 struct dynamic_x_step_type<position_iterator<Deref,Dim> > {
00116 typedef position_iterator<Deref,Dim> type;
00117 };
00118
00119 } }
00120
00121 #endif