Boost GIL


path_spec.hpp
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 
11 #include <boost/gil/io/detail/filesystem.hpp>
12 
13 #include <cstdlib>
14 #include <string>
15 #include <type_traits>
16 
17 namespace boost { namespace gil { namespace detail {
18 
19 template<typename P> struct is_supported_path_spec : std::false_type {};
20 template<> struct is_supported_path_spec< std::string > : std::true_type {};
21 template<> struct is_supported_path_spec< const std::string > : std::true_type {};
22 template<> struct is_supported_path_spec< std::wstring > : std::true_type {};
23 template<> struct is_supported_path_spec< const std::wstring > : std::true_type {};
24 template<> struct is_supported_path_spec< char const* > : std::true_type {};
25 template<> struct is_supported_path_spec< char* > : std::true_type {};
26 template<> struct is_supported_path_spec< const wchar_t* > : std::true_type {};
27 template<> struct is_supported_path_spec< wchar_t* > : std::true_type {};
28 
29 template<int i> struct is_supported_path_spec<const char [i]> : std::true_type {};
30 template<int i> struct is_supported_path_spec<char [i]> : std::true_type {};
31 template<int i> struct is_supported_path_spec<const wchar_t [i]> : std::true_type {};
32 template<int i> struct is_supported_path_spec<wchar_t [i]> : std::true_type {};
33 
34 template<> struct is_supported_path_spec<filesystem::path> : std::true_type {};
35 template<> struct is_supported_path_spec<filesystem::path const> : std::true_type {};
36 
37 inline std::string convert_to_string( std::string const& obj)
38 {
39  return obj;
40 }
41 
42 inline std::string convert_to_string( std::wstring const& s )
43 {
44  std::size_t len = wcslen( s.c_str() );
45  char* c = reinterpret_cast<char*>( alloca( len ));
46  wcstombs( c, s.c_str(), len );
47 
48  return std::string( c, c + len );
49 }
50 
51 inline std::string convert_to_string( char const* str )
52 {
53  return std::string( str );
54 }
55 
56 inline std::string convert_to_string( char* str )
57 {
58  return std::string( str );
59 }
60 
61 inline std::string convert_to_string(filesystem::path const& path)
62 {
63  return convert_to_string(path.string());
64 }
65 
66 inline char const* convert_to_native_string( char* str )
67 {
68  return str;
69 }
70 
71 inline char const* convert_to_native_string( char const* str )
72 {
73  return str;
74 }
75 
76 inline char const* convert_to_native_string( const std::string& str )
77 {
78  return str.c_str();
79 }
80 
81 inline char const* convert_to_native_string( const wchar_t* str )
82 {
83  std::size_t len = wcslen( str ) + 1;
84  char* c = new char[len];
85  wcstombs( c, str, len );
86 
87  return c;
88 }
89 
90 inline char const* convert_to_native_string( std::wstring const& str )
91 {
92  std::size_t len = wcslen( str.c_str() ) + 1;
93  char* c = new char[len];
94  wcstombs( c, str.c_str(), len );
95 
96  return c;
97 }
98 
99 }}} // namespace boost::gil::detail
100 
101 #endif
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36