Generic Image Library: make_backend.hpp Source File

###  | #  |

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
17namespace boost { namespace gil {
18
19template <typename String, typename FormatTag>
20inline
21auto 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
42template <typename FormatTag>
43inline
44auto 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
58template <typename FormatTag>
59inline
60auto 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
68template <typename Device, typename FormatTag>
69inline
70auto 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
87template <typename String, typename FormatTag>
88inline
89auto 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
103template <typename Device, typename FormatTag>
104inline
105auto 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
boost
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36
boost::gil::detail::file_stream_device::read_tag
Used to overload the constructor.
Definition device.hpp:58
boost::gil::get_reader_backend
Helper metafunction to generate image backend type.
Definition get_reader.hpp:115