pixel_dereference.hpp 3.7 KB

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