Boost GIL


make_scanline_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_SCANLINE_READER_HPP
9#define BOOST_GIL_IO_MAKE_SCANLINE_READER_HPP
10
11#include <boost/gil/detail/mp11.hpp>
12#include <boost/gil/io/get_reader.hpp>
13
14#include <type_traits>
15
16namespace boost { namespace gil {
17
18template <typename String, typename FormatTag>
19inline
20auto make_scanline_reader(String const& file_name, FormatTag const&,
21 typename std::enable_if
22 <
23 mp11::mp_and
24 <
25 detail::is_supported_path_spec<String>,
26 is_format_tag<FormatTag>
27 >::value
28 >::type* /*dummy*/ = nullptr)
29 -> typename get_scanline_reader<String, FormatTag>::type
30{
31 using device_t = typename get_read_device<String, FormatTag>::type;
32 device_t device(
33 detail::convert_to_native_string(file_name),
34 typename detail::file_stream_device<FormatTag>::read_tag());
35
36 return typename get_scanline_reader<String, FormatTag>::type(
37 device, image_read_settings<FormatTag>());
38}
39
40template <typename FormatTag>
41inline
42auto make_scanline_reader(std::wstring const& file_name, FormatTag const&)
43 -> typename get_scanline_reader<std::wstring, FormatTag>::type
44{
45 const char* str = detail::convert_to_native_string( file_name );
46
47 typename get_read_device< std::wstring
48 , FormatTag
49 >::type device( str
50 , typename detail::file_stream_device< FormatTag >::read_tag()
51 );
52
53 delete[] str;
54
55 return typename get_scanline_reader< std::wstring
56 , FormatTag
57 >::type( device
58 , image_read_settings< FormatTag >()
59 );
60}
61
62template <typename FormatTag>
63inline
64auto make_scanline_reader(detail::filesystem::path const& path, FormatTag const&)
65 -> typename get_scanline_reader<std::wstring, FormatTag>::type
66{
67 return make_scanline_reader(path.wstring(), image_read_settings<FormatTag>());
68}
69
70template <typename Device, typename FormatTag>
71inline
72auto make_scanline_reader(Device& io_dev, FormatTag const&,
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_scanline_reader<Device, FormatTag>::type
82{
83 return make_scanline_reader(io_dev, image_read_settings<FormatTag>());
84}
85
86}} // namespace boost::gil
87
88#endif
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36