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