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 #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 >= 40600)
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 >= 40600)
31 #pragma GCC diagnostic pop
32 #endif
33 #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
34 
35 #include <boost/mpl/bool.hpp> // for complete types of true_ and false_
36 
37 #include <cstdlib>
38 #include <string>
39 
40 namespace boost { namespace gil { namespace detail {
41 
42 template<typename P> struct is_supported_path_spec : mpl::false_ {};
43 template<> struct is_supported_path_spec< std::string > : mpl::true_ {};
44 template<> struct is_supported_path_spec< const std::string > : mpl::true_ {};
45 template<> struct is_supported_path_spec< std::wstring > : mpl::true_ {};
46 template<> struct is_supported_path_spec< const std::wstring > : mpl::true_ {};
47 template<> struct is_supported_path_spec< const char* > : mpl::true_ {};
48 template<> struct is_supported_path_spec< char* > : mpl::true_ {};
49 template<> struct is_supported_path_spec< const wchar_t* > : mpl::true_ {};
50 template<> struct is_supported_path_spec< wchar_t* > : mpl::true_ {};
51 
52 template<int i> struct is_supported_path_spec<const char [i]> : mpl::true_ {};
53 template<int i> struct is_supported_path_spec<char [i]> : mpl::true_ {};
54 template<int i> struct is_supported_path_spec<const wchar_t [i]> : mpl::true_ {};
55 template<int i> struct is_supported_path_spec<wchar_t [i]> : mpl::true_ {};
56 
57 #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
58 template<> struct is_supported_path_spec< filesystem::path > : mpl::true_ {};
59 template<> struct is_supported_path_spec< const filesystem::path > : mpl::true_ {};
60 #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
61 
62 
66 
67 inline std::string convert_to_string( std::string const& obj)
68 {
69  return obj;
70 }
71 
72 inline std::string convert_to_string( std::wstring const& s )
73 {
74  std::size_t len = wcslen( s.c_str() );
75  char* c = reinterpret_cast<char*>( alloca( len ));
76  wcstombs( c, s.c_str(), len );
77 
78  return std::string( c, c + len );
79 }
80 
81 inline std::string convert_to_string( const char* str )
82 {
83  return std::string( str );
84 }
85 
86 inline std::string convert_to_string( char* str )
87 {
88  return std::string( str );
89 }
90 
91 #ifdef BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
92 inline std::string convert_to_string( const filesystem::path& path )
93 {
94  return convert_to_string( path.string() );
95 }
96 #endif // BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
97 
101 
102 inline const char* convert_to_native_string( char* str )
103 {
104  return str;
105 }
106 
107 inline const char* convert_to_native_string( const char* str )
108 {
109  return str;
110 }
111 
112 inline const char* convert_to_native_string( const std::string& str )
113 {
114  return str.c_str();
115 }
116 
117 inline const char* convert_to_native_string( const wchar_t* str )
118 {
119  std::size_t len = wcslen( str ) + 1;
120  char* c = new char[len];
121  wcstombs( c, str, len );
122 
123  return c;
124 }
125 
126 inline const char* convert_to_native_string( const std::wstring& str )
127 {
128  std::size_t len = wcslen( str.c_str() ) + 1;
129  char* c = new char[len];
130  wcstombs( c, str.c_str(), len );
131 
132  return c;
133 }
134 
135 } // namespace detail
136 } // namespace gil
137 } // namespace boost
138 
139 #endif
Definition: algorithm.hpp:30
Definition: algorithm.hpp:127