Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:55

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 #ifndef BOOST_GIL_CONCEPTS_PIXEL_ITERATOR_HPP
0009 #define BOOST_GIL_CONCEPTS_PIXEL_ITERATOR_HPP
0010 
0011 #include <boost/gil/concepts/channel.hpp>
0012 #include <boost/gil/concepts/color.hpp>
0013 #include <boost/gil/concepts/concept_check.hpp>
0014 #include <boost/gil/concepts/fwd.hpp>
0015 #include <boost/gil/concepts/pixel.hpp>
0016 #include <boost/gil/concepts/pixel_based.hpp>
0017 
0018 #include <boost/iterator/iterator_concepts.hpp>
0019 
0020 #include <cstddef>
0021 #include <iterator>
0022 #include <type_traits>
0023 
0024 #if defined(BOOST_CLANG)
0025 #pragma clang diagnostic push
0026 #pragma clang diagnostic ignored "-Wunknown-pragmas"
0027 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
0028 #endif
0029 
0030 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0031 #pragma GCC diagnostic push
0032 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
0033 #endif
0034 
0035 namespace boost { namespace gil {
0036 
0037 // Forward declarations
0038 template <typename It> struct const_iterator_type;
0039 template <typename It> struct iterator_is_mutable;
0040 template <typename It> struct is_iterator_adaptor;
0041 template <typename It, typename NewBaseIt> struct iterator_adaptor_rebind;
0042 template <typename It> struct iterator_adaptor_get_base;
0043 
0044 // These iterator mutability concepts are taken from Boost concept_check.hpp.
0045 // Isolating mutability to result in faster compile time
0046 namespace detail {
0047 
0048 // Preconditions: TT Models boost_concepts::ForwardTraversalConcept
0049 template <class TT>
0050 struct ForwardIteratorIsMutableConcept
0051 {
0052     void constraints()
0053     {
0054         auto const tmp = *i;
0055         *i++ = tmp; // require postincrement and assignment
0056     }
0057     TT i;
0058 };
0059 
0060 // Preconditions: TT Models boost::BidirectionalIteratorConcept
0061 template <class TT>
0062 struct BidirectionalIteratorIsMutableConcept
0063 {
0064     void constraints()
0065     {
0066         gil_function_requires< ForwardIteratorIsMutableConcept<TT>>();
0067         auto const tmp = *i;
0068         *i-- = tmp; // require postdecrement and assignment
0069     }
0070     TT i;
0071 };
0072 
0073 // Preconditions: TT Models boost_concepts::RandomAccessTraversalConcept
0074 template <class TT>
0075 struct RandomAccessIteratorIsMutableConcept
0076 {
0077     void constraints()
0078     {
0079         gil_function_requires<BidirectionalIteratorIsMutableConcept<TT>>();
0080 
0081         typename std::iterator_traits<TT>::difference_type n = 0;
0082         ignore_unused_variable_warning(n);
0083         i[n] = *i; // require element access and assignment
0084     }
0085     TT i;
0086 };
0087 
0088 // Iterators that can be used as the base of memory_based_step_iterator require some additional functions
0089 // \tparam Iterator Models boost_concepts::RandomAccessTraversalConcept
0090 template <typename Iterator>
0091 struct RandomAccessIteratorIsMemoryBasedConcept
0092 {
0093     void constraints()
0094     {
0095         std::ptrdiff_t bs = memunit_step(it);
0096         ignore_unused_variable_warning(bs);
0097 
0098         it = memunit_advanced(it, 3);
0099         std::ptrdiff_t bd = memunit_distance(it, it);
0100         ignore_unused_variable_warning(bd);
0101 
0102         memunit_advance(it,3);
0103         // for performace you may also provide a customized implementation of memunit_advanced_ref
0104     }
0105     Iterator it;
0106 };
0107 
0108 /// \tparam Iterator Models PixelIteratorConcept
0109 template <typename Iterator>
0110 struct PixelIteratorIsMutableConcept
0111 {
0112     void constraints()
0113     {
0114         gil_function_requires<detail::RandomAccessIteratorIsMutableConcept<Iterator>>();
0115 
0116         using ref_t = typename std::remove_reference
0117             <
0118                 typename std::iterator_traits<Iterator>::reference
0119             >::type;
0120         using channel_t = typename element_type<ref_t>::type;
0121         gil_function_requires<detail::ChannelIsMutableConcept<channel_t>>();
0122     }
0123 };
0124 
0125 } // namespace detail
0126 
0127 /// \ingroup PixelLocatorConcept
0128 /// \brief Concept for locators and views that can define a type just like the given locator or view, except X and Y is swapped
0129 /// \code
0130 /// concept HasTransposedTypeConcept<typename T>
0131 /// {
0132 ///     typename transposed_type<T>;
0133 ///         where Metafunction<transposed_type<T> >;
0134 /// };
0135 /// \endcode
0136 template <typename T>
0137 struct HasTransposedTypeConcept
0138 {
0139     void constraints()
0140     {
0141         using type = typename transposed_type<T>::type;
0142         ignore_unused_variable_warning(type{});
0143     }
0144 };
0145 
0146 /// \defgroup PixelIteratorConceptPixelIterator PixelIteratorConcept
0147 /// \ingroup PixelIteratorConcept
0148 /// \brief STL iterator over pixels
0149 
0150 /// \ingroup PixelIteratorConceptPixelIterator
0151 /// \brief An STL random access traversal iterator over a model of PixelConcept.
0152 ///
0153 /// GIL's iterators must also provide the following metafunctions:
0154 ///  - \p const_iterator_type<Iterator>:   Returns a read-only equivalent of \p Iterator
0155 ///  - \p iterator_is_mutable<Iterator>:   Returns whether the given iterator is read-only or mutable
0156 ///  - \p is_iterator_adaptor<Iterator>:   Returns whether the given iterator is an adaptor over another iterator. See IteratorAdaptorConcept for additional requirements of adaptors.
0157 ///
0158 /// \code
0159 /// concept PixelIteratorConcept<typename Iterator>
0160 ///     : boost_concepts::RandomAccessTraversalConcept<Iterator>, PixelBasedConcept<Iterator>
0161 /// {
0162 ///     where PixelValueConcept<value_type>;
0163 ///     typename const_iterator_type<It>::type;
0164 ///         where PixelIteratorConcept<const_iterator_type<It>::type>;
0165 ///     static const bool  iterator_is_mutable<It>::value;
0166 ///     static const bool  is_iterator_adaptor<It>::value;   // is it an iterator adaptor
0167 /// };
0168 /// \endcode
0169 template <typename Iterator>
0170 struct PixelIteratorConcept
0171 {
0172     void constraints()
0173     {
0174         gil_function_requires<boost_concepts::RandomAccessTraversalConcept<Iterator>>();
0175         gil_function_requires<PixelBasedConcept<Iterator>>();
0176 
0177         using value_type = typename std::iterator_traits<Iterator>::value_type;
0178         gil_function_requires<PixelValueConcept<value_type>>();
0179 
0180         using const_t = typename const_iterator_type<Iterator>::type;
0181         static bool const is_mutable = iterator_is_mutable<Iterator>::value;
0182         ignore_unused_variable_warning(is_mutable);
0183 
0184         // immutable iterator must be constructible from (possibly mutable) iterator
0185         const_t const_it(it);
0186         ignore_unused_variable_warning(const_it);
0187 
0188         check_base(typename is_iterator_adaptor<Iterator>::type());
0189     }
0190 
0191     void check_base(std::false_type) {}
0192 
0193     void check_base(std::true_type)
0194     {
0195         using base_t = typename iterator_adaptor_get_base<Iterator>::type;
0196         gil_function_requires<PixelIteratorConcept<base_t>>();
0197     }
0198 
0199     Iterator it;
0200 };
0201 
0202 /// \brief Pixel iterator that allows for changing its pixel
0203 /// \ingroup PixelIteratorConceptPixelIterator
0204 /// \code
0205 /// concept MutablePixelIteratorConcept<PixelIteratorConcept Iterator>
0206 ///     : MutableRandomAccessIteratorConcept<Iterator> {};
0207 /// \endcode
0208 template <typename Iterator>
0209 struct MutablePixelIteratorConcept
0210 {
0211     void constraints()
0212     {
0213         gil_function_requires<PixelIteratorConcept<Iterator>>();
0214         gil_function_requires<detail::PixelIteratorIsMutableConcept<Iterator>>();
0215     }
0216 };
0217 
0218 /// \defgroup PixelIteratorConceptStepIterator StepIteratorConcept
0219 /// \ingroup PixelIteratorConcept
0220 /// \brief Iterator that advances by a specified step
0221 
0222 /// \ingroup PixelIteratorConceptStepIterator
0223 /// \brief Concept of a random-access iterator that can be advanced in memory units (bytes or bits)
0224 /// \code
0225 /// concept MemoryBasedIteratorConcept<boost_concepts::RandomAccessTraversalConcept Iterator>
0226 /// {
0227 ///     typename byte_to_memunit<Iterator>; where metafunction<byte_to_memunit<Iterator> >;
0228 ///     std::ptrdiff_t      memunit_step(const Iterator&);
0229 ///     std::ptrdiff_t      memunit_distance(const Iterator& , const Iterator&);
0230 ///     void                memunit_advance(Iterator&, std::ptrdiff_t diff);
0231 ///     Iterator            memunit_advanced(const Iterator& p, std::ptrdiff_t diff) { Iterator tmp; memunit_advance(tmp,diff); return tmp; }
0232 ///     Iterator::reference memunit_advanced_ref(const Iterator& p, std::ptrdiff_t diff) { return *memunit_advanced(p,diff); }
0233 /// };
0234 /// \endcode
0235 template <typename Iterator>
0236 struct MemoryBasedIteratorConcept
0237 {
0238     void constraints()
0239     {
0240         gil_function_requires<boost_concepts::RandomAccessTraversalConcept<Iterator>>();
0241         gil_function_requires<detail::RandomAccessIteratorIsMemoryBasedConcept<Iterator>>();
0242     }
0243 };
0244 
0245 /// \ingroup PixelIteratorConceptStepIterator
0246 /// \brief Step iterator concept
0247 ///
0248 /// Step iterators are iterators that have a set_step method
0249 /// \code
0250 /// concept StepIteratorConcept<boost_concepts::ForwardTraversalConcept Iterator>
0251 /// {
0252 ///     template <Integral D>
0253 ///     void Iterator::set_step(D step);
0254 /// };
0255 /// \endcode
0256 template <typename Iterator>
0257 struct StepIteratorConcept
0258 {
0259     void constraints()
0260     {
0261         gil_function_requires<boost_concepts::ForwardTraversalConcept<Iterator>>();
0262         it.set_step(0);
0263     }
0264     Iterator it;
0265 };
0266 
0267 
0268 /// \ingroup PixelIteratorConceptStepIterator
0269 /// \brief Step iterator that allows for modifying its current value
0270 /// \code
0271 /// concept MutableStepIteratorConcept<Mutable_ForwardIteratorConcept Iterator>
0272 ///     : StepIteratorConcept<Iterator> {};
0273 /// \endcode
0274 template <typename Iterator>
0275 struct MutableStepIteratorConcept
0276 {
0277     void constraints()
0278     {
0279         gil_function_requires<StepIteratorConcept<Iterator>>();
0280         gil_function_requires<detail::ForwardIteratorIsMutableConcept<Iterator>>();
0281     }
0282 };
0283 
0284 /// \defgroup PixelIteratorConceptIteratorAdaptor IteratorAdaptorConcept
0285 /// \ingroup PixelIteratorConcept
0286 /// \brief Adaptor over another iterator
0287 
0288 /// \ingroup PixelIteratorConceptIteratorAdaptor
0289 /// \brief Iterator adaptor is a forward iterator adapting another forward iterator.
0290 ///
0291 /// In addition to GIL iterator requirements,
0292 /// GIL iterator adaptors must provide the following metafunctions:
0293 ///  - \p is_iterator_adaptor<Iterator>:             Returns \p std::true_type
0294 ///  - \p iterator_adaptor_get_base<Iterator>:       Returns the base iterator type
0295 ///  - \p iterator_adaptor_rebind<Iterator,NewBase>: Replaces the base iterator with the new one
0296 ///
0297 /// The adaptee can be obtained from the iterator via the "base()" method.
0298 ///
0299 /// \code
0300 /// concept IteratorAdaptorConcept<boost_concepts::ForwardTraversalConcept Iterator>
0301 /// {
0302 ///     where SameType<is_iterator_adaptor<Iterator>::type, std::true_type>;
0303 ///
0304 ///     typename iterator_adaptor_get_base<Iterator>;
0305 ///         where Metafunction<iterator_adaptor_get_base<Iterator> >;
0306 ///         where boost_concepts::ForwardTraversalConcept<iterator_adaptor_get_base<Iterator>::type>;
0307 ///
0308 ///     typename another_iterator;
0309 ///     typename iterator_adaptor_rebind<Iterator,another_iterator>::type;
0310 ///         where boost_concepts::ForwardTraversalConcept<another_iterator>;
0311 ///         where IteratorAdaptorConcept<iterator_adaptor_rebind<Iterator,another_iterator>::type>;
0312 ///
0313 ///     const iterator_adaptor_get_base<Iterator>::type& Iterator::base() const;
0314 /// };
0315 /// \endcode
0316 template <typename Iterator>
0317 struct IteratorAdaptorConcept
0318 {
0319     void constraints()
0320     {
0321         gil_function_requires<boost_concepts::ForwardTraversalConcept<Iterator>>();
0322 
0323         using base_t = typename iterator_adaptor_get_base<Iterator>::type;
0324         gil_function_requires<boost_concepts::ForwardTraversalConcept<base_t>>();
0325 
0326         static_assert(is_iterator_adaptor<Iterator>::value, "");
0327         using rebind_t = typename iterator_adaptor_rebind<Iterator, void*>::type;
0328 
0329         base_t base = it.base();
0330         ignore_unused_variable_warning(base);
0331     }
0332     Iterator it;
0333 };
0334 
0335 /// \brief Iterator adaptor that is mutable
0336 /// \ingroup PixelIteratorConceptIteratorAdaptor
0337 /// \code
0338 /// concept MutableIteratorAdaptorConcept<Mutable_ForwardIteratorConcept Iterator>
0339 ///     : IteratorAdaptorConcept<Iterator> {};
0340 /// \endcode
0341 template <typename Iterator>
0342 struct MutableIteratorAdaptorConcept
0343 {
0344     void constraints()
0345     {
0346         gil_function_requires<IteratorAdaptorConcept<Iterator>>();
0347         gil_function_requires<detail::ForwardIteratorIsMutableConcept<Iterator>>();
0348     }
0349 };
0350 
0351 }} // namespace boost::gil
0352 
0353 #if defined(BOOST_CLANG)
0354 #pragma clang diagnostic pop
0355 #endif
0356 
0357 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
0358 #pragma GCC diagnostic pop
0359 #endif
0360 
0361 #endif