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