Boost GIL


make_scanline_reader.hpp
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 
11 #include <boost/gil/io/get_reader.hpp>
12 
13 #include <boost/mpl/and.hpp>
14 
15 #include <type_traits>
16 
17 namespace boost { namespace gil {
18 
19 template <typename String, typename FormatTag>
20 inline
21 auto make_scanline_reader(String const& file_name, FormatTag const&,
22  typename std::enable_if
23  <
24  mpl::and_
25  <
26  detail::is_supported_path_spec<String>,
27  is_format_tag<FormatTag>
28  >::value
29  >::type* /*dummy*/ = nullptr)
30  -> typename get_scanline_reader<String, FormatTag>::type
31 {
32  using device_t = typename get_read_device<String, FormatTag>::type;
33  device_t device(
34  detail::convert_to_native_string(file_name),
35  typename detail::file_stream_device<FormatTag>::read_tag());
36 
37  return typename get_scanline_reader<String, FormatTag>::type(
38  device, image_read_settings<FormatTag>());
39 }
40 
41 template< typename FormatTag >
42 inline
43 typename get_scanline_reader< std::wstring
44  , FormatTag
45  >::type
46 make_scanline_reader( const std::wstring& file_name
47  , FormatTag const&
48  )
49 {
50  const char* str = detail::convert_to_native_string( file_name );
51 
52  typename get_read_device< std::wstring
53  , FormatTag
54  >::type device( str
55  , typename detail::file_stream_device< FormatTag >::read_tag()
56  );
57 
58  delete[] str;
59 
60  return typename get_scanline_reader< std::wstring
61  , FormatTag
62  >::type( device
63  , image_read_settings< FormatTag >()
64  );
65 }
66 
67 #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
68 template< typename FormatTag >
69 inline
70 typename get_scanline_reader< std::wstring
71  , FormatTag
72  >::type
73 make_scanline_reader( const filesystem::path& path
74  , FormatTag const&
75  )
76 {
77  return make_scanline_reader( path.wstring()
78  , image_read_settings< FormatTag >()
79  );
80 }
81 #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
82 
83 template <typename Device, typename FormatTag>
84 inline
85 auto make_scanline_reader(Device& io_dev, FormatTag const&,
86  typename std::enable_if
87  <
88  mpl::and_
89  <
90  detail::is_adaptable_input_device<FormatTag, Device>,
91  is_format_tag<FormatTag>
92  >::value
93  >::type* /*dummy*/ = nullptr)
94  -> typename get_scanline_reader<Device, FormatTag>::type
95 {
96  return make_scanline_reader(io_dev, image_read_settings<FormatTag>());
97 }
98 
99 }} // namespace boost::gil
100 
101 #endif
Definition: algorithm.hpp:30