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