30 #ifndef _GLIBCXX_FS_DIR_H 31 #define _GLIBCXX_FS_DIR_H 1 33 #if __cplusplus >= 201703L 37 # include <bits/shared_ptr.h> 39 namespace std _GLIBCXX_VISIBILITY(default)
41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 file_status() noexcept : file_status(file_type::none) {}
57 file_status(file_type __ft,
perms __prms = perms::unknown) noexcept
58 : _M_type(__ft), _M_perms(__prms) { }
60 file_status(
const file_status&) noexcept =
default;
61 file_status(file_status&&) noexcept = default;
62 ~file_status() = default;
64 file_status& operator=(const file_status&) noexcept = default;
65 file_status& operator=(file_status&&) noexcept = default;
68 file_type type() const noexcept {
return _M_type; }
69 perms permissions() const noexcept {
return _M_perms; }
72 void type(file_type __ft) noexcept { _M_type = __ft; }
73 void permissions(
perms __prms) noexcept { _M_perms = __prms; }
80 _GLIBCXX_BEGIN_NAMESPACE_CXX11
83 class directory_iterator;
84 class recursive_directory_iterator;
90 directory_entry() noexcept = default;
91 directory_entry(const directory_entry&) = default;
92 directory_entry(directory_entry&&) noexcept = default;
95 directory_entry(const filesystem::path& __p)
99 directory_entry(
const filesystem::path& __p, error_code& __ec)
107 ~directory_entry() =
default;
110 directory_entry& operator=(
const directory_entry&) =
default;
111 directory_entry& operator=(directory_entry&&) noexcept = default;
114 assign(const filesystem::path& __p)
121 assign(
const filesystem::path& __p, error_code& __ec)
128 replace_filename(
const filesystem::path& __p)
130 _M_path.replace_filename(__p);
135 replace_filename(
const filesystem::path& __p, error_code& __ec)
137 _M_path.replace_filename(__p);
143 { _M_type = symlink_status().type(); }
146 refresh(error_code& __ec) noexcept
147 { _M_type = symlink_status(__ec).type(); }
150 const filesystem::path& path() const noexcept {
return _M_path; }
151 operator const filesystem::path& ()
const noexcept {
return _M_path; }
155 {
return filesystem::exists(file_status{_M_file_type()}); }
158 exists(error_code& __ec)
const noexcept
159 {
return filesystem::exists(file_status{_M_file_type(__ec)}); }
162 is_block_file()
const 163 {
return _M_file_type() == file_type::block; }
166 is_block_file(error_code& __ec)
const noexcept
167 {
return _M_file_type(__ec) == file_type::block; }
170 is_character_file()
const 171 {
return _M_file_type() == file_type::character; }
174 is_character_file(error_code& __ec)
const noexcept
175 {
return _M_file_type(__ec) == file_type::character; }
179 {
return _M_file_type() == file_type::directory; }
182 is_directory(error_code& __ec)
const noexcept
183 {
return _M_file_type(__ec) == file_type::directory; }
187 {
return _M_file_type() == file_type::fifo; }
190 is_fifo(error_code& __ec)
const noexcept
191 {
return _M_file_type(__ec) == file_type::fifo; }
195 {
return filesystem::is_other(file_status{_M_file_type()}); }
198 is_other(error_code& __ec)
const noexcept
199 {
return filesystem::is_other(file_status{_M_file_type(__ec)}); }
202 is_regular_file()
const 203 {
return _M_file_type() == file_type::regular; }
206 is_regular_file(error_code& __ec)
const noexcept
207 {
return _M_file_type(__ec) == file_type::regular; }
211 {
return _M_file_type() == file_type::socket; }
214 is_socket(error_code& __ec)
const noexcept
215 {
return _M_file_type(__ec) == file_type::socket; }
220 if (_M_type != file_type::none)
221 return _M_type == file_type::symlink;
222 return symlink_status().type() == file_type::symlink;
226 is_symlink(error_code& __ec)
const noexcept
228 if (_M_type != file_type::none)
229 return _M_type == file_type::symlink;
230 return symlink_status(__ec).type() == file_type::symlink;
235 {
return filesystem::file_size(_M_path); }
238 file_size(error_code& __ec)
const noexcept
239 {
return filesystem::file_size(_M_path, __ec); }
242 hard_link_count()
const 243 {
return filesystem::hard_link_count(_M_path); }
246 hard_link_count(error_code& __ec)
const noexcept
247 {
return filesystem::hard_link_count(_M_path, __ec); }
250 last_write_time()
const 251 {
return filesystem::last_write_time(_M_path); }
255 last_write_time(error_code& __ec)
const noexcept
256 {
return filesystem::last_write_time(_M_path, __ec); }
260 {
return filesystem::status(_M_path); }
263 status(error_code& __ec)
const noexcept
264 {
return filesystem::status(_M_path, __ec); }
267 symlink_status()
const 268 {
return filesystem::symlink_status(_M_path); }
271 symlink_status(error_code& __ec)
const noexcept
272 {
return filesystem::symlink_status(_M_path, __ec); }
275 operator< (
const directory_entry& __rhs)
const noexcept
276 {
return _M_path < __rhs._M_path; }
279 operator==(
const directory_entry& __rhs)
const noexcept
280 {
return _M_path == __rhs._M_path; }
283 operator!=(
const directory_entry& __rhs)
const noexcept
284 {
return _M_path != __rhs._M_path; }
287 operator<=(
const directory_entry& __rhs)
const noexcept
288 {
return _M_path <= __rhs._M_path; }
291 operator> (
const directory_entry& __rhs)
const noexcept
292 {
return _M_path > __rhs._M_path; }
295 operator>=(
const directory_entry& __rhs)
const noexcept
296 {
return _M_path >= __rhs._M_path; }
300 friend class directory_iterator;
301 friend class recursive_directory_iterator;
305 template<
typename _CharT,
typename _Traits>
306 friend basic_ostream<_CharT, _Traits>&
307 operator<<(basic_ostream<_CharT, _Traits>& __os,
308 const directory_entry& __d)
309 {
return __os << __d.path(); }
311 directory_entry(
const filesystem::path& __p, file_type __t)
312 : _M_path(__p), _M_type(__t)
319 if (_M_type != file_type::none && _M_type != file_type::symlink)
321 return status().type();
326 _M_file_type(error_code& __ec)
const noexcept
328 if (_M_type != file_type::none && _M_type != file_type::symlink)
333 return status(__ec).type();
336 filesystem::path _M_path;
337 file_type _M_type = file_type::none;
340 struct __directory_iterator_proxy
342 const directory_entry&
operator*() const& noexcept {
return _M_entry; }
344 directory_entry
operator*() && noexcept {
return std::move(_M_entry); }
347 friend class directory_iterator;
348 friend class recursive_directory_iterator;
351 __directory_iterator_proxy(
const directory_entry& __e) : _M_entry(__e) { }
353 directory_entry _M_entry;
356 class directory_iterator
359 typedef directory_entry value_type;
360 typedef ptrdiff_t difference_type;
361 typedef const directory_entry* pointer;
362 typedef const directory_entry& reference;
363 typedef input_iterator_tag iterator_category;
365 directory_iterator() =
default;
368 directory_iterator(
const path& __p)
369 : directory_iterator(__p, directory_options::none, nullptr) { }
371 directory_iterator(
const path& __p, directory_options __options)
372 : directory_iterator(__p, __options, nullptr) { }
374 directory_iterator(
const path& __p, error_code& __ec)
375 : directory_iterator(__p, directory_options::none, __ec) { }
377 directory_iterator(
const path& __p, directory_options __options,
379 : directory_iterator(__p, __options, &__ec) { }
381 directory_iterator(
const directory_iterator& __rhs) =
default;
383 directory_iterator(directory_iterator&& __rhs) noexcept =
default;
385 ~directory_iterator() =
default;
388 operator=(
const directory_iterator& __rhs) =
default;
391 operator=(directory_iterator&& __rhs) noexcept =
default;
393 const directory_entry&
operator*() const noexcept;
394 const directory_entry* operator->() const noexcept {
return &**
this; }
395 directory_iterator& operator++();
396 directory_iterator& increment(error_code& __ec);
398 __directory_iterator_proxy operator++(
int)
400 __directory_iterator_proxy __pr{**
this};
406 directory_iterator(
const path&, directory_options, error_code*);
409 operator==(
const directory_iterator& __lhs,
410 const directory_iterator& __rhs) noexcept
412 return !__rhs._M_dir.owner_before(__lhs._M_dir)
413 && !__lhs._M_dir.owner_before(__rhs._M_dir);
417 operator!=(
const directory_iterator& __lhs,
418 const directory_iterator& __rhs) noexcept
419 {
return !(__lhs == __rhs); }
421 friend class recursive_directory_iterator;
423 std::__shared_ptr<_Dir> _M_dir;
426 inline directory_iterator
427 begin(directory_iterator __iter) noexcept
430 inline directory_iterator
431 end(directory_iterator) noexcept
432 {
return directory_iterator(); }
434 class recursive_directory_iterator
437 typedef directory_entry value_type;
438 typedef ptrdiff_t difference_type;
439 typedef const directory_entry* pointer;
440 typedef const directory_entry& reference;
441 typedef input_iterator_tag iterator_category;
443 recursive_directory_iterator() =
default;
446 recursive_directory_iterator(
const path& __p)
447 : recursive_directory_iterator(__p, directory_options::none, nullptr) { }
449 recursive_directory_iterator(
const path& __p, directory_options __options)
450 : recursive_directory_iterator(__p, __options, nullptr) { }
452 recursive_directory_iterator(
const path& __p, directory_options __options,
454 : recursive_directory_iterator(__p, __options, &__ec) { }
456 recursive_directory_iterator(
const path& __p, error_code& __ec)
457 : recursive_directory_iterator(__p, directory_options::none, &__ec) { }
459 recursive_directory_iterator(
460 const recursive_directory_iterator&) =
default;
462 recursive_directory_iterator(recursive_directory_iterator&&) =
default;
464 ~recursive_directory_iterator();
467 directory_options options() const noexcept;
468 int depth() const noexcept;
469 bool recursion_pending() const noexcept;
471 const directory_entry& operator*() const noexcept;
472 const directory_entry* operator->() const noexcept {
return &**
this; }
475 recursive_directory_iterator&
476 operator=(
const recursive_directory_iterator& __rhs) noexcept;
477 recursive_directory_iterator&
478 operator=(recursive_directory_iterator&& __rhs) noexcept;
480 recursive_directory_iterator& operator++();
481 recursive_directory_iterator& increment(error_code& __ec);
483 __directory_iterator_proxy operator++(
int)
485 __directory_iterator_proxy __pr{**
this};
491 void pop(error_code&);
493 void disable_recursion_pending() noexcept;
496 recursive_directory_iterator(const path&, directory_options, error_code*);
499 operator==(const recursive_directory_iterator& __lhs,
500 const recursive_directory_iterator& __rhs) noexcept
502 return !__rhs._M_dirs.owner_before(__lhs._M_dirs)
503 && !__lhs._M_dirs.owner_before(__rhs._M_dirs);
507 operator!=(
const recursive_directory_iterator& __lhs,
508 const recursive_directory_iterator& __rhs) noexcept
509 {
return !(__lhs == __rhs); }
512 std::__shared_ptr<_Dir_stack> _M_dirs;
515 inline recursive_directory_iterator
516 begin(recursive_directory_iterator __iter) noexcept
519 inline recursive_directory_iterator
520 end(recursive_directory_iterator) noexcept
521 {
return recursive_directory_iterator(); }
523 _GLIBCXX_END_NAMESPACE_CXX11
531 extern template class 532 __shared_ptr<filesystem::_Dir>;
533 extern template class 534 __shared_ptr<filesystem::recursive_directory_iterator::_Dir_stack>;
536 _GLIBCXX_END_NAMESPACE_VERSION
541 #endif // _GLIBCXX_FS_DIR_H constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
_GLIBCXX20_CONSTEXPR complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
ISO C++ entities toplevel namespace is std.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.