Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / concepts / pixel_dereference.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_DEREFERENCE_HPP
9 #define BOOST_GIL_CONCEPTS_PIXEL_DEREFERENCE_HPP
10
11 #include <boost/gil/concepts/basic.hpp>
12 #include <boost/gil/concepts/concept_check.hpp>
13 #include <boost/gil/concepts/fwd.hpp>
14 #include <boost/gil/concepts/pixel.hpp>
15 #include <boost/gil/concepts/detail/type_traits.hpp>
16
17 #include <boost/concept_check.hpp>
18
19 #include <cstddef>
20 #include <type_traits>
21
22 #if defined(BOOST_CLANG)
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
25 #endif
26
27 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
30 #endif
31
32 namespace boost { namespace gil {
33
34 /// \ingroup PixelDereferenceAdaptorConcept
35 /// \brief Represents a unary function object that can be invoked upon dereferencing a pixel iterator.
36 ///
37 /// This can perform an arbitrary computation, such as color conversion or table lookup.
38 /// \code
39 /// concept PixelDereferenceAdaptorConcept<boost::UnaryFunctionConcept D>
40 ///     : DefaultConstructibleConcept<D>, CopyConstructibleConcept<D>, AssignableConcept<D>
41 /// {
42 ///     typename const_t; where PixelDereferenceAdaptorConcept<const_t>;
43 ///     typename value_type; where PixelValueConcept<value_type>;
44 ///     typename reference;         // may be mutable
45 ///     typename const_reference;   // must not be mutable
46 ///     static const bool D::is_mutable;
47 ///
48 ///     where Convertible<value_type,result_type>;
49 /// };
50 /// \endcode
51 template <typename D>
52 struct PixelDereferenceAdaptorConcept
53 {
54     void constraints()
55     {
56         gil_function_requires
57         <
58             boost::UnaryFunctionConcept
59             <
60                 D,
61                 typename detail::remove_const_and_reference<typename D::result_type>::type,
62                 typename D::argument_type
63             >
64         >();
65         gil_function_requires<boost::DefaultConstructibleConcept<D>>();
66         gil_function_requires<boost::CopyConstructibleConcept<D>>();
67         gil_function_requires<boost::AssignableConcept<D>>();
68
69         gil_function_requires<PixelConcept
70             <
71                 typename detail::remove_const_and_reference<typename D::result_type>::type
72             >>();
73
74         using const_t = typename D::const_t;
75         gil_function_requires<PixelDereferenceAdaptorConcept<const_t>>();
76
77         using value_type = typename D::value_type;
78         gil_function_requires<PixelValueConcept<value_type>>();
79
80         // TODO: Should this be concept-checked after "if you remove const and reference"? --mloskot
81         using reference = typename D::reference; // == PixelConcept (if you remove const and reference)
82         using const_reference = typename D::const_reference; // == PixelConcept (if you remove const and reference)
83
84         bool const is_mutable = D::is_mutable;
85         ignore_unused_variable_warning(is_mutable);
86     }
87     D d;
88 };
89
90 template <typename P>
91 struct PixelDereferenceAdaptorArchetype
92 {
93     using argument_type = P;
94     using result_type = P;
95     using const_t = PixelDereferenceAdaptorArchetype;
96     using value_type = typename std::remove_reference<P>::type;
97     using reference = typename std::add_lvalue_reference<P>::type;
98     using const_reference = reference;
99
100     static const bool is_mutable = false;
101     P operator()(P) const { throw; }
102 };
103
104 }} // namespace boost::gil
105
106 #if defined(BOOST_CLANG)
107 #pragma clang diagnostic pop
108 #endif
109
110 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
111 #pragma GCC diagnostic pop
112 #endif
113
114 #endif