Generic Image Library: position_iterator.hpp Source File

###  | #  |

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

position_iterator.hpp
Go to the documentation of this file.
1 /*
2 Copyright 2005-2007 Adobe Systems Incorporated
3
4 Use, modification and distribution are subject to the Boost Software License,
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt).
7
8 See http://opensource.adobe.com/gil for most recent version including documentation.
9 */
10
11 /*************************************************************************************************/
12
13 #ifndef GIL_POSITION_ITERATOR_HPP
14 #define GIL_POSITION_ITERATOR_HPP
15
24
25 #include <boost/iterator/iterator_facade.hpp>
26 #include "locator.hpp"
27
28 namespace boost { namespace gil {
29
33
34
38 template <typename Deref, // A function object that given a point returns a pixel reference. Models PixelDereferenceAdaptorConcept
39 int Dim> // the dimension to advance along
40 struct position_iterator : public iterator_facade<position_iterator<Deref,Dim>,
41 typename Deref::value_type,
42 std::random_access_iterator_tag,
43 typename Deref::reference,
44 typename Deref::argument_type::template axis<Dim>::coord_t> {
45 typedef iterator_facade<position_iterator<Deref,Dim>,
46 typename Deref::value_type,
47 std::random_access_iterator_tag,
48 typename Deref::reference,
49 typename Deref::argument_type::template axis<Dim>::coord_t> parent_t;
50 typedef typename parent_t::difference_type difference_type;
51 typedef typename parent_t::reference reference;
52 typedef typename Deref::argument_type point_t;
53
54 position_iterator() {}
55 position_iterator(const point_t& p, const point_t& step, const Deref& d) : _p(p), _step(step), _d(d) {}
56
57 position_iterator(const position_iterator& p) : _p(p._p), _step(p._step), _d(p._d) {}
58 template <typename D> position_iterator(const position_iterator<D,Dim>& p) : _p(p._p), _step(p._step), _d(p._d) {}
59 position_iterator& operator=(const position_iterator& p) { _p=p._p; _d=p._d; _step=p._step; return *this; }
60
61 const point_t& pos() const { return _p; }
62 const point_t& step() const { return _step; }
63 const Deref& deref_fn() const { return _d; }
64
65 void set_step(difference_type s) { _step[Dim]=s; }
68 reference operator[](difference_type d) const { point_t p=_p; p[Dim]+=d*_step[Dim]; return _d(p); }
69
70 private:
71 point_t _p, _step;
72 Deref _d;
73
74 template <typename DE, int DI> friend struct position_iterator;
75 friend class boost::iterator_core_access;
76 reference dereference() const { return _d(_p); }
77 void increment() { _p[Dim]+=_step[Dim]; }
78 void decrement() { _p[Dim]-=_step[Dim]; }
79 void advance(difference_type d) { _p[Dim]+=d*_step[Dim]; }
80
81 difference_type distance_to(const position_iterator& it) const { return (it._p[Dim]-_p[Dim])/_step[Dim]; }
82 bool equal(const position_iterator& it) const { return _p==it._p; }
83 };
84
85 template <typename Deref,int Dim>
86 struct const_iterator_type<position_iterator<Deref,Dim> > {
87 typedef position_iterator<typename Deref::const_t,Dim> type;
88 };
89
90 template <typename Deref,int Dim>
91 struct iterator_is_mutable<position_iterator<Deref,Dim> > : public mpl::bool_<Deref::is_mutable> {
92 };
93
95 // PixelBasedConcept
97
98 template <typename Deref,int Dim>
99 struct color_space_type<position_iterator<Deref,Dim> > : public color_space_type<typename Deref::value_type> {};
100
101 template <typename Deref,int Dim>
102 struct channel_mapping_type<position_iterator<Deref,Dim> > : public channel_mapping_type<typename Deref::value_type> {};
103
104 template <typename Deref,int Dim>
105 struct is_planar<position_iterator<Deref,Dim> > : public mpl::false_ {};
106
107 template <typename Deref,int Dim>
108 struct channel_type<position_iterator<Deref,Dim> > : public channel_type<typename Deref::value_type> {};
109
111 // HasDynamicXStepTypeConcept
113
114 template <typename Deref,int Dim>
115 struct dynamic_x_step_type<position_iterator<Deref,Dim> > {
116 typedef position_iterator<Deref,Dim> type;
117 };
118
119 } } // namespace boost::gil
120
121 #endif
boost::gil::position_iterator::operator[]
reference operator[](difference_type d) const
Definition: position_iterator.hpp:68
locator.hpp
pixel 2D locator
boost::gil::position_iterator
An iterator that remembers its current X,Y position and invokes a function object with it upon derefe...
Definition: position_iterator.hpp:40
std::equal
BOOST_FORCEINLINE bool equal(boost::gil::iterator_from_2d< Loc1 > first, boost::gil::iterator_from_2d< Loc1 > last, boost::gil::iterator_from_2d< Loc2 > first2)
std::equal(I1,I1,I2) with I1 and I2 being a iterator_from_2d
Definition: algorithm.hpp:934