path_spec.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // Copyright 2007-2008 Andreas Pokorny, 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_PATH_SPEC_HPP
  9. #define BOOST_GIL_IO_PATH_SPEC_HPP
  10. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  11. // Disable warning: conversion to 'std::atomic<int>::__integral_type {aka int}' from 'long int' may alter its value
  12. #if defined(BOOST_CLANG)
  13. #pragma clang diagnostic push
  14. #pragma clang diagnostic ignored "-Wshorten-64-to-32"
  15. #endif
  16. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  17. #pragma GCC diagnostic push
  18. #pragma GCC diagnostic ignored "-Wconversion"
  19. #endif
  20. #define BOOST_FILESYSTEM_VERSION 3
  21. #include <boost/filesystem/path.hpp>
  22. #if defined(BOOST_CLANG)
  23. #pragma clang diagnostic pop
  24. #endif
  25. #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
  26. #pragma GCC diagnostic pop
  27. #endif
  28. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  29. #include <cstdlib>
  30. #include <string>
  31. #include <type_traits>
  32. namespace boost { namespace gil { namespace detail {
  33. template<typename P> struct is_supported_path_spec : std::false_type {};
  34. template<> struct is_supported_path_spec< std::string > : std::true_type {};
  35. template<> struct is_supported_path_spec< const std::string > : std::true_type {};
  36. template<> struct is_supported_path_spec< std::wstring > : std::true_type {};
  37. template<> struct is_supported_path_spec< const std::wstring > : std::true_type {};
  38. template<> struct is_supported_path_spec< const char* > : std::true_type {};
  39. template<> struct is_supported_path_spec< char* > : std::true_type {};
  40. template<> struct is_supported_path_spec< const wchar_t* > : std::true_type {};
  41. template<> struct is_supported_path_spec< wchar_t* > : std::true_type {};
  42. template<int i> struct is_supported_path_spec<const char [i]> : std::true_type {};
  43. template<int i> struct is_supported_path_spec<char [i]> : std::true_type {};
  44. template<int i> struct is_supported_path_spec<const wchar_t [i]> : std::true_type {};
  45. template<int i> struct is_supported_path_spec<wchar_t [i]> : std::true_type {};
  46. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  47. template<> struct is_supported_path_spec< filesystem::path > : std::true_type {};
  48. template<> struct is_supported_path_spec< const filesystem::path > : std::true_type {};
  49. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  50. ///
  51. /// convert_to_string
  52. ///
  53. inline std::string convert_to_string( std::string const& obj)
  54. {
  55. return obj;
  56. }
  57. inline std::string convert_to_string( std::wstring const& s )
  58. {
  59. std::size_t len = wcslen( s.c_str() );
  60. char* c = reinterpret_cast<char*>( alloca( len ));
  61. wcstombs( c, s.c_str(), len );
  62. return std::string( c, c + len );
  63. }
  64. inline std::string convert_to_string( const char* str )
  65. {
  66. return std::string( str );
  67. }
  68. inline std::string convert_to_string( char* str )
  69. {
  70. return std::string( str );
  71. }
  72. #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  73. inline std::string convert_to_string( const filesystem::path& path )
  74. {
  75. return convert_to_string( path.string() );
  76. }
  77. #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  78. ///
  79. /// convert_to_native_string
  80. ///
  81. inline const char* convert_to_native_string( char* str )
  82. {
  83. return str;
  84. }
  85. inline const char* convert_to_native_string( const char* str )
  86. {
  87. return str;
  88. }
  89. inline const char* convert_to_native_string( const std::string& str )
  90. {
  91. return str.c_str();
  92. }
  93. inline const char* convert_to_native_string( const wchar_t* str )
  94. {
  95. std::size_t len = wcslen( str ) + 1;
  96. char* c = new char[len];
  97. wcstombs( c, str, len );
  98. return c;
  99. }
  100. inline const char* convert_to_native_string( const std::wstring& str )
  101. {
  102. std::size_t len = wcslen( str.c_str() ) + 1;
  103. char* c = new char[len];
  104. wcstombs( c, str.c_str(), len );
  105. return c;
  106. }
  107. } // namespace detail
  108. } // namespace gil
  109. } // namespace boost
  110. #endif