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 #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT 12 #define BOOST_FILESYSTEM_VERSION 3 13 #include <boost/filesystem/path.hpp> 14 #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT 15 16 #include <boost/mpl/bool.hpp> // for complete types of true_ and false_ 17 18 #include <cstdlib> 19 #include <string> 20 21 namespace boost { namespace gil { namespace detail { 22 23 template<typename P> struct is_supported_path_spec : mpl::false_ {}; 24 template<> struct is_supported_path_spec< std::string > : mpl::true_ {}; 25 template<> struct is_supported_path_spec< const std::string > : mpl::true_ {}; 26 template<> struct is_supported_path_spec< std::wstring > : mpl::true_ {}; 27 template<> struct is_supported_path_spec< const std::wstring > : mpl::true_ {}; 28 template<> struct is_supported_path_spec< const char* > : mpl::true_ {}; 29 template<> struct is_supported_path_spec< char* > : mpl::true_ {}; 30 template<> struct is_supported_path_spec< const wchar_t* > : mpl::true_ {}; 31 template<> struct is_supported_path_spec< wchar_t* > : mpl::true_ {}; 32 33 template<int i> struct is_supported_path_spec<const char [i]> : mpl::true_ {}; 34 template<int i> struct is_supported_path_spec<char [i]> : mpl::true_ {}; 35 template<int i> struct is_supported_path_spec<const wchar_t [i]> : mpl::true_ {}; 36 template<int i> struct is_supported_path_spec<wchar_t [i]> : mpl::true_ {}; 37 38 #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT 39 template<> struct is_supported_path_spec< filesystem::path > : mpl::true_ {}; 40 template<> struct is_supported_path_spec< const filesystem::path > : mpl::true_ {}; 41 #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT 42 43 44 /// 45 /// convert_to_string 46 /// 47 convert_to_string(std::string const & obj)48inline std::string convert_to_string( std::string const& obj) 49 { 50 return obj; 51 } 52 convert_to_string(std::wstring const & s)53inline std::string convert_to_string( std::wstring const& s ) 54 { 55 std::size_t len = wcslen( s.c_str() ); 56 char* c = reinterpret_cast<char*>( alloca( len )); 57 wcstombs( c, s.c_str(), len ); 58 59 return std::string( c, c + len ); 60 } 61 convert_to_string(const char * str)62inline std::string convert_to_string( const char* str ) 63 { 64 return std::string( str ); 65 } 66 convert_to_string(char * str)67inline std::string convert_to_string( char* str ) 68 { 69 return std::string( str ); 70 } 71 72 #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT convert_to_string(const filesystem::path & path)73inline 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 /// 80 /// convert_to_native_string 81 /// 82 convert_to_native_string(char * str)83inline const char* convert_to_native_string( char* str ) 84 { 85 return str; 86 } 87 convert_to_native_string(const char * str)88inline const char* convert_to_native_string( const char* str ) 89 { 90 return str; 91 } 92 convert_to_native_string(const std::string & str)93inline const char* convert_to_native_string( const std::string& str ) 94 { 95 return str.c_str(); 96 } 97 convert_to_native_string(const wchar_t * str)98inline const char* convert_to_native_string( const wchar_t* str ) 99 { 100 std::size_t len = wcslen( str ) + 1; 101 char* c = new char[len]; 102 wcstombs( c, str, len ); 103 104 return c; 105 } 106 convert_to_native_string(const std::wstring & str)107inline const char* convert_to_native_string( const std::wstring& str ) 108 { 109 std::size_t len = wcslen( str.c_str() ) + 1; 110 char* c = new char[len]; 111 wcstombs( c, str.c_str(), len ); 112 113 return c; 114 } 115 116 } // namespace detail 117 } // namespace gil 118 } // namespace boost 119 120 #endif 121