make_writer.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. Copyright 2012 Christian Henning
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. /*************************************************************************************************/
  8. #ifndef BOOST_GIL_IO_MAKE_WRITER_HPP
  9. #define BOOST_GIL_IO_MAKE_WRITER_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief
  13. /// \author Christian Henning \n
  14. ///
  15. /// \date 2012 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <boost/utility/enable_if.hpp>
  19. #include <boost/gil/io/get_writer.hpp>
  20. namespace boost { namespace gil {
  21. template< typename String
  22. , typename FormatTag
  23. >
  24. inline
  25. typename get_writer< String
  26. , FormatTag
  27. >::type
  28. make_writer( const String& file_name
  29. , const image_write_info< FormatTag >& info
  30. , typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
  31. , is_format_tag< FormatTag >
  32. >
  33. >::type* /* ptr */ = 0
  34. )
  35. {
  36. typename get_write_device< String
  37. , FormatTag
  38. >::type device( detail::convert_to_native_string( file_name )
  39. , typename detail::file_stream_device< FormatTag >::write_tag()
  40. );
  41. return typename get_writer< String
  42. , FormatTag
  43. >::type( device
  44. , info
  45. );
  46. }
  47. template< typename FormatTag >
  48. inline
  49. typename get_writer< std::wstring
  50. , FormatTag
  51. >::type
  52. make_writer( const std::wstring& file_name
  53. , const image_write_info< FormatTag >& info
  54. )
  55. {
  56. const char* str = detail::convert_to_native_string( file_name );
  57. typename get_write_device< std::wstring
  58. , FormatTag
  59. >::type device( str
  60. , typename detail::file_stream_device< FormatTag >::write_tag()
  61. );
  62. delete[] str;
  63. return typename get_writer< std::wstring
  64. , FormatTag
  65. >::type( device
  66. , info
  67. );
  68. }
  69. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  70. template< typename FormatTag >
  71. inline
  72. typename get_writer< std::wstring
  73. , FormatTag
  74. >::type
  75. make_writer( const filesystem::path& path
  76. , const image_write_info< FormatTag >& info
  77. )
  78. {
  79. return make_writer( path.wstring()
  80. , info
  81. );
  82. }
  83. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  84. template< typename Device
  85. , typename FormatTag
  86. >
  87. inline
  88. typename get_writer< Device
  89. , FormatTag
  90. >::type
  91. make_writer( Device& file
  92. , const image_write_info< FormatTag >& info
  93. , typename enable_if< mpl::and_< typename detail::is_adaptable_output_device< FormatTag, Device >::type
  94. , is_format_tag< FormatTag >
  95. >
  96. >::type* /* ptr */ = 0
  97. )
  98. {
  99. typename get_write_device< Device
  100. , FormatTag
  101. >::type device( file );
  102. return typename get_writer< Device
  103. , FormatTag
  104. >::type( device
  105. , info
  106. );
  107. }
  108. // no image_write_info
  109. template< typename String
  110. , typename FormatTag
  111. >
  112. inline
  113. typename get_writer< String
  114. , FormatTag
  115. >::type
  116. make_writer( const String& file_name
  117. , const FormatTag&
  118. , typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
  119. , is_format_tag< FormatTag >
  120. >
  121. >::type* /* ptr */ = 0
  122. )
  123. {
  124. return make_writer( file_name
  125. , image_write_info< FormatTag >()
  126. );
  127. }
  128. template< typename FormatTag >
  129. inline
  130. typename get_writer< std::wstring
  131. , FormatTag
  132. >::type
  133. make_writer( const std::wstring& file_name
  134. , const FormatTag&
  135. )
  136. {
  137. return make_writer( file_name
  138. , image_write_info< FormatTag >()
  139. );
  140. }
  141. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  142. template< typename FormatTag >
  143. inline
  144. typename get_writer< std::wstring
  145. , FormatTag
  146. >::type
  147. make_writer( const filesystem::path& path
  148. , const FormatTag& tag
  149. )
  150. {
  151. return make_writer( path.wstring()
  152. , tag
  153. );
  154. }
  155. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  156. template< typename Device
  157. , typename FormatTag
  158. >
  159. inline
  160. typename get_writer< Device
  161. , FormatTag
  162. >::type
  163. make_writer( Device& file
  164. , const FormatTag&
  165. , typename enable_if< mpl::and_< typename detail::is_adaptable_output_device< FormatTag, Device >::type
  166. , is_format_tag< FormatTag >
  167. >
  168. >::type* /* ptr */ = 0
  169. )
  170. {
  171. return make_writer( file
  172. , image_write_info< FormatTag >()
  173. );
  174. }
  175. } // namespace gil
  176. } // namespace boost
  177. #endif