9#ifndef BOOST_GIL_IO_PATH_SPEC_HPP
10#define BOOST_GIL_IO_PATH_SPEC_HPP
12#include <boost/gil/io/detail/filesystem.hpp>
21#ifndef WIN32_LEAN_AND_MEAN
22#define WIN32_LEAN_AND_MEAN
30namespace boost {
namespace gil {
namespace detail {
40inline std::string wide_to_utf8(
wchar_t const* str, std::size_t len)
46 int const size = ::WideCharToMultiByte(
47 CP_UTF8, 0, str,
static_cast<int>(len),
nullptr, 0,
nullptr,
nullptr);
48 std::string result(
static_cast<std::size_t
>(size),
'\0');
49 ::WideCharToMultiByte(
50 CP_UTF8, 0, str,
static_cast<int>(len), &result[0], size,
nullptr,
nullptr);
55template<
typename P>
struct is_supported_path_spec : std::false_type {};
56template<>
struct is_supported_path_spec< std::string > : std::true_type {};
57template<>
struct is_supported_path_spec< const std::string > : std::true_type {};
58template<>
struct is_supported_path_spec< std::wstring > : std::true_type {};
59template<>
struct is_supported_path_spec< const std::wstring > : std::true_type {};
60template<>
struct is_supported_path_spec< char const* > : std::true_type {};
61template<>
struct is_supported_path_spec< char* > : std::true_type {};
62template<>
struct is_supported_path_spec< const wchar_t* > : std::true_type {};
63template<>
struct is_supported_path_spec< wchar_t* > : std::true_type {};
65template<
int i>
struct is_supported_path_spec<const char [i]> : std::true_type {};
66template<
int i>
struct is_supported_path_spec<char [i]> : std::true_type {};
67template<
int i>
struct is_supported_path_spec<const wchar_t [i]> : std::true_type {};
68template<
int i>
struct is_supported_path_spec<wchar_t [i]> : std::true_type {};
70template<>
struct is_supported_path_spec<filesystem::path> : std::true_type {};
71template<>
struct is_supported_path_spec<filesystem::path const> : std::true_type {};
73inline std::string convert_to_string( std::string
const& obj)
78inline std::string convert_to_string( std::wstring
const& s )
81 return wide_to_utf8( s.c_str(), s.size() );
83 std::mbstate_t state = std::mbstate_t();
84 const wchar_t* str = s.c_str();
85 const std::size_t len = std::wcsrtombs(
nullptr, &str, 0, &state);
86 std::string result(len,
'\0');
87 std::wcstombs( &result[0], s.c_str(), len );
93inline std::string convert_to_string(
char const* str )
95 return std::string( str );
98inline std::string convert_to_string(
char* str )
100 return std::string( str );
103inline std::string convert_to_string(filesystem::path
const& path)
105 return convert_to_string(path.string());
108inline char const* convert_to_native_string(
char* str )
113inline char const* convert_to_native_string(
char const* str )
118inline char const* convert_to_native_string(
const std::string& str )
123inline char const* convert_to_native_string(
const wchar_t* str )
126 std::string
const utf8 = wide_to_utf8( str, std::wcslen( str ) );
127 char* c =
new char[utf8.size() + 1];
128 std::memcpy( c, utf8.c_str(), utf8.size() + 1 );
132 std::mbstate_t state = std::mbstate_t();
133 const std::size_t len = std::wcsrtombs(
nullptr, &str, 0, &state) + 1;
134 char* c =
new char[len];
135 std::wcstombs( c, str, len );
141inline char const* convert_to_native_string( std::wstring
const& str )
144 return convert_to_native_string( str.c_str() );
146 std::mbstate_t state = std::mbstate_t();
147 const wchar_t* wstr = str.c_str();
148 const std::size_t len = std::wcsrtombs(
nullptr, &wstr, 0, &state) + 1;
149 char* c =
new char[len];
150 std::wcstombs( c, str.c_str(), len );
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition algorithm.hpp:36