get_reader.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // Copyright 2012 Christian Henning
  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_IO_GET_READER_HPP
  9. #define BOOST_GIL_IO_GET_READER_HPP
  10. #include <boost/gil/io/get_read_device.hpp>
  11. #include <boost/gil/detail/mp11.hpp>
  12. #include <type_traits>
  13. namespace boost { namespace gil {
  14. /// \brief Helper metafunction to generate image reader type.
  15. template
  16. <
  17. typename T,
  18. typename FormatTag,
  19. typename ConversionPolicy,
  20. class Enable = void
  21. >
  22. struct get_reader {};
  23. template <typename String, typename FormatTag, typename ConversionPolicy>
  24. struct get_reader
  25. <
  26. String,
  27. FormatTag,
  28. ConversionPolicy,
  29. typename std::enable_if
  30. <
  31. mp11::mp_and
  32. <
  33. detail::is_supported_path_spec<String>,
  34. is_format_tag<FormatTag>
  35. >::value
  36. >::type
  37. >
  38. {
  39. using device_t = typename get_read_device<String, FormatTag>::type;
  40. using type = reader<device_t, FormatTag, ConversionPolicy>;
  41. };
  42. template <typename Device, typename FormatTag, typename ConversionPolicy>
  43. struct get_reader
  44. <
  45. Device,
  46. FormatTag,
  47. ConversionPolicy,
  48. typename std::enable_if
  49. <
  50. mp11::mp_and
  51. <
  52. detail::is_adaptable_input_device<FormatTag, Device>,
  53. is_format_tag<FormatTag>
  54. >::value
  55. >::type
  56. >
  57. {
  58. using device_t = typename get_read_device<Device, FormatTag>::type;
  59. using type = reader<device_t, FormatTag, ConversionPolicy>;
  60. };
  61. /// \brief Helper metafunction to generate dynamic image reader type.
  62. template <typename T, typename FormatTag, class Enable = void>
  63. struct get_dynamic_image_reader
  64. {
  65. };
  66. template <typename String, typename FormatTag>
  67. struct get_dynamic_image_reader
  68. <
  69. String,
  70. FormatTag,
  71. typename std::enable_if
  72. <
  73. mp11::mp_and
  74. <
  75. detail::is_supported_path_spec<String>,
  76. is_format_tag<FormatTag>
  77. >::value
  78. >::type
  79. >
  80. {
  81. using device_t = typename get_read_device<String, FormatTag>::type;
  82. using type = dynamic_image_reader<device_t, FormatTag>;
  83. };
  84. template <typename Device, typename FormatTag>
  85. struct get_dynamic_image_reader
  86. <
  87. Device,
  88. FormatTag,
  89. typename std::enable_if
  90. <
  91. mp11::mp_and
  92. <
  93. detail::is_adaptable_input_device<FormatTag, Device>,
  94. is_format_tag<FormatTag>
  95. >::value
  96. >::type
  97. >
  98. {
  99. using device_t = typename get_read_device<Device, FormatTag>::type;
  100. using type = dynamic_image_reader<device_t, FormatTag>;
  101. };
  102. /// \brief Helper metafunction to generate image backend type.
  103. template <typename T, typename FormatTag, class Enable = void>
  104. struct get_reader_backend
  105. {
  106. };
  107. template <typename String, typename FormatTag>
  108. struct get_reader_backend
  109. <
  110. String,
  111. FormatTag,
  112. typename std::enable_if
  113. <
  114. mp11::mp_and
  115. <
  116. detail::is_supported_path_spec<String>,
  117. is_format_tag<FormatTag>
  118. >::value
  119. >::type
  120. >
  121. {
  122. using device_t = typename get_read_device<String, FormatTag>::type;
  123. using type = reader_backend<device_t, FormatTag>;
  124. };
  125. template <typename Device, typename FormatTag>
  126. struct get_reader_backend
  127. <
  128. Device,
  129. FormatTag,
  130. typename std::enable_if
  131. <
  132. mp11::mp_and
  133. <
  134. detail::is_adaptable_input_device<FormatTag, Device>,
  135. is_format_tag<FormatTag>
  136. >::value
  137. >::type
  138. >
  139. {
  140. using device_t = typename get_read_device<Device, FormatTag>::type;
  141. using type = reader_backend<device_t, FormatTag>;
  142. };
  143. /// \brief Helper metafunction to generate image scanline_reader type.
  144. template <typename T, typename FormatTag>
  145. struct get_scanline_reader
  146. {
  147. using device_t = typename get_read_device<T, FormatTag>::type;
  148. using type = scanline_reader<device_t, FormatTag>;
  149. };
  150. } // namespace gil
  151. } // namespace boost
  152. #endif