make_reader.hpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_READER_HPP
  9. #define BOOST_GIL_IO_MAKE_READER_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_reader.hpp>
  20. namespace boost { namespace gil {
  21. template< typename String
  22. , typename FormatTag
  23. , typename ConversionPolicy
  24. >
  25. inline
  26. typename get_reader< String
  27. , FormatTag
  28. , ConversionPolicy
  29. >::type
  30. make_reader( const String& file_name
  31. , const image_read_settings< FormatTag >& settings
  32. , const ConversionPolicy&
  33. , typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
  34. , is_format_tag< FormatTag >
  35. >
  36. >::type* /* ptr */ = 0
  37. )
  38. {
  39. typename get_read_device< String
  40. , FormatTag
  41. >::type device( detail::convert_to_native_string( file_name )
  42. , typename detail::file_stream_device< FormatTag >::read_tag()
  43. );
  44. return typename get_reader< String
  45. , FormatTag
  46. , ConversionPolicy
  47. >::type( device
  48. , settings
  49. );
  50. }
  51. template< typename FormatTag
  52. , typename ConversionPolicy
  53. >
  54. inline
  55. typename get_reader< std::wstring
  56. , FormatTag
  57. , ConversionPolicy
  58. >::type
  59. make_reader( const std::wstring& file_name
  60. , const image_read_settings< FormatTag >& settings
  61. , const ConversionPolicy&
  62. )
  63. {
  64. const char* str = detail::convert_to_native_string( file_name );
  65. typename get_read_device< std::wstring
  66. , FormatTag
  67. >::type device( str
  68. , typename detail::file_stream_device< FormatTag >::read_tag()
  69. );
  70. delete[] str;
  71. return typename get_reader< std::wstring
  72. , FormatTag
  73. , ConversionPolicy
  74. >::type( device
  75. , settings
  76. );
  77. }
  78. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  79. template< typename FormatTag
  80. , typename ConversionPolicy
  81. >
  82. inline
  83. typename get_reader< std::wstring
  84. , FormatTag
  85. , ConversionPolicy
  86. >::type
  87. make_reader( const filesystem::path& path
  88. , const image_read_settings< FormatTag >& settings
  89. , const ConversionPolicy& cc
  90. )
  91. {
  92. return make_reader( path.wstring()
  93. , settings
  94. , cc
  95. );
  96. }
  97. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  98. template< typename Device
  99. , typename FormatTag
  100. , typename ConversionPolicy
  101. >
  102. inline
  103. typename get_reader< Device
  104. , FormatTag
  105. , ConversionPolicy
  106. >::type
  107. make_reader( Device& file
  108. , const image_read_settings< FormatTag >& settings
  109. , const ConversionPolicy&
  110. , typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
  111. , Device
  112. >
  113. , is_format_tag< FormatTag >
  114. >
  115. >::type* /* ptr */ = 0
  116. )
  117. {
  118. typename get_read_device< Device
  119. , FormatTag
  120. >::type device( file );
  121. return typename get_reader< Device
  122. , FormatTag
  123. , ConversionPolicy
  124. >::type( device
  125. , settings
  126. );
  127. }
  128. // no image_read_settings
  129. template< typename String
  130. , typename FormatTag
  131. , typename ConversionPolicy
  132. >
  133. inline
  134. typename get_reader< String
  135. , FormatTag
  136. , ConversionPolicy
  137. >::type
  138. make_reader( const String& file_name
  139. , const FormatTag&
  140. , const ConversionPolicy& cc
  141. , typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
  142. , is_format_tag< FormatTag >
  143. >
  144. >::type* /* ptr */ = 0
  145. )
  146. {
  147. return make_reader( file_name
  148. , image_read_settings< FormatTag >()
  149. , cc
  150. );
  151. }
  152. template< typename FormatTag
  153. , typename ConversionPolicy
  154. >
  155. inline
  156. typename get_reader< std::wstring
  157. , FormatTag
  158. , ConversionPolicy
  159. >::type
  160. make_reader( const std::wstring& file_name
  161. , const FormatTag&
  162. , const ConversionPolicy& cc
  163. )
  164. {
  165. return make_reader( file_name
  166. , image_read_settings< FormatTag >()
  167. , cc
  168. );
  169. }
  170. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  171. template< typename FormatTag
  172. , typename ConversionPolicy
  173. >
  174. inline
  175. typename get_reader< std::wstring
  176. , FormatTag
  177. , ConversionPolicy
  178. >::type
  179. make_reader( const filesystem::path& path
  180. , const FormatTag&
  181. , const ConversionPolicy& cc
  182. )
  183. {
  184. return make_reader( path.wstring()
  185. , image_read_settings< FormatTag >()
  186. , cc
  187. );
  188. }
  189. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  190. template< typename Device
  191. , typename FormatTag
  192. , typename ConversionPolicy
  193. >
  194. inline
  195. typename get_reader< Device
  196. , FormatTag
  197. , ConversionPolicy
  198. >::type
  199. make_reader( Device& file
  200. , const FormatTag&
  201. , const ConversionPolicy& cc
  202. , typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
  203. , Device
  204. >
  205. , is_format_tag< FormatTag >
  206. >
  207. >::type* /* ptr */ = 0
  208. )
  209. {
  210. return make_reader( file
  211. , image_read_settings< FormatTag >()
  212. , cc
  213. );
  214. }
  215. } // namespace gil
  216. } // namespace boost
  217. #endif