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