Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / io / 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 #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
59 template <typename FormatTag>
60 inline
61 auto make_reader_backend(
62     filesystem::path const& path,
63     image_read_settings<FormatTag> const& settings)
64     -> typename get_reader_backend<std::wstring, FormatTag>::type
65 {
66     return make_reader_backend(path.wstring(), settings);
67 }
68 #endif  // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
69
70 template <typename Device, typename FormatTag>
71 inline
72 auto make_reader_backend(Device& io_dev, image_read_settings<FormatTag> const& settings,
73     typename std::enable_if
74     <
75         mp11::mp_and
76         <
77             detail::is_adaptable_input_device<FormatTag, Device>,
78             is_format_tag<FormatTag>
79         >::value
80     >::type* /*dummy*/ = nullptr)
81     -> typename get_reader_backend<Device, FormatTag>::type
82 {
83     using device_t = typename get_read_device<Device, FormatTag>::type;
84     device_t device(io_dev);
85
86     return reader_backend<device_t, FormatTag>(device, settings);
87 }
88
89 template <typename String, typename FormatTag>
90 inline
91 auto make_reader_backend(String const& file_name, FormatTag const&,
92     typename std::enable_if
93     <
94         mp11::mp_and
95         <
96             detail::is_supported_path_spec<String>,
97             is_format_tag<FormatTag>
98         >::value
99     >::type* /*dummy*/ = nullptr)
100     -> typename get_reader_backend<String, FormatTag>::type
101 {
102     return make_reader_backend(file_name, image_read_settings<FormatTag>());
103 }
104
105 template <typename Device, typename FormatTag>
106 inline
107 auto make_reader_backend(Device& io_dev, FormatTag const&,
108     typename std::enable_if
109     <
110         mp11::mp_and
111         <
112             detail::is_adaptable_input_device<FormatTag, Device>,
113             is_format_tag<FormatTag>
114         >::value
115     >::type* /*dummy*/ = nullptr)
116     -> typename get_reader_backend<Device, FormatTag>::type
117 {
118     return make_reader_backend(io_dev, image_read_settings<FormatTag>());
119 }
120
121 }} // namespace boost::gil
122
123 #endif