Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- filesystem -------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | #ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM |
| 11 | #define _LIBCPP_EXPERIMENTAL_FILESYSTEM |
| 12 | /* |
| 13 | filesystem synopsis |
| 14 | |
| 15 | namespace std { namespace experimental { namespace filesystem { inline namespace v1 { |
| 16 | |
| 17 | class path; |
| 18 | |
| 19 | void swap(path& lhs, path& rhs) _NOEXCEPT; |
| 20 | size_t hash_value(const path& p) _NOEXCEPT; |
| 21 | |
| 22 | bool operator==(const path& lhs, const path& rhs) _NOEXCEPT; |
| 23 | bool operator!=(const path& lhs, const path& rhs) _NOEXCEPT; |
| 24 | bool operator< (const path& lhs, const path& rhs) _NOEXCEPT; |
| 25 | bool operator<=(const path& lhs, const path& rhs) _NOEXCEPT; |
| 26 | bool operator> (const path& lhs, const path& rhs) _NOEXCEPT; |
| 27 | bool operator>=(const path& lhs, const path& rhs) _NOEXCEPT; |
| 28 | |
| 29 | path operator/ (const path& lhs, const path& rhs); |
| 30 | |
| 31 | template <class charT, class traits> |
| 32 | basic_ostream<charT, traits>& |
| 33 | operator<<(basic_ostream<charT, traits>& os, const path& p); |
| 34 | |
| 35 | template <class charT, class traits> |
| 36 | basic_istream<charT, traits>& |
| 37 | operator>>(basic_istream<charT, traits>& is, path& p); |
| 38 | |
| 39 | template <class Source> |
| 40 | path u8path(const Source& source); |
| 41 | template <class InputIterator> |
| 42 | path u8path(InputIterator first, InputIterator last); |
| 43 | |
| 44 | class filesystem_error; |
| 45 | class directory_entry; |
| 46 | |
| 47 | class directory_iterator; |
| 48 | |
| 49 | // enable directory_iterator range-based for statements |
| 50 | directory_iterator begin(directory_iterator iter) noexcept; |
| 51 | directory_iterator end(const directory_iterator&) noexcept; |
| 52 | |
| 53 | class recursive_directory_iterator; |
| 54 | |
| 55 | // enable recursive_directory_iterator range-based for statements |
| 56 | recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept; |
| 57 | recursive_directory_iterator end(const recursive_directory_iterator&) noexcept; |
| 58 | |
| 59 | class file_status; |
| 60 | |
| 61 | struct space_info |
| 62 | { |
| 63 | uintmax_t capacity; |
| 64 | uintmax_t free; |
| 65 | uintmax_t available; |
| 66 | }; |
| 67 | |
| 68 | enum class file_type; |
| 69 | enum class perms; |
| 70 | enum class copy_options; |
| 71 | enum class directory_options; |
| 72 | |
| 73 | typedef chrono::time_point<trivial-clock> file_time_type; |
| 74 | |
| 75 | // operational functions |
| 76 | |
| 77 | path absolute(const path& p, const path& base=current_path()); |
| 78 | |
| 79 | path canonical(const path& p, const path& base = current_path()); |
| 80 | path canonical(const path& p, error_code& ec); |
| 81 | path canonical(const path& p, const path& base, error_code& ec); |
| 82 | |
| 83 | void copy(const path& from, const path& to); |
| 84 | void copy(const path& from, const path& to, error_code& ec) _NOEXCEPT; |
| 85 | void copy(const path& from, const path& to, copy_options options); |
| 86 | void copy(const path& from, const path& to, copy_options options, |
| 87 | error_code& ec) _NOEXCEPT; |
| 88 | |
| 89 | bool copy_file(const path& from, const path& to); |
| 90 | bool copy_file(const path& from, const path& to, error_code& ec) _NOEXCEPT; |
| 91 | bool copy_file(const path& from, const path& to, copy_options option); |
| 92 | bool copy_file(const path& from, const path& to, copy_options option, |
| 93 | error_code& ec) _NOEXCEPT; |
| 94 | |
| 95 | void copy_symlink(const path& existing_symlink, const path& new_symlink); |
| 96 | void copy_symlink(const path& existing_symlink, const path& new_symlink, |
| 97 | error_code& ec) _NOEXCEPT; |
| 98 | |
| 99 | bool create_directories(const path& p); |
| 100 | bool create_directories(const path& p, error_code& ec) _NOEXCEPT; |
| 101 | |
| 102 | bool create_directory(const path& p); |
| 103 | bool create_directory(const path& p, error_code& ec) _NOEXCEPT; |
| 104 | |
| 105 | bool create_directory(const path& p, const path& attributes); |
| 106 | bool create_directory(const path& p, const path& attributes, |
| 107 | error_code& ec) _NOEXCEPT; |
| 108 | |
| 109 | void create_directory_symlink(const path& to, const path& new_symlink); |
| 110 | void create_directory_symlink(const path& to, const path& new_symlink, |
| 111 | error_code& ec) _NOEXCEPT; |
| 112 | |
| 113 | void create_hard_link(const path& to, const path& new_hard_link); |
| 114 | void create_hard_link(const path& to, const path& new_hard_link, |
| 115 | error_code& ec) _NOEXCEPT; |
| 116 | |
| 117 | void create_symlink(const path& to, const path& new_symlink); |
| 118 | void create_symlink(const path& to, const path& new_symlink, |
| 119 | error_code& ec) _NOEXCEPT; |
| 120 | |
| 121 | path current_path(); |
| 122 | path current_path(error_code& ec); |
| 123 | void current_path(const path& p); |
| 124 | void current_path(const path& p, error_code& ec) _NOEXCEPT; |
| 125 | |
| 126 | bool exists(file_status s) _NOEXCEPT; |
| 127 | bool exists(const path& p); |
| 128 | bool exists(const path& p, error_code& ec) _NOEXCEPT; |
| 129 | |
| 130 | bool equivalent(const path& p1, const path& p2); |
| 131 | bool equivalent(const path& p1, const path& p2, error_code& ec) _NOEXCEPT; |
| 132 | |
| 133 | uintmax_t file_size(const path& p); |
| 134 | uintmax_t file_size(const path& p, error_code& ec) _NOEXCEPT; |
| 135 | |
| 136 | uintmax_t hard_link_count(const path& p); |
| 137 | uintmax_t hard_link_count(const path& p, error_code& ec) _NOEXCEPT; |
| 138 | |
| 139 | bool is_block_file(file_status s) _NOEXCEPT; |
| 140 | bool is_block_file(const path& p); |
| 141 | bool is_block_file(const path& p, error_code& ec) _NOEXCEPT; |
| 142 | |
| 143 | bool is_character_file(file_status s) _NOEXCEPT; |
| 144 | bool is_character_file(const path& p); |
| 145 | bool is_character_file(const path& p, error_code& ec) _NOEXCEPT; |
| 146 | |
| 147 | bool is_directory(file_status s) _NOEXCEPT; |
| 148 | bool is_directory(const path& p); |
| 149 | bool is_directory(const path& p, error_code& ec) _NOEXCEPT; |
| 150 | |
| 151 | bool is_empty(const path& p); |
| 152 | bool is_empty(const path& p, error_code& ec) _NOEXCEPT; |
| 153 | |
| 154 | bool is_fifo(file_status s) _NOEXCEPT; |
| 155 | bool is_fifo(const path& p); |
| 156 | bool is_fifo(const path& p, error_code& ec) _NOEXCEPT; |
| 157 | |
| 158 | bool is_other(file_status s) _NOEXCEPT; |
| 159 | bool is_other(const path& p); |
| 160 | bool is_other(const path& p, error_code& ec) _NOEXCEPT; |
| 161 | |
| 162 | bool is_regular_file(file_status s) _NOEXCEPT; |
| 163 | bool is_regular_file(const path& p); |
| 164 | bool is_regular_file(const path& p, error_code& ec) _NOEXCEPT; |
| 165 | |
| 166 | bool is_socket(file_status s) _NOEXCEPT; |
| 167 | bool is_socket(const path& p); |
| 168 | bool is_socket(const path& p, error_code& ec) _NOEXCEPT; |
| 169 | |
| 170 | bool is_symlink(file_status s) _NOEXCEPT; |
| 171 | bool is_symlink(const path& p); |
| 172 | bool is_symlink(const path& p, error_code& ec) _NOEXCEPT; |
| 173 | |
| 174 | file_time_type last_write_time(const path& p); |
| 175 | file_time_type last_write_time(const path& p, error_code& ec) _NOEXCEPT; |
| 176 | void last_write_time(const path& p, file_time_type new_time); |
| 177 | void last_write_time(const path& p, file_time_type new_time, |
| 178 | error_code& ec) _NOEXCEPT; |
| 179 | |
| 180 | void permissions(const path& p, perms prms); |
| 181 | void permissions(const path& p, perms prms, error_code& ec) _NOEXCEPT; |
| 182 | |
| 183 | path read_symlink(const path& p); |
| 184 | path read_symlink(const path& p, error_code& ec); |
| 185 | |
| 186 | bool remove(const path& p); |
| 187 | bool remove(const path& p, error_code& ec) _NOEXCEPT; |
| 188 | |
| 189 | uintmax_t remove_all(const path& p); |
| 190 | uintmax_t remove_all(const path& p, error_code& ec) _NOEXCEPT; |
| 191 | |
| 192 | void rename(const path& from, const path& to); |
| 193 | void rename(const path& from, const path& to, error_code& ec) _NOEXCEPT; |
| 194 | |
| 195 | void resize_file(const path& p, uintmax_t size); |
| 196 | void resize_file(const path& p, uintmax_t size, error_code& ec) _NOEXCEPT; |
| 197 | |
| 198 | space_info space(const path& p); |
| 199 | space_info space(const path& p, error_code& ec) _NOEXCEPT; |
| 200 | |
| 201 | file_status status(const path& p); |
| 202 | file_status status(const path& p, error_code& ec) _NOEXCEPT; |
| 203 | |
| 204 | bool status_known(file_status s) _NOEXCEPT; |
| 205 | |
| 206 | file_status symlink_status(const path& p); |
| 207 | file_status symlink_status(const path& p, error_code& ec) _NOEXCEPT; |
| 208 | |
| 209 | path system_complete(const path& p); |
| 210 | path system_complete(const path& p, error_code& ec); |
| 211 | |
| 212 | path temp_directory_path(); |
| 213 | path temp_directory_path(error_code& ec); |
| 214 | |
| 215 | } } } } // namespaces std::experimental::filesystem::v1 |
| 216 | |
| 217 | */ |
| 218 | |
| 219 | #include <experimental/__config> |
| 220 | #include <cstddef> |
| 221 | #include <chrono> |
| 222 | #include <iterator> |
| 223 | #include <iosfwd> |
| 224 | #include <locale> |
| 225 | #include <memory> |
| 226 | #include <stack> |
| 227 | #include <string> |
| 228 | #include <system_error> |
| 229 | #include <utility> |
| 230 | #include <iomanip> // for quoted |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 231 | #include <string_view> |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 232 | |
| 233 | #include <__debug> |
| 234 | |
| 235 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 236 | #pragma GCC system_header |
| 237 | #endif |
| 238 | |
| 239 | #define __cpp_lib_experimental_filesystem 201406 |
| 240 | |
| 241 | _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM |
| 242 | |
| 243 | typedef chrono::time_point<std::chrono::system_clock> file_time_type; |
| 244 | |
| 245 | struct _LIBCPP_TYPE_VIS space_info |
| 246 | { |
| 247 | uintmax_t capacity; |
| 248 | uintmax_t free; |
| 249 | uintmax_t available; |
| 250 | }; |
| 251 | |
Eric Fiselier | 833d644 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 252 | enum class _LIBCPP_ENUM_VIS file_type : signed char |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 253 | { |
| 254 | none = 0, |
| 255 | not_found = -1, |
| 256 | regular = 1, |
| 257 | directory = 2, |
| 258 | symlink = 3, |
| 259 | block = 4, |
| 260 | character = 5, |
| 261 | fifo = 6, |
| 262 | socket = 7, |
| 263 | unknown = 8 |
| 264 | }; |
| 265 | |
Eric Fiselier | 833d644 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 266 | enum class _LIBCPP_ENUM_VIS perms : unsigned |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 267 | { |
| 268 | none = 0, |
| 269 | |
| 270 | owner_read = 0400, |
| 271 | owner_write = 0200, |
| 272 | owner_exec = 0100, |
| 273 | owner_all = 0700, |
| 274 | |
| 275 | group_read = 040, |
| 276 | group_write = 020, |
| 277 | group_exec = 010, |
| 278 | group_all = 070, |
| 279 | |
| 280 | others_read = 04, |
| 281 | others_write = 02, |
| 282 | others_exec = 01, |
| 283 | others_all = 07, |
| 284 | |
| 285 | all = 0777, |
| 286 | |
| 287 | set_uid = 04000, |
| 288 | set_gid = 02000, |
| 289 | sticky_bit = 01000, |
| 290 | mask = 07777, |
| 291 | unknown = 0xFFFF, |
| 292 | |
| 293 | add_perms = 0x10000, |
| 294 | remove_perms = 0x20000, |
Eric Fiselier | 7c96ddb | 2016-06-21 22:42:42 +0000 | [diff] [blame] | 295 | symlink_nofollow = 0x40000 |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | _LIBCPP_INLINE_VISIBILITY |
| 299 | inline _LIBCPP_CONSTEXPR perms operator&(perms _LHS, perms _RHS) |
| 300 | { return static_cast<perms>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); } |
| 301 | |
| 302 | _LIBCPP_INLINE_VISIBILITY |
| 303 | inline _LIBCPP_CONSTEXPR perms operator|(perms _LHS, perms _RHS) |
| 304 | { return static_cast<perms>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); } |
| 305 | |
| 306 | _LIBCPP_INLINE_VISIBILITY |
| 307 | inline _LIBCPP_CONSTEXPR perms operator^(perms _LHS, perms _RHS) |
| 308 | { return static_cast<perms>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); } |
| 309 | |
| 310 | _LIBCPP_INLINE_VISIBILITY |
| 311 | inline _LIBCPP_CONSTEXPR perms operator~(perms _LHS) |
| 312 | { return static_cast<perms>(~static_cast<unsigned>(_LHS)); } |
| 313 | |
| 314 | _LIBCPP_INLINE_VISIBILITY |
| 315 | inline perms& operator&=(perms& _LHS, perms _RHS) |
| 316 | { return _LHS = _LHS & _RHS; } |
| 317 | |
| 318 | _LIBCPP_INLINE_VISIBILITY |
| 319 | inline perms& operator|=(perms& _LHS, perms _RHS) |
| 320 | { return _LHS = _LHS | _RHS; } |
| 321 | |
| 322 | _LIBCPP_INLINE_VISIBILITY |
| 323 | inline perms& operator^=(perms& _LHS, perms _RHS) |
| 324 | { return _LHS = _LHS ^ _RHS; } |
| 325 | |
Eric Fiselier | 833d644 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 326 | enum class _LIBCPP_ENUM_VIS copy_options : unsigned short |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 327 | { |
| 328 | none = 0, |
| 329 | skip_existing = 1, |
| 330 | overwrite_existing = 2, |
| 331 | update_existing = 4, |
| 332 | recursive = 8, |
| 333 | copy_symlinks = 16, |
| 334 | skip_symlinks = 32, |
| 335 | directories_only = 64, |
| 336 | create_symlinks = 128, |
| 337 | create_hard_links = 256, |
| 338 | __in_recursive_copy = 512, |
| 339 | }; |
| 340 | |
| 341 | _LIBCPP_INLINE_VISIBILITY |
| 342 | inline _LIBCPP_CONSTEXPR copy_options operator&(copy_options _LHS, copy_options _RHS) |
| 343 | { return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & static_cast<unsigned short>(_RHS)); } |
| 344 | |
| 345 | _LIBCPP_INLINE_VISIBILITY |
| 346 | inline _LIBCPP_CONSTEXPR copy_options operator|(copy_options _LHS, copy_options _RHS) |
| 347 | { return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | static_cast<unsigned short>(_RHS)); } |
| 348 | |
| 349 | _LIBCPP_INLINE_VISIBILITY |
| 350 | inline _LIBCPP_CONSTEXPR copy_options operator^(copy_options _LHS, copy_options _RHS) |
| 351 | { return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ static_cast<unsigned short>(_RHS)); } |
| 352 | |
| 353 | _LIBCPP_INLINE_VISIBILITY |
| 354 | inline _LIBCPP_CONSTEXPR copy_options operator~(copy_options _LHS) |
| 355 | { return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); } |
| 356 | |
| 357 | _LIBCPP_INLINE_VISIBILITY |
| 358 | inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) |
| 359 | { return _LHS = _LHS & _RHS; } |
| 360 | |
| 361 | _LIBCPP_INLINE_VISIBILITY |
| 362 | inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) |
| 363 | { return _LHS = _LHS | _RHS; } |
| 364 | |
| 365 | _LIBCPP_INLINE_VISIBILITY |
| 366 | inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) |
| 367 | { return _LHS = _LHS ^ _RHS; } |
| 368 | |
| 369 | |
Eric Fiselier | 833d644 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 370 | enum class _LIBCPP_ENUM_VIS directory_options : unsigned char |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 371 | { |
| 372 | none = 0, |
| 373 | follow_directory_symlink = 1, |
| 374 | skip_permission_denied = 2 |
| 375 | }; |
| 376 | |
| 377 | _LIBCPP_INLINE_VISIBILITY |
| 378 | inline _LIBCPP_CONSTEXPR directory_options operator&(directory_options _LHS, directory_options _RHS) |
| 379 | { return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & static_cast<unsigned char>(_RHS)); } |
| 380 | |
| 381 | _LIBCPP_INLINE_VISIBILITY |
| 382 | inline _LIBCPP_CONSTEXPR directory_options operator|(directory_options _LHS, directory_options _RHS) |
| 383 | { return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | static_cast<unsigned char>(_RHS)); } |
| 384 | |
| 385 | _LIBCPP_INLINE_VISIBILITY |
| 386 | inline _LIBCPP_CONSTEXPR directory_options operator^(directory_options _LHS, directory_options _RHS) |
| 387 | { return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ static_cast<unsigned char>(_RHS)); } |
| 388 | |
| 389 | _LIBCPP_INLINE_VISIBILITY |
| 390 | inline _LIBCPP_CONSTEXPR directory_options operator~(directory_options _LHS) |
| 391 | { return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); } |
| 392 | |
| 393 | _LIBCPP_INLINE_VISIBILITY |
| 394 | inline directory_options& operator&=(directory_options& _LHS, directory_options _RHS) |
| 395 | { return _LHS = _LHS & _RHS; } |
| 396 | |
| 397 | _LIBCPP_INLINE_VISIBILITY |
| 398 | inline directory_options& operator|=(directory_options& _LHS, directory_options _RHS) |
| 399 | { return _LHS = _LHS | _RHS; } |
| 400 | |
| 401 | _LIBCPP_INLINE_VISIBILITY |
| 402 | inline directory_options& operator^=(directory_options& _LHS, directory_options _RHS) |
| 403 | { return _LHS = _LHS ^ _RHS; } |
| 404 | |
| 405 | |
| 406 | class _LIBCPP_TYPE_VIS file_status |
| 407 | { |
| 408 | public: |
| 409 | // constructors |
| 410 | _LIBCPP_INLINE_VISIBILITY |
| 411 | explicit file_status(file_type __ft = file_type::none, |
| 412 | perms __prms = perms::unknown) _NOEXCEPT |
| 413 | : __ft_(__ft), __prms_(__prms) |
| 414 | {} |
| 415 | |
| 416 | file_status(const file_status&) _NOEXCEPT = default; |
| 417 | file_status(file_status&&) _NOEXCEPT = default; |
| 418 | |
| 419 | _LIBCPP_INLINE_VISIBILITY |
| 420 | ~file_status() {} |
| 421 | |
| 422 | file_status& operator=(const file_status&) _NOEXCEPT = default; |
| 423 | file_status& operator=(file_status&&) _NOEXCEPT = default; |
| 424 | |
| 425 | // observers |
| 426 | _LIBCPP_ALWAYS_INLINE |
| 427 | file_type type() const _NOEXCEPT { |
| 428 | return __ft_; |
| 429 | } |
| 430 | |
| 431 | _LIBCPP_ALWAYS_INLINE |
| 432 | perms permissions() const _NOEXCEPT { |
| 433 | return __prms_; |
| 434 | } |
| 435 | |
| 436 | // modifiers |
| 437 | _LIBCPP_ALWAYS_INLINE |
| 438 | void type(file_type __ft) _NOEXCEPT { |
| 439 | __ft_ = __ft; |
| 440 | } |
| 441 | |
| 442 | _LIBCPP_ALWAYS_INLINE |
| 443 | void permissions(perms __p) _NOEXCEPT { |
| 444 | __prms_ = __p; |
| 445 | } |
| 446 | private: |
| 447 | file_type __ft_; |
| 448 | perms __prms_; |
| 449 | }; |
| 450 | |
| 451 | class _LIBCPP_TYPE_VIS directory_entry; |
| 452 | |
| 453 | template <class _Tp> struct __can_convert_char { |
| 454 | static const bool value = false; |
| 455 | }; |
Eric Fiselier | 113315b | 2016-08-28 21:26:01 +0000 | [diff] [blame] | 456 | template <class _Tp> struct __can_convert_char<const _Tp> |
| 457 | : public __can_convert_char<_Tp> { |
| 458 | }; |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 459 | template <> struct __can_convert_char<char> { |
| 460 | static const bool value = true; |
| 461 | using __char_type = char; |
| 462 | }; |
| 463 | template <> struct __can_convert_char<wchar_t> { |
| 464 | static const bool value = true; |
| 465 | using __char_type = wchar_t; |
| 466 | }; |
| 467 | template <> struct __can_convert_char<char16_t> { |
| 468 | static const bool value = true; |
| 469 | using __char_type = char16_t; |
| 470 | }; |
| 471 | template <> struct __can_convert_char<char32_t> { |
| 472 | static const bool value = true; |
| 473 | using __char_type = char32_t; |
| 474 | }; |
| 475 | |
| 476 | template <class _ECharT> |
| 477 | typename enable_if<__can_convert_char<_ECharT>::value, bool>::type |
| 478 | __is_separator(_ECharT __e) { |
| 479 | return __e == _ECharT('/'); |
| 480 | }; |
| 481 | |
| 482 | struct _NullSentinal {}; |
| 483 | |
| 484 | template <class _Tp> |
| 485 | using _Void = void; |
| 486 | |
| 487 | template <class _Tp, class = void> |
| 488 | struct __is_pathable_string : public false_type {}; |
| 489 | |
| 490 | template <class _ECharT, class _Traits, class _Alloc> |
| 491 | struct __is_pathable_string<basic_string<_ECharT, _Traits, _Alloc>, |
| 492 | _Void<typename __can_convert_char<_ECharT>::__char_type>> |
| 493 | : public __can_convert_char<_ECharT> |
| 494 | { |
| 495 | using _Str = basic_string<_ECharT, _Traits, _Alloc>; |
| 496 | using _Base = __can_convert_char<_ECharT>; |
| 497 | static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } |
| 498 | static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); } |
| 499 | static _ECharT __first_or_null(_Str const& __s) { |
| 500 | return __s.empty() ? _ECharT{} : __s[0]; |
| 501 | } |
| 502 | }; |
| 503 | |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 504 | |
| 505 | template <class _ECharT, class _Traits> |
| 506 | struct __is_pathable_string<basic_string_view<_ECharT, _Traits>, |
| 507 | _Void<typename __can_convert_char<_ECharT>::__char_type>> |
| 508 | : public __can_convert_char<_ECharT> |
| 509 | { |
| 510 | using _Str = basic_string_view<_ECharT, _Traits>; |
| 511 | using _Base = __can_convert_char<_ECharT>; |
| 512 | static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } |
| 513 | static _ECharT const* __range_end(_Str const& __s) { return __s.data() + __s.length(); } |
| 514 | static _ECharT __first_or_null(_Str const& __s) { |
| 515 | return __s.empty() ? _ECharT{} : __s[0]; |
| 516 | } |
| 517 | }; |
| 518 | |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 519 | template <class _Source, |
| 520 | class _DS = typename decay<_Source>::type, |
| 521 | class _UnqualPtrType = typename remove_const< |
| 522 | typename remove_pointer<_DS>::type>::type, |
| 523 | bool _IsCharPtr = is_pointer<_DS>::value && |
| 524 | __can_convert_char<_UnqualPtrType>::value |
| 525 | > |
| 526 | struct __is_pathable_char_array : false_type {}; |
| 527 | |
| 528 | template <class _Source, class _ECharT, class _UPtr> |
| 529 | struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true> |
| 530 | : __can_convert_char<typename remove_const<_ECharT>::type> |
| 531 | { |
| 532 | using _Base = __can_convert_char<typename remove_const<_ECharT>::type>; |
| 533 | |
| 534 | static _ECharT const* __range_begin(const _ECharT* __b) { return __b; } |
| 535 | static _ECharT const* __range_end(const _ECharT* __b) |
| 536 | { |
| 537 | using _Iter = const _ECharT*; |
| 538 | const _ECharT __sentinal = _ECharT{}; |
| 539 | _Iter __e = __b; |
| 540 | for (; *__e != __sentinal; ++__e) |
| 541 | ; |
| 542 | return __e; |
| 543 | } |
| 544 | |
| 545 | static _ECharT __first_or_null(const _ECharT* __b) { return *__b; } |
| 546 | }; |
| 547 | |
| 548 | template <class _Iter, bool _IsIt = __is_input_iterator<_Iter>::value, class = void> |
| 549 | struct __is_pathable_iter : false_type {}; |
| 550 | |
| 551 | template <class _Iter> |
| 552 | struct __is_pathable_iter<_Iter, true, |
| 553 | _Void<typename __can_convert_char<typename iterator_traits<_Iter>::value_type>::__char_type>> |
| 554 | : __can_convert_char<typename iterator_traits<_Iter>::value_type> |
| 555 | { |
| 556 | using _ECharT = typename iterator_traits<_Iter>::value_type; |
| 557 | using _Base = __can_convert_char<_ECharT>; |
| 558 | |
| 559 | static _Iter __range_begin(_Iter __b) { return __b; } |
| 560 | static _NullSentinal __range_end(_Iter) { return _NullSentinal{}; } |
| 561 | |
| 562 | static _ECharT __first_or_null(_Iter __b) { return *__b; } |
| 563 | }; |
| 564 | |
| 565 | template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value, |
| 566 | bool _IsCharIterT = __is_pathable_char_array<_Tp>::value, |
| 567 | bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value |
| 568 | > |
| 569 | struct __is_pathable : false_type { |
| 570 | static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false"); |
| 571 | }; |
| 572 | |
| 573 | template <class _Tp> |
| 574 | struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {}; |
| 575 | |
| 576 | |
| 577 | template <class _Tp> |
| 578 | struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> {}; |
| 579 | |
| 580 | |
| 581 | template <class _Tp> |
| 582 | struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {}; |
| 583 | |
| 584 | |
| 585 | template <class _ECharT> |
| 586 | struct _PathCVT { |
| 587 | static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible"); |
| 588 | |
| 589 | typedef __narrow_to_utf8<sizeof(_ECharT)*__CHAR_BIT__> _Narrower; |
| 590 | |
| 591 | static void __append_range(string& __dest, _ECharT const* __b, _ECharT const* __e) { |
| 592 | _Narrower()(back_inserter(__dest), __b, __e); |
| 593 | } |
| 594 | |
| 595 | template <class _Iter> |
| 596 | static void __append_range(string& __dest, _Iter __b, _Iter __e) { |
| 597 | static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); |
| 598 | if (__b == __e) return; |
| 599 | basic_string<_ECharT> __tmp(__b, __e); |
| 600 | _Narrower()(back_inserter(__dest), __tmp.data(), |
| 601 | __tmp.data() + __tmp.length()); |
| 602 | } |
| 603 | |
| 604 | template <class _Iter> |
| 605 | static void __append_range(string& __dest, _Iter __b, _NullSentinal) { |
| 606 | static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); |
| 607 | const _ECharT __sentinal = _ECharT{}; |
| 608 | if (*__b == __sentinal) return; |
| 609 | basic_string<_ECharT> __tmp; |
| 610 | for (; *__b != __sentinal; ++__b) |
| 611 | __tmp.push_back(*__b); |
| 612 | _Narrower()(back_inserter(__dest), __tmp.data(), |
| 613 | __tmp.data() + __tmp.length()); |
| 614 | } |
| 615 | |
| 616 | template <class _Source> |
| 617 | static void __append_source(string& __dest, _Source const& __s) |
| 618 | { |
| 619 | using _Traits = __is_pathable<_Source>; |
| 620 | __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s)); |
| 621 | } |
| 622 | }; |
| 623 | |
| 624 | template <> |
| 625 | struct _PathCVT<char> { |
Eric Fiselier | ad1a12c | 2016-10-30 23:53:50 +0000 | [diff] [blame] | 626 | |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 627 | template <class _Iter> |
Eric Fiselier | 026d38e | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 628 | static typename enable_if< |
| 629 | __is_exactly_input_iterator<_Iter>::value |
| 630 | >::type __append_range(string& __dest, _Iter __b, _Iter __e) { |
| 631 | for (; __b != __e; ++__b) |
| 632 | __dest.push_back(*__b); |
| 633 | } |
| 634 | |
| 635 | template <class _Iter> |
| 636 | static typename enable_if< |
| 637 | __is_forward_iterator<_Iter>::value |
| 638 | >::type __append_range(string& __dest, _Iter __b, _Iter __e) { |
| 639 | __dest.__append_forward_unsafe(__b, __e); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | template <class _Iter> |
| 643 | static void __append_range(string& __dest, _Iter __b, _NullSentinal) { |
| 644 | const char __sentinal = char{}; |
| 645 | for (; *__b != __sentinal; ++__b) |
| 646 | __dest.push_back(*__b); |
| 647 | } |
| 648 | |
| 649 | template <class _Source> |
| 650 | static void __append_source(string& __dest, _Source const& __s) |
| 651 | { |
| 652 | using _Traits = __is_pathable<_Source>; |
Eric Fiselier | ad1a12c | 2016-10-30 23:53:50 +0000 | [diff] [blame] | 653 | __append_range(__dest, _Traits::__range_begin(__s), |
| 654 | _Traits::__range_end(__s)); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 655 | } |
| 656 | }; |
| 657 | |
| 658 | |
| 659 | class _LIBCPP_TYPE_VIS path |
| 660 | { |
| 661 | template <class _SourceOrIter, class _Tp = path&> |
| 662 | using _EnableIfPathable = typename |
| 663 | enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type; |
| 664 | |
| 665 | template <class _Tp> |
| 666 | using _SourceChar = typename __is_pathable<_Tp>::__char_type; |
| 667 | |
| 668 | template <class _Tp> |
| 669 | using _SourceCVT = _PathCVT<_SourceChar<_Tp>>; |
| 670 | |
| 671 | public: |
| 672 | typedef char value_type; |
| 673 | typedef basic_string<value_type> string_type; |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 674 | typedef _VSTD::string_view __string_view; |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 675 | static _LIBCPP_CONSTEXPR value_type preferred_separator = '/'; |
| 676 | |
| 677 | // constructors and destructor |
| 678 | _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {} |
| 679 | _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {} |
| 680 | _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : __pn_(_VSTD::move(__p.__pn_)) {} |
| 681 | |
| 682 | _LIBCPP_INLINE_VISIBILITY |
| 683 | path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {} |
| 684 | |
| 685 | template < |
| 686 | class _Source, |
| 687 | class = _EnableIfPathable<_Source, void> |
| 688 | > |
| 689 | path(const _Source& __src) { |
| 690 | _SourceCVT<_Source>::__append_source(__pn_, __src); |
| 691 | } |
| 692 | |
| 693 | template <class _InputIt> |
| 694 | path(_InputIt __first, _InputIt __last) { |
| 695 | typedef typename iterator_traits<_InputIt>::value_type _ItVal; |
| 696 | _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); |
| 697 | } |
| 698 | |
| 699 | // TODO Implement locale conversions. |
| 700 | template <class _Source, |
| 701 | class = _EnableIfPathable<_Source, void> |
| 702 | > |
| 703 | path(const _Source& __src, const locale& __loc); |
| 704 | template <class _InputIt> |
| 705 | path(_InputIt __first, _InputIt _last, const locale& __loc); |
| 706 | |
| 707 | _LIBCPP_INLINE_VISIBILITY |
| 708 | ~path() = default; |
| 709 | |
| 710 | // assignments |
| 711 | _LIBCPP_INLINE_VISIBILITY |
| 712 | path& operator=(const path& __p) { |
| 713 | __pn_ = __p.__pn_; |
| 714 | return *this; |
| 715 | } |
| 716 | |
| 717 | _LIBCPP_INLINE_VISIBILITY |
| 718 | path& operator=(path&& __p) _NOEXCEPT { |
| 719 | __pn_ = _VSTD::move(__p.__pn_); |
| 720 | return *this; |
| 721 | } |
| 722 | |
Eric Fiselier | f2b4889 | 2017-01-18 05:48:55 +0000 | [diff] [blame^] | 723 | template <class = void> |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 724 | _LIBCPP_INLINE_VISIBILITY |
| 725 | path& operator=(string_type&& __s) _NOEXCEPT { |
| 726 | __pn_ = _VSTD::move(__s); |
| 727 | return *this; |
| 728 | } |
| 729 | |
| 730 | _LIBCPP_INLINE_VISIBILITY |
| 731 | path& assign(string_type&& __s) _NOEXCEPT { |
| 732 | __pn_ = _VSTD::move(__s); |
| 733 | return *this; |
| 734 | } |
| 735 | |
| 736 | template <class _Source> |
| 737 | _LIBCPP_INLINE_VISIBILITY |
| 738 | _EnableIfPathable<_Source> |
| 739 | operator=(const _Source& __src) |
| 740 | { return this->assign(__src); } |
| 741 | |
| 742 | |
| 743 | template <class _Source> |
| 744 | _EnableIfPathable<_Source> |
| 745 | assign(const _Source& __src) { |
| 746 | __pn_.clear(); |
| 747 | _SourceCVT<_Source>::__append_source(__pn_, __src); |
| 748 | return *this; |
| 749 | } |
| 750 | |
| 751 | template <class _InputIt> |
| 752 | path& assign(_InputIt __first, _InputIt __last) { |
| 753 | typedef typename iterator_traits<_InputIt>::value_type _ItVal; |
| 754 | __pn_.clear(); |
| 755 | _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); |
| 756 | return *this; |
| 757 | } |
| 758 | |
| 759 | private: |
| 760 | template <class _ECharT> |
| 761 | void __append_sep_if_needed(_ECharT __first_or_null) { |
| 762 | const _ECharT __null_val = {}; |
| 763 | bool __append_sep = !empty() && |
| 764 | !__is_separator(__pn_.back()) && |
| 765 | __first_or_null != __null_val && // non-empty |
| 766 | !__is_separator(__first_or_null); |
| 767 | if (__append_sep) |
| 768 | __pn_ += preferred_separator; |
| 769 | } |
| 770 | |
| 771 | public: |
| 772 | // appends |
| 773 | path& operator/=(const path& __p) { |
Eric Fiselier | 4ca4e50 | 2016-10-15 21:29:44 +0000 | [diff] [blame] | 774 | _LIBCPP_ASSERT(!__p.has_root_name(), |
| 775 | "cannot append to a path with a root name"); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 776 | __append_sep_if_needed(__p.empty() ? char{} : __p.__pn_[0]); |
| 777 | __pn_ += __p.native(); |
| 778 | return *this; |
| 779 | } |
| 780 | |
| 781 | template <class _Source> |
| 782 | _LIBCPP_INLINE_VISIBILITY |
| 783 | _EnableIfPathable<_Source> |
| 784 | operator/=(const _Source& __src) { |
| 785 | return this->append(__src); |
| 786 | } |
| 787 | |
| 788 | template <class _Source> |
| 789 | _EnableIfPathable<_Source> |
| 790 | append(const _Source& __src) { |
| 791 | using _Traits = __is_pathable<_Source>; |
| 792 | using _CVT = _PathCVT<_SourceChar<_Source>>; |
| 793 | __append_sep_if_needed(_Traits::__first_or_null(__src)); |
| 794 | _CVT::__append_source(__pn_, __src); |
| 795 | return *this; |
| 796 | } |
| 797 | |
| 798 | template <class _InputIt> |
| 799 | path& append(_InputIt __first, _InputIt __last) { |
| 800 | typedef typename iterator_traits<_InputIt>::value_type _ItVal; |
| 801 | static_assert(__can_convert_char<_ItVal>::value, "Must convertible"); |
| 802 | using _CVT = _PathCVT<_ItVal>; |
| 803 | if (__first != __last) { |
| 804 | __append_sep_if_needed(*__first); |
| 805 | _CVT::__append_range(__pn_, __first, __last); |
| 806 | } |
| 807 | return *this; |
| 808 | } |
| 809 | |
| 810 | // concatenation |
| 811 | _LIBCPP_INLINE_VISIBILITY |
| 812 | path& operator+=(const path& __x) { |
| 813 | __pn_ += __x.__pn_; |
| 814 | return *this; |
| 815 | } |
| 816 | |
| 817 | _LIBCPP_INLINE_VISIBILITY |
| 818 | path& operator+=(const string_type& __x) { |
| 819 | __pn_ += __x; |
| 820 | return *this; |
| 821 | } |
| 822 | |
| 823 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 824 | path& operator+=(__string_view __x) { |
| 825 | __pn_ += __x; |
| 826 | return *this; |
| 827 | } |
| 828 | |
| 829 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 830 | path& operator+=(const value_type* __x) { |
| 831 | __pn_ += __x; |
| 832 | return *this; |
| 833 | } |
| 834 | |
| 835 | _LIBCPP_INLINE_VISIBILITY |
| 836 | path& operator+=(value_type __x) { |
| 837 | __pn_ += __x; |
| 838 | return *this; |
| 839 | } |
| 840 | |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 841 | template <class _ECharT> |
| 842 | typename enable_if<__can_convert_char<_ECharT>::value, path&>::type |
| 843 | operator+=(_ECharT __x) |
| 844 | { |
| 845 | basic_string<_ECharT> __tmp; |
| 846 | __tmp += __x; |
| 847 | _PathCVT<_ECharT>::__append_source(__pn_, __tmp); |
| 848 | return *this; |
| 849 | } |
| 850 | |
| 851 | template <class _Source> |
| 852 | _EnableIfPathable<_Source> |
| 853 | operator+=(const _Source& __x) { |
| 854 | return this->concat(__x); |
| 855 | } |
| 856 | |
| 857 | template <class _Source> |
| 858 | _EnableIfPathable<_Source> |
| 859 | concat(const _Source& __x) { |
| 860 | _SourceCVT<_Source>::__append_source(__pn_, __x); |
| 861 | return *this; |
| 862 | } |
| 863 | |
| 864 | template <class _InputIt> |
| 865 | path& concat(_InputIt __first, _InputIt __last) { |
| 866 | typedef typename iterator_traits<_InputIt>::value_type _ItVal; |
| 867 | _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); |
| 868 | return *this; |
| 869 | } |
| 870 | |
| 871 | // modifiers |
| 872 | _LIBCPP_INLINE_VISIBILITY |
| 873 | void clear() _NOEXCEPT { |
| 874 | __pn_.clear(); |
| 875 | } |
| 876 | |
| 877 | path& make_preferred() { return *this; } |
Eric Fiselier | 620a9a5 | 2016-10-15 22:37:42 +0000 | [diff] [blame] | 878 | |
| 879 | _LIBCPP_INLINE_VISIBILITY |
| 880 | path& remove_filename() { |
| 881 | if (__pn_.size() == __root_path_raw().size()) |
| 882 | clear(); |
| 883 | else |
| 884 | __pn_ = __parent_path(); |
| 885 | return *this; |
| 886 | } |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 887 | |
| 888 | path& replace_filename(const path& __replacement) { |
| 889 | remove_filename(); |
| 890 | return (*this /= __replacement); |
| 891 | } |
| 892 | |
| 893 | path& replace_extension(const path& __replacement = path()); |
| 894 | |
| 895 | _LIBCPP_INLINE_VISIBILITY |
| 896 | void swap(path& __rhs) _NOEXCEPT { |
| 897 | __pn_.swap(__rhs.__pn_); |
| 898 | } |
| 899 | |
| 900 | // native format observers |
| 901 | _LIBCPP_INLINE_VISIBILITY |
| 902 | const string_type& native() const _NOEXCEPT { |
| 903 | return __pn_; |
| 904 | } |
| 905 | |
| 906 | _LIBCPP_INLINE_VISIBILITY |
| 907 | const value_type* c_str() const _NOEXCEPT { return __pn_.c_str(); } |
| 908 | |
| 909 | _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; } |
| 910 | |
| 911 | template <class _ECharT, class _Traits = char_traits<_ECharT>, |
| 912 | class _Allocator = allocator<_ECharT> > |
| 913 | basic_string<_ECharT, _Traits, _Allocator> |
| 914 | string(const _Allocator& __a = _Allocator()) const { |
| 915 | using _CVT = __widen_from_utf8<sizeof(_ECharT)*__CHAR_BIT__>; |
| 916 | using _Str = basic_string<_ECharT, _Traits, _Allocator>; |
| 917 | _Str __s(__a); |
| 918 | __s.reserve(__pn_.size()); |
| 919 | _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size()); |
| 920 | return __s; |
| 921 | } |
| 922 | |
| 923 | _LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; } |
| 924 | _LIBCPP_INLINE_VISIBILITY std::wstring wstring() const { return string<wchar_t>(); } |
| 925 | _LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; } |
| 926 | _LIBCPP_INLINE_VISIBILITY std::u16string u16string() const { return string<char16_t>(); } |
| 927 | _LIBCPP_INLINE_VISIBILITY std::u32string u32string() const { return string<char32_t>(); } |
| 928 | |
| 929 | // generic format observers |
| 930 | template <class _ECharT, class _Traits = char_traits<_ECharT>, |
| 931 | class _Allocator = allocator<_ECharT> |
| 932 | > |
| 933 | basic_string<_ECharT, _Traits, _Allocator> |
| 934 | generic_string(const _Allocator& __a = _Allocator()) const { |
| 935 | return string<_ECharT, _Traits, _Allocator>(__a); |
| 936 | } |
| 937 | |
| 938 | std::string generic_string() const { return __pn_; } |
| 939 | std::wstring generic_wstring() const { return string<wchar_t>(); } |
| 940 | std::string generic_u8string() const { return __pn_; } |
| 941 | std::u16string generic_u16string() const { return string<char16_t>(); } |
| 942 | std::u32string generic_u32string() const { return string<char32_t>(); } |
| 943 | |
| 944 | private: |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 945 | _LIBCPP_FUNC_VIS int __compare(__string_view) const; |
| 946 | _LIBCPP_FUNC_VIS __string_view __root_name() const; |
| 947 | _LIBCPP_FUNC_VIS __string_view __root_directory() const; |
Eric Fiselier | 620a9a5 | 2016-10-15 22:37:42 +0000 | [diff] [blame] | 948 | _LIBCPP_FUNC_VIS __string_view __root_path_raw() const; |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 949 | _LIBCPP_FUNC_VIS __string_view __relative_path() const; |
| 950 | _LIBCPP_FUNC_VIS __string_view __parent_path() const; |
| 951 | _LIBCPP_FUNC_VIS __string_view __filename() const; |
| 952 | _LIBCPP_FUNC_VIS __string_view __stem() const; |
| 953 | _LIBCPP_FUNC_VIS __string_view __extension() const; |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 954 | |
| 955 | public: |
| 956 | // compare |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 957 | _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const _NOEXCEPT { return __compare(__p.__pn_);} |
| 958 | _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { return __compare(__s); } |
| 959 | _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { return __compare(__s); } |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 960 | _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { return __compare(__s); } |
| 961 | |
| 962 | // decomposition |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 963 | _LIBCPP_INLINE_VISIBILITY path root_name() const { return string_type(__root_name()); } |
| 964 | _LIBCPP_INLINE_VISIBILITY path root_directory() const { return string_type(__root_directory()); } |
| 965 | _LIBCPP_INLINE_VISIBILITY path root_path() const { return root_name().append(string_type(__root_directory())); } |
| 966 | _LIBCPP_INLINE_VISIBILITY path relative_path() const { return string_type(__relative_path()); } |
| 967 | _LIBCPP_INLINE_VISIBILITY path parent_path() const { return string_type(__parent_path()); } |
| 968 | _LIBCPP_INLINE_VISIBILITY path filename() const { return string_type(__filename()); } |
| 969 | _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem());} |
| 970 | _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); } |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 971 | |
| 972 | // query |
| 973 | _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); } |
| 974 | |
| 975 | _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); } |
| 976 | _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); } |
Eric Fiselier | 620a9a5 | 2016-10-15 22:37:42 +0000 | [diff] [blame] | 977 | _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { return !__root_path_raw().empty(); } |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 978 | _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { return !__relative_path().empty(); } |
| 979 | _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { return !__parent_path().empty(); } |
| 980 | _LIBCPP_INLINE_VISIBILITY bool has_filename() const { return !__filename().empty(); } |
| 981 | _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); } |
| 982 | _LIBCPP_INLINE_VISIBILITY bool has_extension() const { return !__extension().empty(); } |
| 983 | |
| 984 | _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { return has_root_directory(); } |
| 985 | _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); } |
| 986 | |
| 987 | // iterators |
| 988 | class _LIBCPP_TYPE_VIS iterator; |
| 989 | typedef iterator const_iterator; |
| 990 | |
| 991 | _LIBCPP_FUNC_VIS iterator begin() const; |
| 992 | _LIBCPP_FUNC_VIS iterator end() const; |
| 993 | |
| 994 | private: |
| 995 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2645dbe | 2016-07-23 03:10:56 +0000 | [diff] [blame] | 996 | path& __assign_view(__string_view const& __s) noexcept { __pn_ = string_type(__s); return *this; } |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 997 | string_type __pn_; |
| 998 | }; |
| 999 | |
| 1000 | inline _LIBCPP_ALWAYS_INLINE |
| 1001 | void swap(path& __lhs, path& __rhs) _NOEXCEPT { |
| 1002 | __lhs.swap(__rhs); |
| 1003 | } |
| 1004 | |
| 1005 | _LIBCPP_FUNC_VIS |
| 1006 | size_t hash_value(const path& __p) _NOEXCEPT; |
| 1007 | |
| 1008 | inline _LIBCPP_INLINE_VISIBILITY |
| 1009 | bool operator==(const path& __lhs, const path& __rhs) _NOEXCEPT |
| 1010 | { return __lhs.compare(__rhs) == 0; } |
| 1011 | |
| 1012 | inline _LIBCPP_INLINE_VISIBILITY |
| 1013 | bool operator!=(const path& __lhs, const path& __rhs) _NOEXCEPT |
| 1014 | { return __lhs.compare(__rhs) != 0; } |
| 1015 | |
| 1016 | inline _LIBCPP_INLINE_VISIBILITY |
| 1017 | bool operator<(const path& __lhs, const path& __rhs) _NOEXCEPT |
| 1018 | { return __lhs.compare(__rhs) < 0; } |
| 1019 | |
| 1020 | inline _LIBCPP_INLINE_VISIBILITY |
| 1021 | bool operator<=(const path& __lhs, const path& __rhs) _NOEXCEPT |
| 1022 | { return __lhs.compare(__rhs) <= 0; } |
| 1023 | |
| 1024 | inline _LIBCPP_INLINE_VISIBILITY |
| 1025 | bool operator>(const path& __lhs, const path& __rhs) _NOEXCEPT |
| 1026 | { return __lhs.compare(__rhs) > 0; } |
| 1027 | |
| 1028 | inline _LIBCPP_INLINE_VISIBILITY |
| 1029 | bool operator>=(const path& __lhs, const path& __rhs) _NOEXCEPT |
| 1030 | { return __lhs.compare(__rhs) >= 0; } |
| 1031 | |
| 1032 | inline _LIBCPP_INLINE_VISIBILITY |
| 1033 | path operator/(const path& __lhs, const path& __rhs) { |
| 1034 | return path(__lhs) /= __rhs; |
| 1035 | } |
| 1036 | |
| 1037 | template <class _CharT, class _Traits> |
| 1038 | _LIBCPP_INLINE_VISIBILITY |
| 1039 | typename enable_if<is_same<_CharT, char>::value && |
| 1040 | is_same<_Traits, char_traits<char>>::value, |
| 1041 | basic_ostream<_CharT, _Traits>& |
| 1042 | >::type |
| 1043 | operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { |
| 1044 | __os << std::__quoted(__p.native()); |
| 1045 | return __os; |
| 1046 | } |
| 1047 | |
| 1048 | template <class _CharT, class _Traits> |
| 1049 | _LIBCPP_INLINE_VISIBILITY |
| 1050 | typename enable_if<!is_same<_CharT, char>::value || |
| 1051 | !is_same<_Traits, char_traits<char>>::value, |
| 1052 | basic_ostream<_CharT, _Traits>& |
| 1053 | >::type |
| 1054 | operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { |
| 1055 | __os << std::__quoted(__p.string<_CharT, _Traits>()); |
| 1056 | return __os; |
| 1057 | } |
| 1058 | |
| 1059 | template <class _CharT, class _Traits> |
| 1060 | _LIBCPP_INLINE_VISIBILITY |
| 1061 | basic_istream<_CharT, _Traits>& |
| 1062 | operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) |
| 1063 | { |
| 1064 | basic_string<_CharT, _Traits> __tmp; |
| 1065 | __is >> __quoted(__tmp); |
| 1066 | __p = __tmp; |
| 1067 | return __is; |
| 1068 | } |
| 1069 | |
| 1070 | template <class _Source> |
| 1071 | _LIBCPP_INLINE_VISIBILITY |
| 1072 | typename enable_if<__is_pathable<_Source>::value, path>::type |
| 1073 | u8path(const _Source& __s){ |
| 1074 | static_assert(is_same<typename __is_pathable<_Source>::__char_type, char>::value, |
| 1075 | "u8path(Source const&) requires Source have a character type of type 'char'"); |
| 1076 | return path(__s); |
| 1077 | } |
| 1078 | |
| 1079 | template <class _InputIt> |
| 1080 | _LIBCPP_INLINE_VISIBILITY |
| 1081 | typename enable_if<__is_pathable<_InputIt>::value, path>::type |
| 1082 | u8path(_InputIt __f, _InputIt __l) { |
| 1083 | static_assert(is_same<typename __is_pathable<_InputIt>::__char_type, char>::value, |
| 1084 | "u8path(Iter, Iter) requires Iter have a value_type of type 'char'"); |
| 1085 | return path(__f, __l); |
| 1086 | } |
| 1087 | |
| 1088 | class _LIBCPP_TYPE_VIS path::iterator |
| 1089 | { |
| 1090 | public: |
| 1091 | typedef bidirectional_iterator_tag iterator_category; |
| 1092 | typedef path value_type; |
| 1093 | typedef std::ptrdiff_t difference_type; |
| 1094 | typedef const path* pointer; |
| 1095 | typedef const path& reference; |
| 1096 | public: |
| 1097 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1098 | iterator() : __stashed_elem_(), __path_ptr_(nullptr), |
| 1099 | __entry_(), __state_(__singular) {} |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1100 | |
| 1101 | iterator(const iterator&) = default; |
| 1102 | ~iterator() = default; |
| 1103 | |
| 1104 | iterator& operator=(const iterator&) = default; |
| 1105 | |
| 1106 | _LIBCPP_INLINE_VISIBILITY |
| 1107 | reference operator*() const { |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1108 | return __stashed_elem_; |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | _LIBCPP_INLINE_VISIBILITY |
| 1112 | pointer operator->() const { |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1113 | return &__stashed_elem_; |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | _LIBCPP_INLINE_VISIBILITY |
| 1117 | iterator& operator++() { |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1118 | _LIBCPP_ASSERT(__state_ != __singular, |
| 1119 | "attempting to increment a singular iterator"); |
| 1120 | _LIBCPP_ASSERT(__state_ != __at_end, |
| 1121 | "attempting to increment the end iterator"); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1122 | return __increment(); |
| 1123 | } |
| 1124 | |
| 1125 | _LIBCPP_INLINE_VISIBILITY |
| 1126 | iterator operator++(int) { |
| 1127 | iterator __it(*this); |
| 1128 | this->operator++(); |
| 1129 | return __it; |
| 1130 | } |
| 1131 | |
| 1132 | _LIBCPP_INLINE_VISIBILITY |
| 1133 | iterator& operator--() { |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1134 | _LIBCPP_ASSERT(__state_ != __singular, |
| 1135 | "attempting to decrement a singular iterator"); |
| 1136 | _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(), |
| 1137 | "attempting to decrement the begin iterator"); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1138 | return __decrement(); |
| 1139 | } |
| 1140 | |
| 1141 | _LIBCPP_INLINE_VISIBILITY |
| 1142 | iterator operator--(int) { |
| 1143 | iterator __it(*this); |
| 1144 | this->operator--(); |
| 1145 | return __it; |
| 1146 | } |
| 1147 | |
| 1148 | private: |
| 1149 | friend class path; |
Eric Fiselier | 03f7d10 | 2016-09-16 00:07:16 +0000 | [diff] [blame] | 1150 | |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1151 | static constexpr unsigned char __singular = 0; |
| 1152 | static constexpr unsigned char __at_end = 6; |
| 1153 | |
Eric Fiselier | 03f7d10 | 2016-09-16 00:07:16 +0000 | [diff] [blame] | 1154 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1155 | friend bool operator==(const iterator&, const iterator&); |
| 1156 | |
| 1157 | _LIBCPP_FUNC_VIS iterator& __increment(); |
| 1158 | _LIBCPP_FUNC_VIS iterator& __decrement(); |
| 1159 | |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1160 | path __stashed_elem_; |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1161 | const path* __path_ptr_; |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1162 | path::__string_view __entry_; |
| 1163 | unsigned char __state_; |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1164 | }; |
| 1165 | |
| 1166 | inline _LIBCPP_INLINE_VISIBILITY |
| 1167 | bool operator==(const path::iterator& __lhs, const path::iterator& __rhs) { |
| 1168 | return __lhs.__path_ptr_ == __rhs.__path_ptr_ && |
Eric Fiselier | 271a19e | 2016-10-30 23:30:38 +0000 | [diff] [blame] | 1169 | __lhs.__entry_.data() == __rhs.__entry_.data(); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | inline _LIBCPP_INLINE_VISIBILITY |
| 1173 | bool operator!=(const path::iterator& __lhs, const path::iterator& __rhs) { |
| 1174 | return !(__lhs == __rhs); |
| 1175 | } |
| 1176 | |
| 1177 | class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error |
| 1178 | { |
| 1179 | public: |
| 1180 | _LIBCPP_INLINE_VISIBILITY |
| 1181 | filesystem_error(const string& __what, error_code __ec) |
| 1182 | : system_error(__ec, __what), |
| 1183 | __paths_(make_shared<_Storage>(path(), path())) |
| 1184 | {} |
| 1185 | |
| 1186 | _LIBCPP_INLINE_VISIBILITY |
| 1187 | filesystem_error(const string& __what, const path& __p1, error_code __ec) |
| 1188 | : system_error(__ec, __what), |
| 1189 | __paths_(make_shared<_Storage>(__p1, path())) |
| 1190 | {} |
| 1191 | |
| 1192 | _LIBCPP_INLINE_VISIBILITY |
| 1193 | filesystem_error(const string& __what, const path& __p1, const path& __p2, |
| 1194 | error_code __ec) |
| 1195 | : system_error(__ec, __what), |
| 1196 | __paths_(make_shared<_Storage>(__p1, __p2)) |
| 1197 | {} |
| 1198 | |
| 1199 | _LIBCPP_INLINE_VISIBILITY |
| 1200 | const path& path1() const _NOEXCEPT { |
| 1201 | return __paths_->first; |
| 1202 | } |
| 1203 | |
| 1204 | _LIBCPP_INLINE_VISIBILITY |
| 1205 | const path& path2() const _NOEXCEPT { |
| 1206 | return __paths_->second; |
| 1207 | } |
| 1208 | |
| 1209 | _LIBCPP_FUNC_VIS |
| 1210 | ~filesystem_error() override; // key function |
| 1211 | |
| 1212 | // TODO(ericwf): Create a custom error message. |
| 1213 | //const char* what() const _NOEXCEPT; |
| 1214 | |
| 1215 | private: |
| 1216 | typedef pair<path, path> _Storage; |
| 1217 | shared_ptr<_Storage> __paths_; |
| 1218 | }; |
| 1219 | |
Marshall Clow | e7acb0e | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1220 | template <class... _Args> |
| 1221 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
Eric Fiselier | 0e5ebbc | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1222 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | e7acb0e | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1223 | void __throw_filesystem_error(_Args && ...__args) |
| 1224 | { |
Marshall Clow | e7acb0e | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1225 | throw filesystem_error(std::forward<_Args>(__args)...); |
Marshall Clow | e7acb0e | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1226 | } |
Eric Fiselier | 0e5ebbc | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1227 | #else |
| 1228 | void __throw_filesystem_error(_Args&&...) |
| 1229 | { |
| 1230 | _VSTD::abort(); |
| 1231 | } |
| 1232 | #endif |
| 1233 | |
Marshall Clow | e7acb0e | 2016-08-25 17:47:09 +0000 | [diff] [blame] | 1234 | |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1235 | // operational functions |
| 1236 | |
| 1237 | _LIBCPP_FUNC_VIS |
| 1238 | path __canonical(const path&, const path&, error_code *__ec=nullptr); |
| 1239 | _LIBCPP_FUNC_VIS |
| 1240 | void __copy(const path& __from, const path& __to, copy_options __opt, |
| 1241 | error_code *__ec=nullptr); |
| 1242 | _LIBCPP_FUNC_VIS |
| 1243 | bool __copy_file(const path& __from, const path& __to, copy_options __opt, |
| 1244 | error_code *__ec=nullptr); |
| 1245 | _LIBCPP_FUNC_VIS |
| 1246 | void __copy_symlink(const path& __existing_symlink, const path& __new_symlink, |
| 1247 | error_code *__ec=nullptr); |
| 1248 | _LIBCPP_FUNC_VIS |
| 1249 | bool __create_directories(const path& p, error_code *ec=nullptr); |
| 1250 | _LIBCPP_FUNC_VIS |
| 1251 | bool __create_directory(const path& p, error_code *ec=nullptr); |
| 1252 | _LIBCPP_FUNC_VIS |
| 1253 | bool __create_directory(const path& p, const path & attributes, |
| 1254 | error_code *ec=nullptr); |
| 1255 | _LIBCPP_FUNC_VIS |
| 1256 | void __create_directory_symlink(const path& __to, const path& __new_symlink, |
| 1257 | error_code *__ec=nullptr); |
| 1258 | _LIBCPP_FUNC_VIS |
| 1259 | void __create_hard_link(const path& __to, const path& __new_hard_link, |
| 1260 | error_code *__ec=nullptr); |
| 1261 | _LIBCPP_FUNC_VIS |
| 1262 | void __create_symlink(const path& __to, const path& __new_symlink, |
| 1263 | error_code *__ec=nullptr); |
| 1264 | _LIBCPP_FUNC_VIS |
| 1265 | path __current_path(error_code *__ec=nullptr); |
| 1266 | _LIBCPP_FUNC_VIS |
| 1267 | void __current_path(const path&, error_code *__ec=nullptr); |
| 1268 | _LIBCPP_FUNC_VIS |
| 1269 | bool __equivalent(const path&, const path&, error_code *__ec=nullptr); |
| 1270 | _LIBCPP_FUNC_VIS |
| 1271 | uintmax_t __file_size(const path&, error_code *__ec=nullptr); |
| 1272 | _LIBCPP_FUNC_VIS |
| 1273 | uintmax_t __hard_link_count(const path&, error_code *__ec=nullptr); |
| 1274 | _LIBCPP_FUNC_VIS |
| 1275 | bool __fs_is_empty(const path& p, error_code *ec=nullptr); |
| 1276 | _LIBCPP_FUNC_VIS |
| 1277 | file_time_type __last_write_time(const path& p, error_code *ec=nullptr); |
| 1278 | _LIBCPP_FUNC_VIS |
| 1279 | void __last_write_time(const path& p, file_time_type new_time, |
| 1280 | error_code *ec=nullptr); |
| 1281 | _LIBCPP_FUNC_VIS |
| 1282 | void __permissions(const path& p, perms prms, error_code *ec=nullptr); |
| 1283 | _LIBCPP_FUNC_VIS |
| 1284 | path __read_symlink(const path& p, error_code *ec=nullptr); |
| 1285 | _LIBCPP_FUNC_VIS |
| 1286 | bool __remove(const path& p, error_code *ec=nullptr); |
| 1287 | _LIBCPP_FUNC_VIS |
| 1288 | uintmax_t __remove_all(const path& p, error_code *ec=nullptr); |
| 1289 | _LIBCPP_FUNC_VIS |
| 1290 | void __rename(const path& from, const path& to, error_code *ec=nullptr); |
| 1291 | _LIBCPP_FUNC_VIS |
| 1292 | void __resize_file(const path& p, uintmax_t size, error_code *ec=nullptr); |
| 1293 | _LIBCPP_FUNC_VIS |
| 1294 | space_info __space(const path&, error_code *__ec=nullptr); |
| 1295 | _LIBCPP_FUNC_VIS |
| 1296 | file_status __status(const path&, error_code *__ec=nullptr); |
| 1297 | _LIBCPP_FUNC_VIS |
| 1298 | file_status __symlink_status(const path&, error_code *__ec=nullptr); |
| 1299 | _LIBCPP_FUNC_VIS |
| 1300 | path __system_complete(const path&, error_code *__ec=nullptr); |
| 1301 | _LIBCPP_FUNC_VIS |
| 1302 | path __temp_directory_path(error_code *__ec=nullptr); |
| 1303 | |
| 1304 | inline _LIBCPP_INLINE_VISIBILITY |
| 1305 | path current_path() { |
| 1306 | return __current_path(); |
| 1307 | } |
| 1308 | |
| 1309 | inline _LIBCPP_INLINE_VISIBILITY |
| 1310 | path current_path(error_code& __ec) { |
| 1311 | return __current_path(&__ec); |
| 1312 | } |
| 1313 | |
| 1314 | inline _LIBCPP_INLINE_VISIBILITY |
| 1315 | void current_path(const path& __p) { |
| 1316 | __current_path(__p); |
| 1317 | } |
| 1318 | |
| 1319 | inline _LIBCPP_INLINE_VISIBILITY |
| 1320 | void current_path(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1321 | __current_path(__p, &__ec); |
| 1322 | } |
| 1323 | |
| 1324 | _LIBCPP_FUNC_VIS |
| 1325 | path absolute(const path&, const path& __p2 = current_path()); |
| 1326 | |
| 1327 | inline _LIBCPP_INLINE_VISIBILITY |
| 1328 | path canonical(const path& __p, const path& __base = current_path()) { |
| 1329 | return __canonical(__p, __base); |
| 1330 | } |
| 1331 | |
| 1332 | inline _LIBCPP_INLINE_VISIBILITY |
| 1333 | path canonical(const path& __p, error_code& __ec) { |
| 1334 | path __base = __current_path(&__ec); |
| 1335 | if (__ec) return {}; |
| 1336 | return __canonical(__p, __base, &__ec); |
| 1337 | } |
| 1338 | |
| 1339 | inline _LIBCPP_INLINE_VISIBILITY |
| 1340 | path canonical(const path& __p, const path& __base, error_code& __ec) { |
| 1341 | return __canonical(__p, __base, &__ec); |
| 1342 | } |
| 1343 | |
| 1344 | inline _LIBCPP_INLINE_VISIBILITY |
| 1345 | void copy(const path& __from, const path& __to) { |
| 1346 | __copy(__from, __to, copy_options::none); |
| 1347 | } |
| 1348 | |
| 1349 | inline _LIBCPP_INLINE_VISIBILITY |
| 1350 | void copy(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { |
| 1351 | __copy(__from, __to, copy_options::none, &__ec); |
| 1352 | } |
| 1353 | |
| 1354 | inline _LIBCPP_INLINE_VISIBILITY |
| 1355 | void copy(const path& __from, const path& __to, copy_options __opt) { |
| 1356 | __copy(__from, __to, __opt); |
| 1357 | } |
| 1358 | |
| 1359 | inline _LIBCPP_INLINE_VISIBILITY |
| 1360 | void copy(const path& __from, const path& __to, |
| 1361 | copy_options __opt, error_code& __ec) _NOEXCEPT { |
| 1362 | __copy(__from, __to, __opt, &__ec); |
| 1363 | } |
| 1364 | |
| 1365 | inline _LIBCPP_INLINE_VISIBILITY |
| 1366 | bool copy_file(const path& __from, const path& __to) { |
| 1367 | return __copy_file(__from, __to, copy_options::none); |
| 1368 | } |
| 1369 | |
| 1370 | inline _LIBCPP_INLINE_VISIBILITY |
| 1371 | bool copy_file(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { |
| 1372 | return __copy_file(__from, __to, copy_options::none, &__ec); |
| 1373 | } |
| 1374 | |
| 1375 | inline _LIBCPP_INLINE_VISIBILITY |
| 1376 | bool copy_file(const path& __from, const path& __to, copy_options __opt) { |
| 1377 | return __copy_file(__from, __to, __opt); |
| 1378 | } |
| 1379 | |
| 1380 | inline _LIBCPP_INLINE_VISIBILITY |
| 1381 | bool copy_file(const path& __from, const path& __to, |
| 1382 | copy_options __opt, error_code& __ec) _NOEXCEPT { |
| 1383 | return __copy_file(__from, __to, __opt, &__ec); |
| 1384 | } |
| 1385 | |
| 1386 | inline _LIBCPP_INLINE_VISIBILITY |
| 1387 | void copy_symlink(const path& __existing, const path& __new) { |
| 1388 | __copy_symlink(__existing, __new); |
| 1389 | } |
| 1390 | |
| 1391 | inline _LIBCPP_INLINE_VISIBILITY |
| 1392 | void copy_symlink(const path& __ext, const path& __new, error_code& __ec) _NOEXCEPT { |
| 1393 | __copy_symlink(__ext, __new, &__ec); |
| 1394 | } |
| 1395 | |
| 1396 | inline _LIBCPP_INLINE_VISIBILITY |
| 1397 | bool create_directories(const path& __p) { |
| 1398 | return __create_directories(__p); |
| 1399 | } |
| 1400 | |
| 1401 | inline _LIBCPP_INLINE_VISIBILITY |
| 1402 | bool create_directories(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1403 | return __create_directories(__p, &__ec); |
| 1404 | } |
| 1405 | |
| 1406 | inline _LIBCPP_INLINE_VISIBILITY |
| 1407 | bool create_directory(const path& __p) { |
| 1408 | return __create_directory(__p); |
| 1409 | } |
| 1410 | |
| 1411 | inline _LIBCPP_INLINE_VISIBILITY |
| 1412 | bool create_directory(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1413 | return __create_directory(__p, &__ec); |
| 1414 | } |
| 1415 | |
| 1416 | inline _LIBCPP_INLINE_VISIBILITY |
| 1417 | bool create_directory(const path& __p, const path& __attrs) { |
| 1418 | return __create_directory(__p, __attrs); |
| 1419 | } |
| 1420 | |
| 1421 | inline _LIBCPP_INLINE_VISIBILITY |
| 1422 | bool create_directory(const path& __p, const path& __attrs, error_code& __ec) _NOEXCEPT { |
| 1423 | return __create_directory(__p, __attrs, &__ec); |
| 1424 | } |
| 1425 | |
| 1426 | inline _LIBCPP_INLINE_VISIBILITY |
| 1427 | void create_directory_symlink(const path& __to, const path& __new) { |
| 1428 | __create_directory_symlink(__to, __new); |
| 1429 | } |
| 1430 | |
| 1431 | inline _LIBCPP_INLINE_VISIBILITY |
| 1432 | void create_directory_symlink(const path& __to, const path& __new, |
| 1433 | error_code& __ec) _NOEXCEPT { |
| 1434 | __create_directory_symlink(__to, __new, &__ec); |
| 1435 | } |
| 1436 | |
| 1437 | inline _LIBCPP_INLINE_VISIBILITY |
| 1438 | void create_hard_link(const path& __to, const path& __new) { |
| 1439 | __create_hard_link(__to, __new); |
| 1440 | } |
| 1441 | |
| 1442 | inline _LIBCPP_INLINE_VISIBILITY |
| 1443 | void create_hard_link(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT { |
| 1444 | __create_hard_link(__to, __new, &__ec); |
| 1445 | } |
| 1446 | |
| 1447 | inline _LIBCPP_INLINE_VISIBILITY |
| 1448 | void create_symlink(const path& __to, const path& __new) { |
| 1449 | __create_symlink(__to, __new); |
| 1450 | } |
| 1451 | |
| 1452 | inline _LIBCPP_INLINE_VISIBILITY |
| 1453 | void create_symlink(const path& __to, const path& __new, error_code& __ec) _NOEXCEPT { |
| 1454 | return __create_symlink(__to, __new, &__ec); |
| 1455 | } |
| 1456 | |
| 1457 | inline _LIBCPP_INLINE_VISIBILITY |
| 1458 | bool status_known(file_status __s) _NOEXCEPT { |
| 1459 | return __s.type() != file_type::none; |
| 1460 | } |
| 1461 | |
| 1462 | inline _LIBCPP_INLINE_VISIBILITY |
| 1463 | bool exists(file_status __s) _NOEXCEPT { |
| 1464 | return status_known(__s) && __s.type() != file_type::not_found; |
| 1465 | } |
| 1466 | |
| 1467 | inline _LIBCPP_INLINE_VISIBILITY |
| 1468 | bool exists(const path& __p) { |
| 1469 | return exists(__status(__p)); |
| 1470 | } |
| 1471 | |
| 1472 | inline _LIBCPP_INLINE_VISIBILITY |
| 1473 | bool exists(const path& __p, error_code& __ec) _NOEXCEPT { |
Eric Fiselier | 756a6bd | 2016-06-21 22:11:16 +0000 | [diff] [blame] | 1474 | auto __s = __status(__p, &__ec); |
| 1475 | if (status_known(__s)) __ec.clear(); |
| 1476 | return exists(__s); |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | inline _LIBCPP_INLINE_VISIBILITY |
| 1480 | bool equivalent(const path& __p1, const path& __p2) { |
| 1481 | return __equivalent(__p1, __p2); |
| 1482 | } |
| 1483 | |
| 1484 | inline _LIBCPP_INLINE_VISIBILITY |
| 1485 | bool equivalent(const path& __p1, const path& __p2, error_code& __ec) _NOEXCEPT { |
| 1486 | return __equivalent(__p1, __p2, &__ec); |
| 1487 | } |
| 1488 | |
| 1489 | inline _LIBCPP_INLINE_VISIBILITY |
| 1490 | uintmax_t file_size(const path& __p) { |
| 1491 | return __file_size(__p); |
| 1492 | } |
| 1493 | |
| 1494 | inline _LIBCPP_INLINE_VISIBILITY |
| 1495 | uintmax_t file_size(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1496 | return __file_size(__p, &__ec); |
| 1497 | } |
| 1498 | |
| 1499 | inline _LIBCPP_INLINE_VISIBILITY |
| 1500 | uintmax_t hard_link_count(const path& __p) { |
| 1501 | return __hard_link_count(__p); |
| 1502 | } |
| 1503 | |
| 1504 | inline _LIBCPP_INLINE_VISIBILITY |
| 1505 | uintmax_t hard_link_count(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1506 | return __hard_link_count(__p, &__ec); |
| 1507 | } |
| 1508 | |
| 1509 | inline _LIBCPP_INLINE_VISIBILITY |
| 1510 | bool is_block_file(file_status __s) _NOEXCEPT { |
| 1511 | return __s.type() == file_type::block; |
| 1512 | } |
| 1513 | |
| 1514 | inline _LIBCPP_INLINE_VISIBILITY |
| 1515 | bool is_block_file(const path& __p) { |
| 1516 | return is_block_file(__status(__p)); |
| 1517 | } |
| 1518 | |
| 1519 | inline _LIBCPP_INLINE_VISIBILITY |
| 1520 | bool is_block_file(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1521 | return is_block_file(__status(__p, &__ec)); |
| 1522 | } |
| 1523 | |
| 1524 | inline _LIBCPP_INLINE_VISIBILITY |
| 1525 | bool is_character_file(file_status __s) _NOEXCEPT { |
| 1526 | return __s.type() == file_type::character; |
| 1527 | } |
| 1528 | |
| 1529 | inline _LIBCPP_INLINE_VISIBILITY |
| 1530 | bool is_character_file(const path& __p) { |
| 1531 | return is_character_file(__status(__p)); |
| 1532 | } |
| 1533 | |
| 1534 | inline _LIBCPP_INLINE_VISIBILITY |
| 1535 | bool is_character_file(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1536 | return is_character_file(__status(__p, &__ec)); |
| 1537 | } |
| 1538 | |
| 1539 | inline _LIBCPP_INLINE_VISIBILITY |
| 1540 | bool is_directory(file_status __s) _NOEXCEPT { |
| 1541 | return __s.type() == file_type::directory; |
| 1542 | } |
| 1543 | |
| 1544 | inline _LIBCPP_INLINE_VISIBILITY |
| 1545 | bool is_directory(const path& __p) { |
| 1546 | return is_directory(__status(__p)); |
| 1547 | } |
| 1548 | |
| 1549 | inline _LIBCPP_INLINE_VISIBILITY |
| 1550 | bool is_directory(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1551 | return is_directory(__status(__p, &__ec)); |
| 1552 | } |
| 1553 | |
| 1554 | inline _LIBCPP_INLINE_VISIBILITY |
| 1555 | bool is_empty(const path& __p) { |
| 1556 | return __fs_is_empty(__p); |
| 1557 | } |
| 1558 | |
| 1559 | inline _LIBCPP_INLINE_VISIBILITY |
| 1560 | bool is_empty(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1561 | return __fs_is_empty(__p, &__ec); |
| 1562 | } |
| 1563 | |
| 1564 | inline _LIBCPP_INLINE_VISIBILITY |
| 1565 | bool is_fifo(file_status __s) _NOEXCEPT { |
| 1566 | return __s.type() == file_type::fifo; |
| 1567 | } |
| 1568 | inline _LIBCPP_INLINE_VISIBILITY |
| 1569 | bool is_fifo(const path& __p) { |
| 1570 | return is_fifo(__status(__p)); |
| 1571 | } |
| 1572 | |
| 1573 | inline _LIBCPP_INLINE_VISIBILITY |
| 1574 | bool is_fifo(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1575 | return is_fifo(__status(__p, &__ec)); |
| 1576 | } |
| 1577 | |
| 1578 | inline _LIBCPP_INLINE_VISIBILITY |
| 1579 | bool is_regular_file(file_status __s) _NOEXCEPT { |
| 1580 | return __s.type() == file_type::regular; |
| 1581 | } |
| 1582 | |
| 1583 | inline _LIBCPP_INLINE_VISIBILITY |
| 1584 | bool is_regular_file(const path& __p) { |
| 1585 | return is_regular_file(__status(__p)); |
| 1586 | } |
| 1587 | |
| 1588 | inline _LIBCPP_INLINE_VISIBILITY |
| 1589 | bool is_regular_file(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1590 | return is_regular_file(__status(__p, &__ec)); |
| 1591 | } |
| 1592 | |
| 1593 | inline _LIBCPP_INLINE_VISIBILITY |
| 1594 | bool is_socket(file_status __s) _NOEXCEPT { |
| 1595 | return __s.type() == file_type::socket; |
| 1596 | } |
| 1597 | |
| 1598 | inline _LIBCPP_INLINE_VISIBILITY |
| 1599 | bool is_socket(const path& __p) { |
| 1600 | return is_socket(__status(__p)); |
| 1601 | } |
| 1602 | |
| 1603 | inline _LIBCPP_INLINE_VISIBILITY |
| 1604 | bool is_socket(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1605 | return is_socket(__status(__p, &__ec)); |
| 1606 | } |
| 1607 | |
| 1608 | inline _LIBCPP_INLINE_VISIBILITY |
| 1609 | bool is_symlink(file_status __s) _NOEXCEPT { |
| 1610 | return __s.type() == file_type::symlink; |
| 1611 | } |
| 1612 | |
| 1613 | inline _LIBCPP_INLINE_VISIBILITY |
| 1614 | bool is_symlink(const path& __p) { |
| 1615 | return is_symlink(__symlink_status(__p)); |
| 1616 | } |
| 1617 | |
| 1618 | inline _LIBCPP_INLINE_VISIBILITY |
| 1619 | bool is_symlink(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1620 | return is_symlink(__symlink_status(__p, &__ec)); |
| 1621 | } |
| 1622 | |
| 1623 | inline _LIBCPP_INLINE_VISIBILITY |
| 1624 | bool is_other(file_status __s) _NOEXCEPT { |
| 1625 | return exists(__s) |
| 1626 | && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s); |
| 1627 | } |
| 1628 | |
| 1629 | inline _LIBCPP_INLINE_VISIBILITY |
| 1630 | bool is_other(const path& __p) { |
| 1631 | return is_other(__status(__p)); |
| 1632 | } |
| 1633 | |
| 1634 | inline _LIBCPP_INLINE_VISIBILITY |
| 1635 | bool is_other(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1636 | return is_other(__status(__p, &__ec)); |
| 1637 | } |
| 1638 | |
| 1639 | inline _LIBCPP_INLINE_VISIBILITY |
| 1640 | file_time_type last_write_time(const path& __p) { |
| 1641 | return __last_write_time(__p); |
| 1642 | } |
| 1643 | |
| 1644 | inline _LIBCPP_INLINE_VISIBILITY |
| 1645 | file_time_type last_write_time(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1646 | return __last_write_time(__p, &__ec); |
| 1647 | } |
| 1648 | |
| 1649 | inline _LIBCPP_INLINE_VISIBILITY |
| 1650 | void last_write_time(const path& __p, file_time_type __t) { |
| 1651 | __last_write_time(__p, __t); |
| 1652 | } |
| 1653 | |
| 1654 | inline _LIBCPP_INLINE_VISIBILITY |
| 1655 | void last_write_time(const path& __p, file_time_type __t, error_code& __ec) _NOEXCEPT { |
| 1656 | __last_write_time(__p, __t, &__ec); |
| 1657 | } |
| 1658 | |
| 1659 | inline _LIBCPP_INLINE_VISIBILITY |
| 1660 | void permissions(const path& __p, perms __prms) { |
| 1661 | __permissions(__p, __prms); |
| 1662 | } |
| 1663 | |
| 1664 | inline _LIBCPP_INLINE_VISIBILITY |
| 1665 | void permissions(const path& __p, perms __prms, error_code& __ec) { |
| 1666 | __permissions(__p, __prms, &__ec); |
| 1667 | } |
| 1668 | |
| 1669 | inline _LIBCPP_INLINE_VISIBILITY |
| 1670 | path read_symlink(const path& __p) { |
| 1671 | return __read_symlink(__p); |
| 1672 | } |
| 1673 | |
| 1674 | inline _LIBCPP_INLINE_VISIBILITY |
| 1675 | path read_symlink(const path& __p, error_code& __ec) { |
| 1676 | return __read_symlink(__p, &__ec); |
| 1677 | } |
| 1678 | |
| 1679 | inline _LIBCPP_INLINE_VISIBILITY |
| 1680 | bool remove(const path& __p) { |
| 1681 | return __remove(__p); |
| 1682 | } |
| 1683 | |
| 1684 | inline _LIBCPP_INLINE_VISIBILITY |
| 1685 | bool remove(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1686 | return __remove(__p, &__ec); |
| 1687 | } |
| 1688 | |
| 1689 | inline _LIBCPP_INLINE_VISIBILITY |
| 1690 | uintmax_t remove_all(const path& __p) { |
| 1691 | return __remove_all(__p); |
| 1692 | } |
| 1693 | |
| 1694 | inline _LIBCPP_INLINE_VISIBILITY |
| 1695 | uintmax_t remove_all(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1696 | return __remove_all(__p, &__ec); |
| 1697 | } |
| 1698 | |
| 1699 | inline _LIBCPP_INLINE_VISIBILITY |
| 1700 | void rename(const path& __from, const path& __to) { |
| 1701 | return __rename(__from, __to); |
| 1702 | } |
| 1703 | |
| 1704 | inline _LIBCPP_INLINE_VISIBILITY |
| 1705 | void rename(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { |
| 1706 | return __rename(__from, __to, &__ec); |
| 1707 | } |
| 1708 | |
| 1709 | inline _LIBCPP_INLINE_VISIBILITY |
| 1710 | void resize_file(const path& __p, uintmax_t __ns) { |
| 1711 | return __resize_file(__p, __ns); |
| 1712 | } |
| 1713 | |
| 1714 | inline _LIBCPP_INLINE_VISIBILITY |
| 1715 | void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) _NOEXCEPT { |
| 1716 | return __resize_file(__p, __ns, &__ec); |
| 1717 | } |
| 1718 | |
| 1719 | inline _LIBCPP_INLINE_VISIBILITY |
| 1720 | space_info space(const path& __p) { |
| 1721 | return __space(__p); |
| 1722 | } |
| 1723 | |
| 1724 | inline _LIBCPP_INLINE_VISIBILITY |
| 1725 | space_info space(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1726 | return __space(__p, &__ec); |
| 1727 | } |
| 1728 | |
| 1729 | inline _LIBCPP_INLINE_VISIBILITY |
| 1730 | file_status status(const path& __p) { |
| 1731 | return __status(__p); |
| 1732 | } |
| 1733 | |
| 1734 | inline _LIBCPP_INLINE_VISIBILITY |
| 1735 | file_status status(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1736 | return __status(__p, &__ec); |
| 1737 | } |
| 1738 | |
| 1739 | inline _LIBCPP_INLINE_VISIBILITY |
| 1740 | file_status symlink_status(const path& __p) { |
| 1741 | return __symlink_status(__p); |
| 1742 | } |
| 1743 | |
| 1744 | inline _LIBCPP_INLINE_VISIBILITY |
| 1745 | file_status symlink_status(const path& __p, error_code& __ec) _NOEXCEPT { |
| 1746 | return __symlink_status(__p, &__ec); |
| 1747 | } |
| 1748 | |
| 1749 | inline _LIBCPP_INLINE_VISIBILITY |
| 1750 | path system_complete(const path& __p) { |
| 1751 | return __system_complete(__p); |
| 1752 | } |
| 1753 | |
| 1754 | inline _LIBCPP_INLINE_VISIBILITY |
| 1755 | path system_complete(const path& __p, error_code& __ec) { |
| 1756 | return __system_complete(__p, &__ec); |
| 1757 | } |
| 1758 | |
| 1759 | inline _LIBCPP_INLINE_VISIBILITY |
| 1760 | path temp_directory_path() { |
| 1761 | return __temp_directory_path(); |
| 1762 | } |
| 1763 | |
| 1764 | inline _LIBCPP_INLINE_VISIBILITY |
| 1765 | path temp_directory_path(error_code& __ec) { |
| 1766 | return __temp_directory_path(&__ec); |
| 1767 | } |
| 1768 | |
| 1769 | |
| 1770 | class directory_entry |
| 1771 | { |
| 1772 | typedef _VSTD_FS::path _Path; |
| 1773 | |
| 1774 | public: |
| 1775 | // constructors and destructors |
| 1776 | directory_entry() _NOEXCEPT = default; |
| 1777 | directory_entry(directory_entry const&) = default; |
| 1778 | directory_entry(directory_entry&&) _NOEXCEPT = default; |
| 1779 | |
| 1780 | _LIBCPP_INLINE_VISIBILITY |
| 1781 | explicit directory_entry(_Path const& __p) : __p_(__p) {} |
| 1782 | |
| 1783 | ~directory_entry() {} |
| 1784 | |
| 1785 | directory_entry& operator=(directory_entry const&) = default; |
| 1786 | directory_entry& operator=(directory_entry&&) _NOEXCEPT = default; |
| 1787 | |
| 1788 | _LIBCPP_INLINE_VISIBILITY |
| 1789 | void assign(_Path const& __p) { |
| 1790 | __p_ = __p; |
| 1791 | } |
| 1792 | |
| 1793 | _LIBCPP_INLINE_VISIBILITY |
| 1794 | void replace_filename(_Path const& __p) { |
| 1795 | __p_ = __p_.parent_path() / __p; |
| 1796 | } |
| 1797 | |
| 1798 | _LIBCPP_INLINE_VISIBILITY |
| 1799 | _Path const& path() const _NOEXCEPT { |
| 1800 | return __p_; |
| 1801 | } |
| 1802 | |
| 1803 | _LIBCPP_INLINE_VISIBILITY |
| 1804 | operator const _Path&() const _NOEXCEPT { |
| 1805 | return __p_; |
| 1806 | } |
| 1807 | |
| 1808 | _LIBCPP_INLINE_VISIBILITY |
| 1809 | file_status status() const { |
| 1810 | return _VSTD_FS::status(__p_); |
| 1811 | } |
| 1812 | |
| 1813 | _LIBCPP_INLINE_VISIBILITY |
| 1814 | file_status status(error_code& __ec) const _NOEXCEPT { |
| 1815 | return _VSTD_FS::status(__p_, __ec); |
| 1816 | } |
| 1817 | |
| 1818 | _LIBCPP_INLINE_VISIBILITY |
| 1819 | file_status symlink_status() const { |
| 1820 | return _VSTD_FS::symlink_status(__p_); |
| 1821 | } |
| 1822 | |
| 1823 | _LIBCPP_INLINE_VISIBILITY |
| 1824 | file_status symlink_status(error_code& __ec) const _NOEXCEPT { |
| 1825 | return _VSTD_FS::symlink_status(__p_, __ec); |
| 1826 | } |
| 1827 | |
| 1828 | _LIBCPP_INLINE_VISIBILITY |
| 1829 | bool operator< (directory_entry const& __rhs) const _NOEXCEPT { |
| 1830 | return __p_ < __rhs.__p_; |
| 1831 | } |
| 1832 | |
| 1833 | _LIBCPP_INLINE_VISIBILITY |
| 1834 | bool operator==(directory_entry const& __rhs) const _NOEXCEPT { |
| 1835 | return __p_ == __rhs.__p_; |
| 1836 | } |
| 1837 | |
| 1838 | _LIBCPP_INLINE_VISIBILITY |
| 1839 | bool operator!=(directory_entry const& __rhs) const _NOEXCEPT { |
| 1840 | return __p_ != __rhs.__p_; |
| 1841 | } |
| 1842 | |
| 1843 | _LIBCPP_INLINE_VISIBILITY |
| 1844 | bool operator<=(directory_entry const& __rhs) const _NOEXCEPT { |
| 1845 | return __p_ <= __rhs.__p_; |
| 1846 | } |
| 1847 | |
| 1848 | _LIBCPP_INLINE_VISIBILITY |
| 1849 | bool operator> (directory_entry const& __rhs) const _NOEXCEPT { |
| 1850 | return __p_ > __rhs.__p_; |
| 1851 | } |
| 1852 | |
| 1853 | _LIBCPP_INLINE_VISIBILITY |
| 1854 | bool operator>=(directory_entry const& __rhs) const _NOEXCEPT { |
| 1855 | return __p_ >= __rhs.__p_; |
| 1856 | } |
| 1857 | private: |
| 1858 | _Path __p_; |
| 1859 | }; |
| 1860 | |
| 1861 | |
| 1862 | class directory_iterator; |
| 1863 | class recursive_directory_iterator; |
| 1864 | class __dir_stream; |
| 1865 | |
| 1866 | class __dir_element_proxy { |
| 1867 | public: |
| 1868 | |
| 1869 | inline _LIBCPP_INLINE_VISIBILITY |
| 1870 | directory_entry operator*() { return _VSTD::move(__elem_); } |
| 1871 | |
| 1872 | private: |
| 1873 | friend class directory_iterator; |
| 1874 | friend class recursive_directory_iterator; |
| 1875 | explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {} |
| 1876 | __dir_element_proxy(__dir_element_proxy&& __o) : __elem_(_VSTD::move(__o.__elem_)) {} |
| 1877 | directory_entry __elem_; |
| 1878 | }; |
| 1879 | |
| 1880 | class directory_iterator |
| 1881 | { |
| 1882 | public: |
| 1883 | typedef directory_entry value_type; |
| 1884 | typedef ptrdiff_t difference_type; |
| 1885 | typedef value_type const* pointer; |
| 1886 | typedef value_type const& reference; |
| 1887 | typedef input_iterator_tag iterator_category; |
| 1888 | |
| 1889 | public: |
| 1890 | //ctor & dtor |
| 1891 | directory_iterator() _NOEXCEPT |
| 1892 | { } |
| 1893 | |
| 1894 | explicit directory_iterator(const path& __p) |
| 1895 | : directory_iterator(__p, nullptr) |
| 1896 | { } |
| 1897 | |
| 1898 | directory_iterator(const path& __p, directory_options __opts) |
| 1899 | : directory_iterator(__p, nullptr, __opts) |
| 1900 | { } |
| 1901 | |
| 1902 | directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT |
| 1903 | : directory_iterator(__p, &__ec) |
| 1904 | { } |
| 1905 | |
| 1906 | directory_iterator(const path& __p, directory_options __opts, |
| 1907 | error_code& __ec) _NOEXCEPT |
| 1908 | : directory_iterator(__p, &__ec, __opts) |
| 1909 | { } |
| 1910 | |
| 1911 | directory_iterator(const directory_iterator&) = default; |
| 1912 | directory_iterator(directory_iterator&&) = default; |
| 1913 | directory_iterator& operator=(const directory_iterator&) = default; |
| 1914 | |
| 1915 | directory_iterator& operator=(directory_iterator&& __o) _NOEXCEPT { |
| 1916 | // non-default implementation provided to support self-move assign. |
| 1917 | if (this != &__o) { |
| 1918 | __imp_ = _VSTD::move(__o.__imp_); |
| 1919 | } |
| 1920 | return *this; |
| 1921 | } |
| 1922 | |
| 1923 | ~directory_iterator() = default; |
| 1924 | |
| 1925 | const directory_entry& operator*() const { |
| 1926 | _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced"); |
| 1927 | return __deref(); |
| 1928 | } |
| 1929 | |
| 1930 | const directory_entry* operator->() const |
| 1931 | { return &**this; } |
| 1932 | |
| 1933 | directory_iterator& operator++() |
| 1934 | { return __increment(); } |
| 1935 | |
| 1936 | __dir_element_proxy operator++(int) { |
| 1937 | __dir_element_proxy __p(**this); |
| 1938 | __increment(); |
| 1939 | return __p; |
| 1940 | } |
| 1941 | |
| 1942 | directory_iterator& increment(error_code& __ec) _NOEXCEPT |
| 1943 | { return __increment(&__ec); } |
| 1944 | |
| 1945 | private: |
Eric Fiselier | 03f7d10 | 2016-09-16 00:07:16 +0000 | [diff] [blame] | 1946 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 1947 | friend bool operator==(const directory_iterator& __lhs, |
| 1948 | const directory_iterator& __rhs) _NOEXCEPT; |
| 1949 | |
| 1950 | // construct the dir_stream |
| 1951 | _LIBCPP_FUNC_VIS |
| 1952 | directory_iterator(const path&, error_code *, directory_options = directory_options::none); |
| 1953 | _LIBCPP_FUNC_VIS |
| 1954 | directory_iterator& __increment(error_code * __ec = nullptr); |
| 1955 | _LIBCPP_FUNC_VIS |
| 1956 | const directory_entry& __deref() const; |
| 1957 | |
| 1958 | private: |
| 1959 | shared_ptr<__dir_stream> __imp_; |
| 1960 | }; |
| 1961 | |
| 1962 | |
| 1963 | inline _LIBCPP_INLINE_VISIBILITY |
| 1964 | bool operator==(const directory_iterator& __lhs, |
| 1965 | const directory_iterator& __rhs) _NOEXCEPT { |
| 1966 | return __lhs.__imp_ == __rhs.__imp_; |
| 1967 | } |
| 1968 | |
| 1969 | inline _LIBCPP_INLINE_VISIBILITY |
| 1970 | bool operator!=(const directory_iterator& __lhs, |
| 1971 | const directory_iterator& __rhs) _NOEXCEPT { |
| 1972 | return !(__lhs == __rhs); |
| 1973 | } |
| 1974 | |
| 1975 | // enable directory_iterator range-based for statements |
| 1976 | inline _LIBCPP_INLINE_VISIBILITY |
| 1977 | directory_iterator begin(directory_iterator __iter) _NOEXCEPT { |
| 1978 | return __iter; |
| 1979 | } |
| 1980 | |
| 1981 | inline _LIBCPP_INLINE_VISIBILITY |
| 1982 | directory_iterator end(const directory_iterator&) _NOEXCEPT { |
| 1983 | return directory_iterator(); |
| 1984 | } |
| 1985 | |
| 1986 | class recursive_directory_iterator { |
| 1987 | public: |
| 1988 | using value_type = directory_entry; |
| 1989 | using difference_type = std::ptrdiff_t; |
| 1990 | using pointer = directory_entry const *; |
| 1991 | using reference = directory_entry const &; |
| 1992 | using iterator_category = std::input_iterator_tag; |
| 1993 | |
| 1994 | public: |
| 1995 | // constructors and destructor |
| 1996 | _LIBCPP_INLINE_VISIBILITY |
| 1997 | recursive_directory_iterator() _NOEXCEPT |
| 1998 | : __rec_(false) |
| 1999 | {} |
| 2000 | |
| 2001 | _LIBCPP_INLINE_VISIBILITY |
| 2002 | explicit recursive_directory_iterator(const path& __p, |
| 2003 | directory_options __xoptions = directory_options::none) |
| 2004 | : recursive_directory_iterator(__p, __xoptions, nullptr) |
| 2005 | { } |
| 2006 | |
| 2007 | _LIBCPP_INLINE_VISIBILITY |
| 2008 | recursive_directory_iterator(const path& __p, |
| 2009 | directory_options __xoptions, error_code& __ec) _NOEXCEPT |
| 2010 | : recursive_directory_iterator(__p, __xoptions, &__ec) |
| 2011 | { } |
| 2012 | |
| 2013 | _LIBCPP_INLINE_VISIBILITY |
| 2014 | recursive_directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT |
| 2015 | : recursive_directory_iterator(__p, directory_options::none, &__ec) |
| 2016 | { } |
| 2017 | |
| 2018 | recursive_directory_iterator(const recursive_directory_iterator&) = default; |
| 2019 | recursive_directory_iterator(recursive_directory_iterator&&) = default; |
| 2020 | |
| 2021 | recursive_directory_iterator & |
| 2022 | operator=(const recursive_directory_iterator&) = default; |
| 2023 | |
| 2024 | _LIBCPP_INLINE_VISIBILITY |
| 2025 | recursive_directory_iterator & |
| 2026 | operator=(recursive_directory_iterator&& __o) noexcept { |
| 2027 | // non-default implementation provided to support self-move assign. |
| 2028 | if (this != &__o) { |
| 2029 | __imp_ = _VSTD::move(__o.__imp_); |
| 2030 | __rec_ = __o.__rec_; |
| 2031 | } |
| 2032 | return *this; |
| 2033 | } |
| 2034 | |
| 2035 | ~recursive_directory_iterator() = default; |
| 2036 | |
| 2037 | _LIBCPP_INLINE_VISIBILITY |
| 2038 | const directory_entry& operator*() const |
| 2039 | { return __deref(); } |
| 2040 | |
| 2041 | _LIBCPP_INLINE_VISIBILITY |
| 2042 | const directory_entry* operator->() const |
| 2043 | { return &__deref(); } |
| 2044 | |
| 2045 | recursive_directory_iterator& operator++() |
| 2046 | { return __increment(); } |
| 2047 | |
| 2048 | _LIBCPP_INLINE_VISIBILITY |
| 2049 | __dir_element_proxy operator++(int) { |
| 2050 | __dir_element_proxy __p(**this); |
| 2051 | __increment(); |
| 2052 | return __p; |
| 2053 | } |
| 2054 | |
| 2055 | _LIBCPP_INLINE_VISIBILITY |
| 2056 | recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT |
| 2057 | { return __increment(&__ec); } |
| 2058 | |
| 2059 | _LIBCPP_FUNC_VIS directory_options options() const; |
| 2060 | _LIBCPP_FUNC_VIS int depth() const; |
| 2061 | |
| 2062 | _LIBCPP_INLINE_VISIBILITY |
| 2063 | void pop() { __pop(); } |
| 2064 | |
| 2065 | _LIBCPP_INLINE_VISIBILITY |
| 2066 | void pop(error_code& __ec) |
| 2067 | { __pop(&__ec); } |
| 2068 | |
| 2069 | _LIBCPP_INLINE_VISIBILITY |
| 2070 | bool recursion_pending() const |
| 2071 | { return __rec_; } |
| 2072 | |
| 2073 | _LIBCPP_INLINE_VISIBILITY |
| 2074 | void disable_recursion_pending() |
| 2075 | { __rec_ = false; } |
| 2076 | |
| 2077 | private: |
| 2078 | recursive_directory_iterator(const path& __p, directory_options __opt, |
| 2079 | error_code *__ec); |
| 2080 | |
| 2081 | _LIBCPP_FUNC_VIS |
| 2082 | const directory_entry& __deref() const; |
| 2083 | |
| 2084 | _LIBCPP_FUNC_VIS |
| 2085 | bool __try_recursion(error_code* __ec); |
| 2086 | |
| 2087 | _LIBCPP_FUNC_VIS |
| 2088 | void __advance(error_code* __ec=nullptr); |
| 2089 | |
| 2090 | _LIBCPP_FUNC_VIS |
| 2091 | recursive_directory_iterator& __increment(error_code *__ec=nullptr); |
| 2092 | |
| 2093 | _LIBCPP_FUNC_VIS |
| 2094 | void __pop(error_code* __ec=nullptr); |
| 2095 | |
Eric Fiselier | 03f7d10 | 2016-09-16 00:07:16 +0000 | [diff] [blame] | 2096 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 2097 | friend bool operator==(const recursive_directory_iterator&, |
| 2098 | const recursive_directory_iterator&) _NOEXCEPT; |
| 2099 | |
| 2100 | struct __shared_imp; |
| 2101 | shared_ptr<__shared_imp> __imp_; |
| 2102 | bool __rec_; |
| 2103 | }; // class recursive_directory_iterator |
| 2104 | |
| 2105 | |
Eric Fiselier | 03f7d10 | 2016-09-16 00:07:16 +0000 | [diff] [blame] | 2106 | inline _LIBCPP_INLINE_VISIBILITY |
| 2107 | bool operator==(const recursive_directory_iterator& __lhs, |
| 2108 | const recursive_directory_iterator& __rhs) _NOEXCEPT |
Eric Fiselier | 6e9a694 | 2016-06-17 19:46:40 +0000 | [diff] [blame] | 2109 | { |
| 2110 | return __lhs.__imp_ == __rhs.__imp_; |
| 2111 | } |
| 2112 | |
| 2113 | _LIBCPP_INLINE_VISIBILITY |
| 2114 | inline bool operator!=(const recursive_directory_iterator& __lhs, |
| 2115 | const recursive_directory_iterator& __rhs) _NOEXCEPT |
| 2116 | { |
| 2117 | return !(__lhs == __rhs); |
| 2118 | } |
| 2119 | // enable recursive_directory_iterator range-based for statements |
| 2120 | inline _LIBCPP_INLINE_VISIBILITY |
| 2121 | recursive_directory_iterator begin(recursive_directory_iterator __iter) _NOEXCEPT { |
| 2122 | return __iter; |
| 2123 | } |
| 2124 | |
| 2125 | inline _LIBCPP_INLINE_VISIBILITY |
| 2126 | recursive_directory_iterator end(const recursive_directory_iterator&) _NOEXCEPT { |
| 2127 | return recursive_directory_iterator(); |
| 2128 | } |
| 2129 | |
| 2130 | _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM |
| 2131 | |
| 2132 | #endif // _LIBCPP_EXPERIMENTAL_FILESYSTEM |