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
16namespace boost { namespace gil {
17
18template <typename String, typename FormatTag>
19inline
20auto 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
37template <typename FormatTag>
38inline
39auto 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
59template <typename FormatTag>
60inline
61auto 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
67template <typename Device, typename FormatTag>
68inline
69auto 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
86template <typename String, typename FormatTag>
87inline
88auto 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
102template <typename FormatTag>
103inline
104auto 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
112template <typename FormatTag>
113inline
114auto 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
120template <typename Device, typename FormatTag>
121inline
122auto 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