pixel_dereference.hpp 3.6 KB

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