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