Update copyright years.
[official-gcc.git] / libstdc++-v3 / include / experimental / fs_dir.h
blob6f036abab29dd8d55252a5b93ed171a13094dbf1
1 // Filesystem directory utilities -*- C++ -*-
3 // Copyright (C) 2014-2015 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file experimental/fs_dir.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{experimental/filesystem}
30 #ifndef _GLIBCXX_EXPERIMENTAL_FS_DIR_H
31 #define _GLIBCXX_EXPERIMENTAL_FS_DIR_H 1
33 #if __cplusplus < 201103L
34 # include <bits/c++0x_warning.h>
35 #else
36 # include <typeinfo>
37 # include <ext/concurrence.h>
38 # include <bits/unique_ptr.h>
39 # include <bits/shared_ptr.h>
41 namespace std _GLIBCXX_VISIBILITY(default)
43 namespace experimental
45 namespace filesystem
47 inline namespace v1
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 /**
52 * @ingroup filesystem
53 * @{
56 class file_status
58 public:
59 // constructors
60 explicit
61 file_status(file_type __ft = file_type::none,
62 perms __prms = perms::unknown) noexcept
63 : _M_type(__ft), _M_perms(__prms) { }
65 file_status(const file_status&) noexcept = default;
66 file_status(file_status&&) noexcept = default;
67 ~file_status() = default;
69 file_status& operator=(const file_status&) noexcept = default;
70 file_status& operator=(file_status&&) noexcept = default;
72 // observers
73 file_type type() const noexcept { return _M_type; }
74 perms permissions() const noexcept { return _M_perms; }
76 // modifiers
77 void type(file_type __ft) noexcept { _M_type = __ft; }
78 void permissions(perms __prms) noexcept { _M_perms = __prms; }
80 private:
81 file_type _M_type;
82 perms _M_perms;
86 class directory_entry
88 public:
89 // constructors and destructor
90 directory_entry() noexcept = default;
91 directory_entry(const directory_entry&) = default;
92 directory_entry(directory_entry&&) noexcept = default;
93 explicit directory_entry(const filesystem::path& __p) : _M_path(__p) { }
94 ~directory_entry() = default;
96 // modifiers
97 directory_entry& operator=(const directory_entry&) = default;
98 directory_entry& operator=(directory_entry&&) noexcept = default;
100 void assign(const filesystem::path& __p) { _M_path = __p; }
102 void
103 replace_filename(const filesystem::path& __p)
104 { _M_path = _M_path.parent_path() / __p; }
106 // observers
107 const filesystem::path& path() const noexcept { return _M_path; }
108 operator const filesystem::path&() const noexcept { return _M_path; }
110 file_status
111 status() const
112 { return filesystem::status(_M_path); }
114 file_status
115 status(error_code& __ec) const noexcept
116 { return filesystem::status(_M_path, __ec); }
118 file_status
119 symlink_status() const
120 { return filesystem::symlink_status(_M_path); }
122 file_status
123 symlink_status(error_code& __ec) const noexcept
124 { return filesystem::symlink_status(_M_path, __ec); }
126 bool
127 operator< (const directory_entry& __rhs) const noexcept
128 { return _M_path < __rhs._M_path; }
130 bool
131 operator==(const directory_entry& __rhs) const noexcept
132 { return _M_path == __rhs._M_path; }
134 bool
135 operator!=(const directory_entry& __rhs) const noexcept
136 { return _M_path != __rhs._M_path; }
138 bool
139 operator<=(const directory_entry& __rhs) const noexcept
140 { return _M_path <= __rhs._M_path; }
142 bool
143 operator> (const directory_entry& __rhs) const noexcept
144 { return _M_path > __rhs._M_path; }
146 bool
147 operator>=(const directory_entry& __rhs) const noexcept
148 { return _M_path >= __rhs._M_path; }
150 private:
151 filesystem::path _M_path;
154 struct _Dir;
155 class recursive_directory_iterator;
157 class directory_iterator
159 public:
160 typedef directory_entry value_type;
161 typedef ptrdiff_t difference_type;
162 typedef const directory_entry* pointer;
163 typedef const directory_entry& reference;
164 typedef input_iterator_tag iterator_category;
166 directory_iterator() noexcept = default;
168 explicit
169 directory_iterator(const path& __p)
170 : directory_iterator(__p, directory_options::none, nullptr) { }
172 directory_iterator(const path& __p, directory_options __options)
173 : directory_iterator(__p, __options, nullptr) { }
175 directory_iterator(const path& __p, error_code& __ec) noexcept
176 : directory_iterator(__p, directory_options::none, __ec) { }
178 directory_iterator(const path& __p,
179 directory_options __options, error_code& __ec) noexcept
180 : directory_iterator(__p, __options, &__ec) { }
182 directory_iterator(const directory_iterator& rhs) = default;
184 directory_iterator(directory_iterator&& rhs) noexcept = default;
186 ~directory_iterator() = default;
188 directory_iterator& operator=(const directory_iterator& rhs) = default;
189 directory_iterator& operator=(directory_iterator&& rhs) noexcept = default;
191 const directory_entry& operator*() const;
192 const directory_entry* operator->() const { return &**this; }
193 directory_iterator& operator++();
194 directory_iterator& increment(error_code& __ec) noexcept;
196 directory_iterator operator++(int)
198 auto __tmp = *this;
199 ++*this;
200 return __tmp;
203 friend bool
204 operator==(const directory_iterator& __lhs,
205 const directory_iterator& __rhs)
206 { return __lhs._M_dir == __rhs._M_dir; }
208 private:
209 directory_iterator(const path&, directory_options, error_code*);
210 directory_iterator(std::shared_ptr<_Dir>, error_code*);
212 friend class recursive_directory_iterator;
214 std::shared_ptr<_Dir> _M_dir;
217 inline directory_iterator
218 begin(directory_iterator __iter) { return __iter; }
220 inline directory_iterator
221 end(directory_iterator) { return directory_iterator(); }
223 inline bool
224 operator!=(const directory_iterator& __lhs, const directory_iterator& __rhs)
225 { return !(__lhs == __rhs); }
227 class recursive_directory_iterator
229 public:
230 typedef directory_entry value_type;
231 typedef ptrdiff_t difference_type;
232 typedef const directory_entry* pointer;
233 typedef const directory_entry& reference;
234 typedef input_iterator_tag iterator_category;
236 recursive_directory_iterator() noexcept = default;
238 explicit
239 recursive_directory_iterator(const path& __p)
240 : recursive_directory_iterator(__p, directory_options::none, nullptr) { }
242 recursive_directory_iterator(const path& __p, directory_options __options)
243 : recursive_directory_iterator(__p, __options, nullptr) { }
245 recursive_directory_iterator(const path& __p,
246 directory_options __options,
247 error_code& __ec) noexcept
248 : recursive_directory_iterator(__p, __options, &__ec) { }
250 recursive_directory_iterator(const path& __p, error_code& __ec) noexcept
251 : recursive_directory_iterator(__p, directory_options::none, &__ec) { }
253 recursive_directory_iterator(
254 const recursive_directory_iterator&) = default;
256 recursive_directory_iterator(
257 recursive_directory_iterator&&) noexcept = default;
259 ~recursive_directory_iterator();
261 // observers
262 directory_options options() const { return _M_options; }
263 int depth() const;
264 bool recursion_pending() const { return _M_pending; }
266 const directory_entry& operator*() const;
267 const directory_entry* operator->() const { return &**this; }
269 // modifiers
270 recursive_directory_iterator&
271 operator=(const recursive_directory_iterator& rhs) noexcept;
272 recursive_directory_iterator&
273 operator=(recursive_directory_iterator&& rhs) noexcept;
275 recursive_directory_iterator& operator++();
276 recursive_directory_iterator& increment(error_code& __ec) noexcept;
278 recursive_directory_iterator operator++(int)
280 auto __tmp = *this;
281 ++*this;
282 return __tmp;
285 void pop();
287 void disable_recursion_pending() { _M_pending = false; }
289 friend bool
290 operator==(const recursive_directory_iterator& __lhs,
291 const recursive_directory_iterator& __rhs)
292 { return __lhs._M_dirs == __rhs._M_dirs; }
294 private:
295 recursive_directory_iterator(const path&, directory_options, error_code*);
297 struct _Dir_stack;
298 std::shared_ptr<_Dir_stack> _M_dirs;
299 directory_options _M_options;
300 bool _M_pending;
303 inline recursive_directory_iterator
304 begin(recursive_directory_iterator __iter) { return __iter; }
306 inline recursive_directory_iterator
307 end(recursive_directory_iterator) { return recursive_directory_iterator(); }
309 inline bool
310 operator!=(const recursive_directory_iterator& __lhs,
311 const recursive_directory_iterator& __rhs)
312 { return !(__lhs == __rhs); }
314 // @} group filesystem
315 _GLIBCXX_END_NAMESPACE_VERSION
316 } // namespace v1
317 } // namespace filesystem
318 } // namespace experimental
319 } // namespace std
321 #endif // C++11
323 #endif // _GLIBCXX_EXPERIMENTAL_FS_DIR_H