get_writer.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_WRITER_HPP
  9. #define BOOST_GIL_IO_GET_WRITER_HPP
  10. #include <boost/gil/detail/mp11.hpp>
  11. #include <boost/gil/io/get_write_device.hpp>
  12. #include <type_traits>
  13. namespace boost { namespace gil {
  14. /// \brief Helper metafunction to generate writer type.
  15. template <typename T, typename FormatTag, class Enable = void>
  16. struct get_writer {};
  17. template <typename String, typename FormatTag>
  18. struct get_writer
  19. <
  20. String,
  21. FormatTag,
  22. typename std::enable_if
  23. <
  24. mp11::mp_and
  25. <
  26. detail::is_supported_path_spec<String>,
  27. is_format_tag<FormatTag>
  28. >::value
  29. >::type
  30. >
  31. {
  32. using device_t = typename get_write_device<String, FormatTag>::type;
  33. using type = writer<device_t, FormatTag>;
  34. };
  35. template <typename Device, typename FormatTag>
  36. struct get_writer
  37. <
  38. Device,
  39. FormatTag,
  40. typename std::enable_if
  41. <
  42. mp11::mp_and
  43. <
  44. detail::is_adaptable_output_device<FormatTag, Device>,
  45. is_format_tag<FormatTag>
  46. >::value
  47. >::type
  48. >
  49. {
  50. using device_t = typename get_write_device<Device, FormatTag>::type;
  51. using type = writer<device_t, FormatTag>;
  52. };
  53. /// \brief Helper metafunction to generate dynamic image writer type.
  54. template <typename T, typename FormatTag, class Enable = void>
  55. struct get_dynamic_image_writer {};
  56. template <typename String, typename FormatTag>
  57. struct get_dynamic_image_writer
  58. <
  59. String,
  60. FormatTag,
  61. typename std::enable_if
  62. <
  63. mp11::mp_and
  64. <
  65. detail::is_supported_path_spec<String>,
  66. is_format_tag<FormatTag>
  67. >::value
  68. >::type
  69. >
  70. {
  71. using device_t = typename get_write_device<String, FormatTag>::type;
  72. using type = dynamic_image_writer<device_t, FormatTag>;
  73. };
  74. template <typename Device, typename FormatTag>
  75. struct get_dynamic_image_writer
  76. <
  77. Device,
  78. FormatTag,
  79. typename std::enable_if
  80. <
  81. mp11::mp_and
  82. <
  83. detail::is_write_device<FormatTag, Device>,
  84. is_format_tag<FormatTag>
  85. >::value
  86. >::type
  87. >
  88. {
  89. using device_t = typename get_write_device<Device, FormatTag>::type;
  90. using type = dynamic_image_writer<device_t, FormatTag>;
  91. };
  92. }} // namespace boost::gil
  93. #endif