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;
303 directory_entry(
const filesystem::path& __p, file_type __t)
304 : _M_path(__p), _M_type(__t)
311 if (_M_type != file_type::none && _M_type != file_type::symlink)
313 return status().type();
318 _M_file_type(error_code& __ec)
const noexcept
320 if (_M_type != file_type::none && _M_type != file_type::symlink)
325 return status(__ec).type();
328 filesystem::path _M_path;
329 file_type _M_type = file_type::none;
332 struct __directory_iterator_proxy
334 const directory_entry&
operator*() const& noexcept {
return _M_entry; }
336 directory_entry
operator*() && noexcept {
return std::move(_M_entry); }
339 friend class directory_iterator;
340 friend class recursive_directory_iterator;
343 __directory_iterator_proxy(
const directory_entry& __e) : _M_entry(__e) { }
345 directory_entry _M_entry;
348 class directory_iterator
351 typedef directory_entry value_type;
352 typedef ptrdiff_t difference_type;
353 typedef const directory_entry* pointer;
354 typedef const directory_entry& reference;
355 typedef input_iterator_tag iterator_category;
357 directory_iterator() =
default;
360 directory_iterator(
const path& __p)
361 : directory_iterator(__p, directory_options::none, nullptr) { }
363 directory_iterator(
const path& __p, directory_options __options)
364 : directory_iterator(__p, __options, nullptr) { }
366 directory_iterator(
const path& __p, error_code& __ec)
367 : directory_iterator(__p, directory_options::none, __ec) { }
369 directory_iterator(
const path& __p, directory_options __options,
371 : directory_iterator(__p, __options, &__ec) { }
373 directory_iterator(
const directory_iterator& __rhs) =
default;
375 directory_iterator(directory_iterator&& __rhs) noexcept =
default;
377 ~directory_iterator() =
default;
380 operator=(
const directory_iterator& __rhs) =
default;
383 operator=(directory_iterator&& __rhs) noexcept =
default;
385 const directory_entry&
operator*()
const;
386 const directory_entry* operator->()
const {
return &**
this; }
387 directory_iterator& operator++();
388 directory_iterator& increment(error_code& __ec);
390 __directory_iterator_proxy operator++(
int)
392 __directory_iterator_proxy __pr{**
this};
398 directory_iterator(
const path&, directory_options, error_code*);
401 operator==(
const directory_iterator& __lhs,
402 const directory_iterator& __rhs);
404 friend class recursive_directory_iterator;
409 inline directory_iterator
410 begin(directory_iterator __iter) noexcept
413 inline directory_iterator
414 end(directory_iterator) noexcept
415 {
return directory_iterator(); }
418 operator==(
const directory_iterator& __lhs,
const directory_iterator& __rhs)
420 return !__rhs._M_dir.owner_before(__lhs._M_dir)
421 && !__lhs._M_dir.owner_before(__rhs._M_dir);
425 operator!=(
const directory_iterator& __lhs,
const directory_iterator& __rhs)
426 {
return !(__lhs == __rhs); }
428 class recursive_directory_iterator
431 typedef directory_entry value_type;
432 typedef ptrdiff_t difference_type;
433 typedef const directory_entry* pointer;
434 typedef const directory_entry& reference;
435 typedef input_iterator_tag iterator_category;
437 recursive_directory_iterator() =
default;
440 recursive_directory_iterator(
const path& __p)
441 : recursive_directory_iterator(__p, directory_options::none, nullptr) { }
443 recursive_directory_iterator(
const path& __p, directory_options __options)
444 : recursive_directory_iterator(__p, __options, nullptr) { }
446 recursive_directory_iterator(
const path& __p, directory_options __options,
448 : recursive_directory_iterator(__p, __options, &__ec) { }
450 recursive_directory_iterator(
const path& __p, error_code& __ec)
451 : recursive_directory_iterator(__p, directory_options::none, &__ec) { }
453 recursive_directory_iterator(
454 const recursive_directory_iterator&) =
default;
456 recursive_directory_iterator(recursive_directory_iterator&&) =
default;
458 ~recursive_directory_iterator();
461 directory_options options()
const {
return _M_options; }
463 bool recursion_pending()
const {
return _M_pending; }
465 const directory_entry&
operator*()
const;
466 const directory_entry* operator->()
const {
return &**
this; }
469 recursive_directory_iterator&
470 operator=(
const recursive_directory_iterator& __rhs) noexcept;
471 recursive_directory_iterator&
472 operator=(recursive_directory_iterator&& __rhs) noexcept;
474 recursive_directory_iterator& operator++();
475 recursive_directory_iterator& increment(error_code& __ec);
477 __directory_iterator_proxy operator++(
int)
479 __directory_iterator_proxy __pr{**
this};
485 void pop(error_code&);
487 void disable_recursion_pending() { _M_pending =
false; }
490 recursive_directory_iterator(
const path&, directory_options, error_code*);
493 operator==(
const recursive_directory_iterator& __lhs,
494 const recursive_directory_iterator& __rhs);
498 directory_options _M_options = {};
499 bool _M_pending =
false;
502 inline recursive_directory_iterator
503 begin(recursive_directory_iterator __iter) noexcept
506 inline recursive_directory_iterator
507 end(recursive_directory_iterator) noexcept
508 {
return recursive_directory_iterator(); }
511 operator==(
const recursive_directory_iterator& __lhs,
512 const recursive_directory_iterator& __rhs)
514 return !__rhs._M_dirs.owner_before(__lhs._M_dirs)
515 && !__lhs._M_dirs.owner_before(__rhs._M_dirs);
519 operator!=(
const recursive_directory_iterator& __lhs,
520 const recursive_directory_iterator& __rhs)
521 {
return !(__lhs == __rhs); }
523 _GLIBCXX_END_NAMESPACE_CXX11
528 _GLIBCXX_END_NAMESPACE_VERSION
533 #endif // _GLIBCXX_FS_DIR_H
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 * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.