Boost GIL


make_writer.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_WRITER_HPP
9 #define BOOST_GIL_IO_MAKE_WRITER_HPP
10 
11 #include <boost/gil/detail/mp11.hpp>
12 #include <boost/gil/io/get_writer.hpp>
13 
14 #include <type_traits>
15 
16 namespace boost { namespace gil {
17 
18 template <typename String, typename FormatTag>
19 inline
20 auto make_writer(String const& file_name, image_write_info<FormatTag> const& info,
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>::type* /*dummy*/ = nullptr)
28  -> typename get_writer<String, FormatTag>::type
29 {
30  typename get_write_device<String, FormatTag>::type device(
31  detail::convert_to_native_string(file_name),
32  typename detail::file_stream_device<FormatTag>::write_tag());
33 
34  return typename get_writer<String, FormatTag>::type(device, info);
35 }
36 
37 template <typename FormatTag>
38 inline
39 auto make_writer(std::wstring const& file_name, image_write_info<FormatTag> const& info)
40  -> typename get_writer<std::wstring, FormatTag>::type
41 {
42  const char* str = detail::convert_to_native_string( file_name );
43 
44  typename get_write_device< std::wstring
45  , FormatTag
46  >::type device( str
47  , typename detail::file_stream_device< FormatTag >::write_tag()
48  );
49 
50  delete[] str;
51 
52  return typename get_writer< std::wstring
53  , FormatTag
54  >::type( device
55  , info
56  );
57 }
58 
59 template <typename FormatTag>
60 inline
61 auto make_writer(detail::filesystem::path const& path, image_write_info<FormatTag> const& info)
62  -> typename get_writer<std::wstring, FormatTag>::type
63 {
64  return make_writer(path.wstring(), info);
65 }
66 
67 template <typename Device, typename FormatTag>
68 inline
69 auto make_writer(Device& file, image_write_info<FormatTag> const& info,
70  typename std::enable_if
71  <
72  mp11::mp_and
73  <
74  typename detail::is_adaptable_output_device<FormatTag, Device>::type,
75  is_format_tag<FormatTag>
76  >::value
77  >::type* /*dummy*/ = nullptr)
78  -> typename get_writer<Device, FormatTag>::type
79 {
80  typename get_write_device<Device, FormatTag>::type device(file);
81  return typename get_writer<Device, FormatTag>::type(device, info);
82 }
83 
84 // no image_write_info
85 
86 template <typename String, typename FormatTag>
87 inline
88 auto make_writer(String const& file_name, FormatTag const&,
89  typename std::enable_if
90  <
91  mp11::mp_and
92  <
93  detail::is_supported_path_spec<String>,
94  is_format_tag<FormatTag>
95  >::value
96  >::type* /*dummy*/ = nullptr)
97  -> typename get_writer<String, FormatTag>::type
98 {
99  return make_writer(file_name, image_write_info<FormatTag>());
100 }
101 
102 template <typename FormatTag>
103 inline
104 auto make_writer(std::wstring const &file_name, FormatTag const&)
105  -> typename get_writer<std::wstring, FormatTag>::type
106 {
107  return make_writer( file_name
108  , image_write_info< FormatTag >()
109  );
110 }
111 
112 template <typename FormatTag>
113 inline
114 auto make_writer(detail::filesystem::path const& path, FormatTag const& tag)
115  -> typename get_writer<std::wstring, FormatTag>::type
116 {
117  return make_writer(path.wstring(), tag);
118 }
119 
120 template <typename Device, typename FormatTag>
121 inline
122 auto make_writer(Device& file, FormatTag const&,
123  typename std::enable_if
124  <
125  mp11::mp_and
126  <
127  typename detail::is_adaptable_output_device<FormatTag, Device>::type,
128  is_format_tag<FormatTag>
129  >::value
130  >::type* /*dummy*/ = nullptr)
131  -> typename get_writer<Device, FormatTag>::type
132 {
133  return make_writer(file, image_write_info<FormatTag>());
134 }
135 
136 }} // namespace boost::gil
137 
138 #endif
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36