Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:42:29

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