make_backend.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_BACKEND_HPP
  9. #define BOOST_GIL_IO_MAKE_BACKEND_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 "get_reader.hpp"
  20. namespace boost { namespace gil {
  21. template< typename String
  22. , typename FormatTag
  23. >
  24. inline
  25. typename get_reader_backend< String
  26. , FormatTag
  27. >::type
  28. make_reader_backend( const String& file_name
  29. , const image_read_settings< FormatTag >& settings
  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. typedef typename get_read_device< String
  37. , FormatTag
  38. >::type device_t;
  39. device_t device( detail::convert_to_native_string( file_name )
  40. , typename detail::file_stream_device< FormatTag >::read_tag()
  41. );
  42. return reader_backend< device_t, FormatTag >( device, settings );
  43. }
  44. template< typename FormatTag >
  45. inline
  46. typename get_reader_backend< std::wstring
  47. , FormatTag
  48. >::type
  49. make_reader_backend( const std::wstring& file_name
  50. , const image_read_settings< FormatTag >& settings
  51. )
  52. {
  53. typedef typename get_read_device< std::wstring
  54. , FormatTag
  55. >::type device_t;
  56. const char* str = detail::convert_to_native_string( file_name );
  57. device_t device( str
  58. , typename detail::file_stream_device< FormatTag >::read_tag()
  59. );
  60. delete[] str;
  61. return reader_backend< device_t, FormatTag >( device, settings );
  62. }
  63. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  64. template< typename FormatTag >
  65. inline
  66. typename get_reader_backend< std::wstring
  67. , FormatTag
  68. >::type
  69. make_reader_backend( const filesystem::path& path
  70. , const image_read_settings< FormatTag >& settings
  71. )
  72. {
  73. return make_reader_backend( path.wstring()
  74. , settings
  75. );
  76. }
  77. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  78. template< typename Device
  79. , typename FormatTag
  80. >
  81. inline
  82. typename get_reader_backend< Device
  83. , FormatTag
  84. >::type
  85. make_reader_backend( Device& io_dev
  86. , const image_read_settings< FormatTag >& settings
  87. , typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
  88. , Device
  89. >
  90. , is_format_tag< FormatTag >
  91. >
  92. >::type* /* ptr */ = 0
  93. )
  94. {
  95. typedef typename get_read_device< Device
  96. , FormatTag
  97. >::type device_t;
  98. device_t device( io_dev );
  99. return reader_backend< device_t, FormatTag >( device, settings );
  100. }
  101. template< typename String
  102. , typename FormatTag
  103. >
  104. inline
  105. typename get_reader_backend< String
  106. , FormatTag
  107. >::type
  108. make_reader_backend( const String& file_name
  109. , const FormatTag&
  110. , typename enable_if< mpl::and_< detail::is_supported_path_spec< String >
  111. , is_format_tag< FormatTag >
  112. >
  113. >::type* /* ptr */ = 0
  114. )
  115. {
  116. return make_reader_backend( file_name, image_read_settings< FormatTag >() );
  117. }
  118. template< typename Device
  119. , typename FormatTag
  120. >
  121. inline
  122. typename get_reader_backend< Device
  123. , FormatTag
  124. >::type
  125. make_reader_backend( Device& io_dev
  126. , const FormatTag&
  127. , typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
  128. , Device
  129. >
  130. , is_format_tag< FormatTag >
  131. >
  132. >::type* /* ptr */ = 0
  133. )
  134. {
  135. return make_reader_backend( io_dev, image_read_settings< FormatTag >() );
  136. }
  137. } // namespace gil
  138. } // namespace boost
  139. #endif