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