path_spec.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. Copyright 2007-2008 Andreas Pokorny, 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_PATH_SPEC_HPP
  9. #define BOOST_GIL_IO_PATH_SPEC_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief
  13. /// \author Andreas Pokorny, Christian Henning \n
  14. ///
  15. /// \date 2007-2012 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <cstdlib>
  19. #include <string>
  20. #include <boost/mpl/bool_fwd.hpp>
  21. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  22. #define BOOST_FILESYSTEM_VERSION 3
  23. #include <boost/filesystem/path.hpp>
  24. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  25. namespace boost { namespace gil { namespace detail {
  26. template<typename P> struct is_supported_path_spec : mpl::false_ {};
  27. template<> struct is_supported_path_spec< std::string > : mpl::true_ {};
  28. template<> struct is_supported_path_spec< const std::string > : mpl::true_ {};
  29. template<> struct is_supported_path_spec< std::wstring > : mpl::true_ {};
  30. template<> struct is_supported_path_spec< const std::wstring > : mpl::true_ {};
  31. template<> struct is_supported_path_spec< const char* > : mpl::true_ {};
  32. template<> struct is_supported_path_spec< char* > : mpl::true_ {};
  33. template<> struct is_supported_path_spec< const wchar_t* > : mpl::true_ {};
  34. template<> struct is_supported_path_spec< wchar_t* > : mpl::true_ {};
  35. template<int i> struct is_supported_path_spec<const char [i]> : mpl::true_ {};
  36. template<int i> struct is_supported_path_spec<char [i]> : mpl::true_ {};
  37. template<int i> struct is_supported_path_spec<const wchar_t [i]> : mpl::true_ {};
  38. template<int i> struct is_supported_path_spec<wchar_t [i]> : mpl::true_ {};
  39. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  40. template<> struct is_supported_path_spec< filesystem::path > : mpl::true_ {};
  41. template<> struct is_supported_path_spec< const filesystem::path > : mpl::true_ {};
  42. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  43. ///
  44. /// convert_to_string
  45. ///
  46. inline std::string convert_to_string( std::string const& obj)
  47. {
  48. return obj;
  49. }
  50. inline std::string convert_to_string( std::wstring const& s )
  51. {
  52. std::size_t len = wcslen( s.c_str() );
  53. char* c = reinterpret_cast<char*>( alloca( len ));
  54. wcstombs( c, s.c_str(), len );
  55. return std::string( c, c + len );
  56. }
  57. inline std::string convert_to_string( const char* str )
  58. {
  59. return std::string( str );
  60. }
  61. inline std::string convert_to_string( char* str )
  62. {
  63. return std::string( str );
  64. }
  65. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  66. inline std::string convert_to_string( const filesystem::path& path )
  67. {
  68. return convert_to_string( path.string() );
  69. }
  70. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  71. ///
  72. /// convert_to_native_string
  73. ///
  74. inline const char* convert_to_native_string( char* str )
  75. {
  76. return str;
  77. }
  78. inline const char* convert_to_native_string( const char* str )
  79. {
  80. return str;
  81. }
  82. inline const char* convert_to_native_string( const std::string& str )
  83. {
  84. return str.c_str();
  85. }
  86. inline const char* convert_to_native_string( const wchar_t* str )
  87. {
  88. std::size_t len = wcslen( str ) + 1;
  89. char* c = new char[len];
  90. wcstombs( c, str, len );
  91. return c;
  92. }
  93. inline const char* convert_to_native_string( const std::wstring& str )
  94. {
  95. std::size_t len = wcslen( str.c_str() ) + 1;
  96. char* c = new char[len];
  97. wcstombs( c, str.c_str(), len );
  98. return c;
  99. }
  100. } // namespace detail
  101. } // namespace gil
  102. } // namespace boost
  103. #endif