Boost GIL


make_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_READER_HPP
9 #define BOOST_GIL_IO_MAKE_READER_HPP
10 
11 #include <boost/gil/detail/mp11.hpp>
12 #include <boost/gil/io/get_reader.hpp>
13 
14 #include <type_traits>
15 
16 namespace boost { namespace gil {
17 
18 template <typename String, typename FormatTag, typename ConversionPolicy>
19 inline
20 auto make_reader(
21  String const&file_name,
22  image_read_settings<FormatTag> const& settings,
23  ConversionPolicy const&,
24  typename std::enable_if
25  <
26  mp11::mp_and
27  <
28  detail::is_supported_path_spec<String>,
29  is_format_tag<FormatTag>
30  >::value
31  >::type* /*dummy*/ = nullptr)
32  -> typename get_reader<String, FormatTag, ConversionPolicy>::type
33 {
34  typename get_read_device<String, FormatTag>::type device(
35  detail::convert_to_native_string(file_name),
36  typename detail::file_stream_device<FormatTag>::read_tag());
37 
38  return
39  typename get_reader<String, FormatTag, ConversionPolicy>::type(device, settings);
40 }
41 
42 template <typename FormatTag, typename ConversionPolicy>
43 inline
44 auto make_reader(std::wstring const &file_name, image_read_settings<FormatTag> const& settings, ConversionPolicy const&)
45  -> typename get_reader<std::wstring, FormatTag, ConversionPolicy>::type
46 {
47  const char* str = detail::convert_to_native_string( file_name );
48 
49  typename get_read_device< std::wstring
50  , FormatTag
51  >::type device( str
52  , typename detail::file_stream_device< FormatTag >::read_tag()
53  );
54 
55  delete[] str; // TODO: RAII
56 
57  return typename get_reader< std::wstring
58  , FormatTag
59  , ConversionPolicy
60  >::type( device
61  , settings
62  );
63 }
64 
65 template <typename FormatTag, typename ConversionPolicy>
66 inline
67 auto make_reader(detail::filesystem::path const& path, image_read_settings<FormatTag> const& settings, ConversionPolicy const& cc)
68  -> typename get_reader<std::wstring, FormatTag, ConversionPolicy>::type
69 {
70  return make_reader(path.wstring(), settings, cc);
71 }
72 
73 template <typename Device, typename FormatTag, typename ConversionPolicy>
74 inline
75 auto make_reader(
76  Device& file,
77  image_read_settings<FormatTag> const& settings,
78  ConversionPolicy const&,
79  typename std::enable_if
80  <
81  mp11::mp_and
82  <
83  detail::is_adaptable_input_device<FormatTag, Device>,
84  is_format_tag<FormatTag>
85  >::value
86  >::type* /*dummy*/ = nullptr)
87  -> typename get_reader<Device, FormatTag, ConversionPolicy>::type
88 {
89  typename get_read_device<Device, FormatTag>::type device(file);
90 
91  return
92  typename get_reader<Device, FormatTag, ConversionPolicy>::type(device, settings);
93 }
94 
95 // no image_read_settings
96 
97 template <typename String, typename FormatTag, typename ConversionPolicy>
98 inline
99 auto make_reader(
100  String const&file_name,
101  FormatTag const&,
102  ConversionPolicy const& cc,
103  typename std::enable_if
104  <
105  mp11::mp_and
106  <
107  detail::is_supported_path_spec<String>,
108  is_format_tag<FormatTag>
109  >::value
110  >::type* /*dummy*/ = nullptr)
111  -> typename get_reader<String, FormatTag, ConversionPolicy>::type
112 {
113  return make_reader(file_name, image_read_settings<FormatTag>(), cc);
114 }
115 
116 template <typename FormatTag, typename ConversionPolicy>
117 inline
118 auto make_reader(std::wstring const &file_name, FormatTag const&, ConversionPolicy const& cc)
119  -> typename get_reader<std::wstring, FormatTag, ConversionPolicy>::type
120 {
121  return make_reader( file_name
122  , image_read_settings< FormatTag >()
123  , cc
124  );
125 }
126 
127 template <typename FormatTag, typename ConversionPolicy>
128 inline
129 auto make_reader(detail::filesystem::path const& path, FormatTag const&, ConversionPolicy const& cc)
130  -> typename get_reader<std::wstring, FormatTag, ConversionPolicy>::type
131 {
132  return make_reader(path.wstring(), image_read_settings<FormatTag>(), cc);
133 }
134 
135 template <typename Device, typename FormatTag, typename ConversionPolicy>
136 inline
137 auto make_reader(
138  Device& file,
139  FormatTag const&,
140  ConversionPolicy const& cc,
141  typename std::enable_if
142  <
143  mp11::mp_and
144  <
145  detail::is_adaptable_input_device<FormatTag, Device>,
146  is_format_tag<FormatTag>
147  >::value
148  >::type* /*dummy*/ = nullptr)
149  -> typename get_reader<Device, FormatTag, ConversionPolicy>::type
150 {
151  return make_reader(file, image_read_settings<FormatTag>(), cc);
152 }
153 
154 }} // namespace boost::gil
155 
156 #endif
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36