Boost GIL


make_backend.hpp
1 //
2 //
3 // Copyright 2012 Christian Henning
4 //
5 // Distributed under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8 //
9 #ifndef BOOST_GIL_IO_MAKE_BACKEND_HPP
10 #define BOOST_GIL_IO_MAKE_BACKEND_HPP
11 
12 #include <boost/gil/detail/mp11.hpp>
13 #include <boost/gil/io/get_reader.hpp>
14 
15 #include <type_traits>
16 
17 namespace boost { namespace gil {
18 
19 template <typename String, typename FormatTag>
20 inline
21 auto make_reader_backend(
22  String const& file_name, image_read_settings<FormatTag> const& settings,
23  typename std::enable_if
24  <
25  mp11::mp_and
26  <
27  detail::is_supported_path_spec<String>,
28  is_format_tag<FormatTag>
29  >::value
30  >::type* /*dummy*/ = nullptr)
31  -> typename get_reader_backend<String, FormatTag>::type
32 {
33  using device_t = typename get_read_device<String, FormatTag>::type;
34 
35  device_t device(
36  detail::convert_to_native_string(file_name),
37  typename detail::file_stream_device<FormatTag>::read_tag());
38 
39  return reader_backend<device_t, FormatTag>(device, settings);
40 }
41 
42 template <typename FormatTag>
43 inline
44 auto make_reader_backend(
45  std::wstring const& file_name, image_read_settings<FormatTag> const& settings)
46  -> typename get_reader_backend<std::wstring, FormatTag>::type
47 {
48  char const* str = detail::convert_to_native_string(file_name);
49 
50  using device_t = typename get_read_device<std::wstring, FormatTag>::type;
51  device_t device(str, typename detail::file_stream_device<FormatTag>::read_tag());
52 
53  delete[] str; // TODO: RAII
54 
55  return reader_backend<device_t, FormatTag>(device, settings);
56 }
57 
58 template <typename FormatTag>
59 inline
60 auto make_reader_backend(
61  detail::filesystem::path const& path,
62  image_read_settings<FormatTag> const& settings)
63  -> typename get_reader_backend<std::wstring, FormatTag>::type
64 {
65  return make_reader_backend(path.wstring(), settings);
66 }
67 
68 template <typename Device, typename FormatTag>
69 inline
70 auto make_reader_backend(Device& io_dev, image_read_settings<FormatTag> const& settings,
71  typename std::enable_if
72  <
73  mp11::mp_and
74  <
75  detail::is_adaptable_input_device<FormatTag, Device>,
76  is_format_tag<FormatTag>
77  >::value
78  >::type* /*dummy*/ = nullptr)
79  -> typename get_reader_backend<Device, FormatTag>::type
80 {
81  using device_t = typename get_read_device<Device, FormatTag>::type;
82  device_t device(io_dev);
83 
84  return reader_backend<device_t, FormatTag>(device, settings);
85 }
86 
87 template <typename String, typename FormatTag>
88 inline
89 auto make_reader_backend(String const& file_name, FormatTag const&,
90  typename std::enable_if
91  <
92  mp11::mp_and
93  <
94  detail::is_supported_path_spec<String>,
95  is_format_tag<FormatTag>
96  >::value
97  >::type* /*dummy*/ = nullptr)
98  -> typename get_reader_backend<String, FormatTag>::type
99 {
100  return make_reader_backend(file_name, image_read_settings<FormatTag>());
101 }
102 
103 template <typename Device, typename FormatTag>
104 inline
105 auto make_reader_backend(Device& io_dev, FormatTag const&,
106  typename std::enable_if
107  <
108  mp11::mp_and
109  <
110  detail::is_adaptable_input_device<FormatTag, Device>,
111  is_format_tag<FormatTag>
112  >::value
113  >::type* /*dummy*/ = nullptr)
114  -> typename get_reader_backend<Device, FormatTag>::type
115 {
116  return make_reader_backend(io_dev, image_read_settings<FormatTag>());
117 }
118 
119 }} // namespace boost::gil
120 
121 #endif
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36