Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:03

0001 //
0002 //
0003 // Copyright 2012 Christian Henning
0004 //
0005 // Distributed under the Boost Software License, Version 1.0
0006 // See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt
0008 //
0009 #ifndef BOOST_GIL_IO_MAKE_BACKEND_HPP
0010 #define BOOST_GIL_IO_MAKE_BACKEND_HPP
0011 
0012 #include <boost/gil/detail/mp11.hpp>
0013 #include <boost/gil/io/get_reader.hpp>
0014 
0015 #include <type_traits>
0016 
0017 namespace boost { namespace gil {
0018 
0019 template <typename String, typename FormatTag>
0020 inline
0021 auto make_reader_backend(
0022     String const& file_name, image_read_settings<FormatTag> const& settings,
0023     typename std::enable_if
0024     <
0025         mp11::mp_and
0026         <
0027             detail::is_supported_path_spec<String>,
0028             is_format_tag<FormatTag>
0029         >::value
0030     >::type* /*dummy*/ = nullptr)
0031     -> typename get_reader_backend<String, FormatTag>::type
0032 {
0033     using device_t = typename get_read_device<String, FormatTag>::type;
0034 
0035     device_t device(
0036         detail::convert_to_native_string(file_name),
0037         typename detail::file_stream_device<FormatTag>::read_tag());
0038 
0039     return reader_backend<device_t, FormatTag>(device, settings);
0040 }
0041 
0042 template <typename FormatTag>
0043 inline
0044 auto make_reader_backend(
0045     std::wstring const& file_name, image_read_settings<FormatTag> const& settings)
0046     -> typename get_reader_backend<std::wstring, FormatTag>::type
0047 {
0048     char const* str = detail::convert_to_native_string(file_name);
0049 
0050     using device_t = typename get_read_device<std::wstring, FormatTag>::type;
0051     device_t device(str, typename detail::file_stream_device<FormatTag>::read_tag());
0052 
0053     delete[] str;  // TODO: RAII
0054 
0055     return reader_backend<device_t, FormatTag>(device, settings);
0056 }
0057 
0058 template <typename FormatTag>
0059 inline
0060 auto make_reader_backend(
0061     detail::filesystem::path const& path,
0062     image_read_settings<FormatTag> const& settings)
0063     -> typename get_reader_backend<std::wstring, FormatTag>::type
0064 {
0065     return make_reader_backend(path.wstring(), settings);
0066 }
0067 
0068 template <typename Device, typename FormatTag>
0069 inline
0070 auto make_reader_backend(Device& io_dev, image_read_settings<FormatTag> const& settings,
0071     typename std::enable_if
0072     <
0073         mp11::mp_and
0074         <
0075             detail::is_adaptable_input_device<FormatTag, Device>,
0076             is_format_tag<FormatTag>
0077         >::value
0078     >::type* /*dummy*/ = nullptr)
0079     -> typename get_reader_backend<Device, FormatTag>::type
0080 {
0081     using device_t = typename get_read_device<Device, FormatTag>::type;
0082     device_t device(io_dev);
0083 
0084     return reader_backend<device_t, FormatTag>(device, settings);
0085 }
0086 
0087 template <typename String, typename FormatTag>
0088 inline
0089 auto make_reader_backend(String const& file_name, FormatTag const&,
0090     typename std::enable_if
0091     <
0092         mp11::mp_and
0093         <
0094             detail::is_supported_path_spec<String>,
0095             is_format_tag<FormatTag>
0096         >::value
0097     >::type* /*dummy*/ = nullptr)
0098     -> typename get_reader_backend<String, FormatTag>::type
0099 {
0100     return make_reader_backend(file_name, image_read_settings<FormatTag>());
0101 }
0102 
0103 template <typename Device, typename FormatTag>
0104 inline
0105 auto make_reader_backend(Device& io_dev, FormatTag const&,
0106     typename std::enable_if
0107     <
0108         mp11::mp_and
0109         <
0110             detail::is_adaptable_input_device<FormatTag, Device>,
0111             is_format_tag<FormatTag>
0112         >::value
0113     >::type* /*dummy*/ = nullptr)
0114     -> typename get_reader_backend<Device, FormatTag>::type
0115 {
0116     return make_reader_backend(io_dev, image_read_settings<FormatTag>());
0117 }
0118 
0119 }} // namespace boost::gil
0120 
0121 #endif