make_scanline_reader.hpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_MAKE_SCANLINE_READER_HPP
  9. #define BOOST_GIL_IO_MAKE_SCANLINE_READER_HPP
  10. #include <boost/gil/detail/mp11.hpp>
  11. #include <boost/gil/io/get_reader.hpp>
  12. #include <type_traits>
  13. namespace boost { namespace gil {
  14. template <typename String, typename FormatTag>
  15. inline
  16. auto make_scanline_reader(String const& file_name, FormatTag const&,
  17. typename std::enable_if
  18. <
  19. mp11::mp_and
  20. <
  21. detail::is_supported_path_spec<String>,
  22. is_format_tag<FormatTag>
  23. >::value
  24. >::type* /*dummy*/ = nullptr)
  25. -> typename get_scanline_reader<String, FormatTag>::type
  26. {
  27. using device_t = typename get_read_device<String, FormatTag>::type;
  28. device_t device(
  29. detail::convert_to_native_string(file_name),
  30. typename detail::file_stream_device<FormatTag>::read_tag());
  31. return typename get_scanline_reader<String, FormatTag>::type(
  32. device, image_read_settings<FormatTag>());
  33. }
  34. template <typename FormatTag>
  35. inline
  36. auto make_scanline_reader(std::wstring const& file_name, FormatTag const&)
  37. -> typename get_scanline_reader<std::wstring, FormatTag>::type
  38. {
  39. const char* str = detail::convert_to_native_string( file_name );
  40. typename get_read_device< std::wstring
  41. , FormatTag
  42. >::type device( str
  43. , typename detail::file_stream_device< FormatTag >::read_tag()
  44. );
  45. delete[] str;
  46. return typename get_scanline_reader< std::wstring
  47. , FormatTag
  48. >::type( device
  49. , image_read_settings< FormatTag >()
  50. );
  51. }
  52. template <typename FormatTag>
  53. inline
  54. auto make_scanline_reader(detail::filesystem::path const& path, FormatTag const&)
  55. -> typename get_scanline_reader<std::wstring, FormatTag>::type
  56. {
  57. return make_scanline_reader(path.wstring(), image_read_settings<FormatTag>());
  58. }
  59. template <typename Device, typename FormatTag>
  60. inline
  61. auto make_scanline_reader(Device& io_dev, FormatTag const&,
  62. typename std::enable_if
  63. <
  64. mp11::mp_and
  65. <
  66. detail::is_adaptable_input_device<FormatTag, Device>,
  67. is_format_tag<FormatTag>
  68. >::value
  69. >::type* /*dummy*/ = nullptr)
  70. -> typename get_scanline_reader<Device, FormatTag>::type
  71. {
  72. return make_scanline_reader(io_dev, image_read_settings<FormatTag>());
  73. }
  74. }} // namespace boost::gil
  75. #endif