Boost GIL


concepts/pixel_iterator.hpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #ifndef BOOST_GIL_CONCEPTS_PIXEL_ITERATOR_HPP
9 #define BOOST_GIL_CONCEPTS_PIXEL_ITERATOR_HPP
10 
11 #include <boost/gil/concepts/channel.hpp>
12 #include <boost/gil/concepts/color.hpp>
13 #include <boost/gil/concepts/concept_check.hpp>
14 #include <boost/gil/concepts/fwd.hpp>
15 #include <boost/gil/concepts/pixel.hpp>
16 #include <boost/gil/concepts/pixel_based.hpp>
17 
18 #include <boost/iterator/iterator_concepts.hpp>
19 
20 #include <cstddef>
21 #include <iterator>
22 #include <type_traits>
23 
24 #if defined(BOOST_CLANG)
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wunknown-pragmas"
27 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
28 #endif
29 
30 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
33 #endif
34 
35 namespace boost { namespace gil {
36 
37 // Forward declarations
38 template <typename It> struct const_iterator_type;
39 template <typename It> struct iterator_is_mutable;
40 template <typename It> struct is_iterator_adaptor;
41 template <typename It, typename NewBaseIt> struct iterator_adaptor_rebind;
42 template <typename It> struct iterator_adaptor_get_base;
43 
44 // These iterator mutability concepts are taken from Boost concept_check.hpp.
45 // Isolating mutability to result in faster compile time
46 namespace detail {
47 
48 // Preconditions: TT Models boost_concepts::ForwardTraversalConcept
49 template <class TT>
50 struct ForwardIteratorIsMutableConcept
51 {
52  void constraints()
53  {
54  auto const tmp = *i;
55  *i++ = tmp; // require postincrement and assignment
56  }
57  TT i;
58 };
59 
60 // Preconditions: TT Models boost::BidirectionalIteratorConcept
61 template <class TT>
62 struct BidirectionalIteratorIsMutableConcept
63 {
64  void constraints()
65  {
66  gil_function_requires< ForwardIteratorIsMutableConcept<TT>>();
67  auto const tmp = *i;
68  *i-- = tmp; // require postdecrement and assignment
69  }
70  TT i;
71 };
72 
73 // Preconditions: TT Models boost_concepts::RandomAccessTraversalConcept
74 template <class TT>
75 struct RandomAccessIteratorIsMutableConcept
76 {
77  void constraints()
78  {
79  gil_function_requires<BidirectionalIteratorIsMutableConcept<TT>>();
80 
81  typename std::iterator_traits<TT>::difference_type n = 0;
82  ignore_unused_variable_warning(n);
83  i[n] = *i; // require element access and assignment
84  }
85  TT i;
86 };
87 
88 // Iterators that can be used as the base of memory_based_step_iterator require some additional functions
89 // \tparam Iterator Models boost_concepts::RandomAccessTraversalConcept
90 template <typename Iterator>
91 struct RandomAccessIteratorIsMemoryBasedConcept
92 {
93  void constraints()
94  {
95  std::ptrdiff_t bs = memunit_step(it);
96  ignore_unused_variable_warning(bs);
97 
98  it = memunit_advanced(it, 3);
99  std::ptrdiff_t bd = memunit_distance(it, it);
100  ignore_unused_variable_warning(bd);
101 
102  memunit_advance(it,3);
103  // for performace you may also provide a customized implementation of memunit_advanced_ref
104  }
105  Iterator it;
106 };
107 
109 template <typename Iterator>
111 {
112  void constraints()
113  {
114  gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<Iterator>>();
115 
116  using ref_t = typename std::remove_reference
117  <
118  typename std::iterator_traits<Iterator>::reference
119  >::type;
120  using channel_t = typename element_type<ref_t>::type;
121  gil_function_requires<detail::ChannelIsMutableConcept<channel_t>>();
122  }
123 };
124 
125 } // namespace detail
126 
136 template <typename T>
138 {
139  void constraints()
140  {
141  using type = typename transposed_type<T>::type;
142  ignore_unused_variable_warning(type{});
143  }
144 };
145 
149 
169 template <typename Iterator>
171 {
172  void constraints()
173  {
174  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<Iterator>>();
175  gil_function_requires<PixelBasedConcept<Iterator>>();
176 
177  using value_type = typename std::iterator_traits<Iterator>::value_type;
178  gil_function_requires<PixelValueConcept<value_type>>();
179 
180  using const_t = typename const_iterator_type<Iterator>::type;
181  static bool const is_mutable = iterator_is_mutable<Iterator>::value;
182  ignore_unused_variable_warning(is_mutable);
183 
184  // immutable iterator must be constructible from (possibly mutable) iterator
185  const_t const_it(it);
186  ignore_unused_variable_warning(const_it);
187 
188  check_base(typename is_iterator_adaptor<Iterator>::type());
189  }
190 
191  void check_base(std::false_type) {}
192 
193  void check_base(std::true_type)
194  {
195  using base_t = typename iterator_adaptor_get_base<Iterator>::type;
196  gil_function_requires<PixelIteratorConcept<base_t>>();
197  }
198 
199  Iterator it;
200 };
201 
208 template <typename Iterator>
210 {
211  void constraints()
212  {
213  gil_function_requires<PixelIteratorConcept<Iterator>>();
214  gil_function_requires<detail::PixelIteratorIsMutableConcept<Iterator>>();
215  }
216 };
217 
221 
235 template <typename Iterator>
237 {
238  void constraints()
239  {
240  gil_function_requires<boost_concepts::RandomAccessTraversalConcept<Iterator>>();
241  gil_function_requires<detail::RandomAccessIteratorIsMemoryBasedConcept<Iterator>>();
242  }
243 };
244 
256 template <typename Iterator>
258 {
259  void constraints()
260  {
261  gil_function_requires<boost_concepts::ForwardTraversalConcept<Iterator>>();
262  it.set_step(0);
263  }
264  Iterator it;
265 };
266 
267 
274 template <typename Iterator>
276 {
277  void constraints()
278  {
279  gil_function_requires<StepIteratorConcept<Iterator>>();
280  gil_function_requires<detail::ForwardIteratorIsMutableConcept<Iterator>>();
281  }
282 };
283 
287 
316 template <typename Iterator>
318 {
319  void constraints()
320  {
321  gil_function_requires<boost_concepts::ForwardTraversalConcept<Iterator>>();
322 
323  using base_t = typename iterator_adaptor_get_base<Iterator>::type;
324  gil_function_requires<boost_concepts::ForwardTraversalConcept<base_t>>();
325 
326  static_assert(is_iterator_adaptor<Iterator>::value, "");
327  using rebind_t = typename iterator_adaptor_rebind<Iterator, void*>::type;
328 
329  base_t base = it.base();
330  ignore_unused_variable_warning(base);
331  }
332  Iterator it;
333 };
334 
341 template <typename Iterator>
343 {
344  void constraints()
345  {
346  gil_function_requires<IteratorAdaptorConcept<Iterator>>();
347  gil_function_requires<detail::ForwardIteratorIsMutableConcept<Iterator>>();
348  }
349 };
350 
351 }} // namespace boost::gil
352 
353 #if defined(BOOST_CLANG)
354 #pragma clang diagnostic pop
355 #endif
356 
357 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
358 #pragma GCC diagnostic pop
359 #endif
360 
361 #endif
metafunction predicate determining whether the given iterator is a plain one or an adaptor over anoth...
Definition: metafunctions.hpp:34
Pixel iterator that allows for changing its pixel.
Definition: concepts/pixel_iterator.hpp:209
Concept of a random-access iterator that can be advanced in memory units (bytes or bits)
Definition: concepts/pixel_iterator.hpp:236
returns the base iterator for a given iterator adaptor. Provide an specialization when introducing ne...
Definition: metafunctions.hpp:35
Iterator adaptor is a forward iterator adapting another forward iterator.
Definition: concepts/pixel_iterator.hpp:317
Step iterator that allows for modifying its current value.
Definition: concepts/pixel_iterator.hpp:275
Specifies the element type of a homogeneous color base.
Definition: color_base_algorithm.hpp:221
Concept for locators and views that can define a type just like the given locator or view,...
Definition: concepts/pixel_iterator.hpp:137
Changes the base iterator of an iterator adaptor. Provide an specialization when introducing new iter...
Definition: pixel_iterator.hpp:36
Iterator adaptor that is mutable.
Definition: concepts/pixel_iterator.hpp:342
Metafunction predicate returning whether the given iterator allows for changing its values.
Definition: pixel_iterator.hpp:49
Definition: concepts/pixel_iterator.hpp:110
An STL random access traversal iterator over a model of PixelConcept.
Definition: concepts/pixel_iterator.hpp:170
Returns the type of an iterator just like the input iterator, except operating over immutable values.
Definition: pixel_iterator.hpp:40
Step iterator concept.
Definition: concepts/pixel_iterator.hpp:257