File indexing completed on 2025-01-18 09:38:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef BOOST_IOSTREAMS_DETAIL_PATH_HPP_INCLUDED
0021 #define BOOST_IOSTREAMS_DETAIL_PATH_HPP_INCLUDED
0022
0023 #include <cstring>
0024 #include <string>
0025 #include <boost/iostreams/detail/config/wide_streams.hpp>
0026 #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
0027 # include <cwchar>
0028 #endif
0029 #include <boost/static_assert.hpp>
0030 #include <boost/type.hpp>
0031 #include <boost/type_traits/is_same.hpp>
0032
0033 namespace boost { namespace iostreams { namespace detail {
0034
0035 #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
0036
0037 class path {
0038 template<typename T, typename V>
0039 struct sfinae
0040 {
0041 typedef V type;
0042 };
0043 public:
0044
0045
0046 path() : narrow_(), wide_(), is_wide_(false) { }
0047
0048
0049 path(const std::string& p) : narrow_(p), wide_(), is_wide_(false) { }
0050
0051
0052 path(const char* p) : narrow_(p), wide_(), is_wide_(false) { }
0053
0054
0055
0056 template<typename Path>
0057 explicit path(const Path& p, typename Path::external_string_type* = 0)
0058 {
0059 init(p.external_file_string());
0060 }
0061
0062
0063 template<typename Path>
0064 explicit path(const Path& p, typename Path::codecvt_type* = 0)
0065 {
0066 init(p.native());
0067 }
0068
0069
0070 path(const path& p)
0071 : narrow_(p.narrow_), wide_(p.wide_), is_wide_(p.is_wide_)
0072 { }
0073
0074
0075 path& operator=(const path& p)
0076 {
0077 narrow_ = p.narrow_;
0078 wide_ = p.wide_;
0079 is_wide_ = p.is_wide_;
0080 return *this;
0081 }
0082
0083
0084 path& operator=(const std::string& p)
0085 {
0086 narrow_ = p;
0087 wide_.clear();
0088 is_wide_ = false;
0089 return *this;
0090 }
0091
0092
0093 path& operator=(const char* p)
0094 {
0095 narrow_.assign(p);
0096 wide_.clear();
0097 is_wide_ = false;
0098 return *this;
0099 }
0100
0101 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1400)
0102
0103
0104
0105
0106
0107 template<typename Path>
0108 typename sfinae<typename Path::external_string_type, path&>::type
0109 operator=(const Path& p)
0110 {
0111 init(p.external_file_string());
0112 return *this;
0113 }
0114 #endif
0115
0116
0117 template<typename Path>
0118 typename sfinae<typename Path::codecvt_type, path&>::type
0119 operator=(const Path& p)
0120 {
0121 init(p.native());
0122 return *this;
0123 }
0124
0125 bool is_wide() const { return is_wide_; }
0126
0127
0128
0129 const char* c_str() const { return narrow_.c_str(); }
0130
0131
0132
0133 const wchar_t* c_wstr() const { return wide_.c_str(); }
0134 private:
0135
0136
0137
0138 path(const std::wstring&);
0139 path& operator=(const std::wstring&);
0140
0141 void init(std::string const& file_path)
0142 {
0143 narrow_ = file_path;
0144 wide_.clear();
0145 is_wide_ = false;
0146 }
0147
0148 void init(std::wstring const& file_path)
0149 {
0150 narrow_.clear();
0151 wide_ = file_path;
0152 is_wide_ = true;
0153 }
0154
0155 std::string narrow_;
0156 std::wstring wide_;
0157 bool is_wide_;
0158 };
0159
0160 inline bool operator==(const path& lhs, const path& rhs)
0161 {
0162 return lhs.is_wide() ?
0163 rhs.is_wide() && std::wcscmp(lhs.c_wstr(), rhs.c_wstr()) == 0 :
0164 !rhs.is_wide() && std::strcmp(lhs.c_str(), rhs.c_str()) == 0;
0165 }
0166
0167 #else
0168
0169 class path {
0170 public:
0171 path() { }
0172 path(const std::string& p) : path_(p) { }
0173 path(const char* p) : path_(p) { }
0174 template<typename Path>
0175 path(const Path& p) : path_(p.external_file_string()) { }
0176 path(const path& p) : path_(p.path_) { }
0177 path& operator=(const path& other)
0178 {
0179 path_ = other.path_;
0180 return *this;
0181 }
0182 path& operator=(const std::string& p)
0183 {
0184 path_ = p;
0185 return *this;
0186 }
0187 path& operator=(const char* p)
0188 {
0189 path_ = p;
0190 return *this;
0191 }
0192 template<typename Path>
0193 path& operator=(const Path& p)
0194 {
0195 path_ = p.external_file_string();
0196 return *this;
0197 }
0198 bool is_wide() const { return false; }
0199 const char* c_str() const { return path_.c_str(); }
0200 const wchar_t* c_wstr() const { return 0; }
0201 private:
0202 std::string path_;
0203 };
0204
0205 inline bool operator==(const path& lhs, const path& rhs)
0206 {
0207 return std::strcmp(lhs.c_str(), rhs.c_str()) == 0 ;
0208 }
0209
0210 #endif
0211
0212 } } }
0213
0214 #endif