From Jason Turner

[fs.class.directory_entry]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmajko70i/{from.md → to.md} +0 -367
tmp/tmpmajko70i/{from.md → to.md} RENAMED
@@ -1,367 +0,0 @@
1
- ### Class `directory_entry` <a id="fs.class.directory_entry">[[fs.class.directory_entry]]</a>
2
-
3
- ``` cpp
4
- namespace std::filesystem {
5
- class directory_entry {
6
- public:
7
- // [fs.dir.entry.cons], constructors and destructor
8
- directory_entry() noexcept = default;
9
- directory_entry(const directory_entry&) = default;
10
- directory_entry(directory_entry&&) noexcept = default;
11
- explicit directory_entry(const path& p);
12
- directory_entry(const path& p, error_code& ec);
13
- ~directory_entry();
14
-
15
- // assignments:
16
- directory_entry& operator=(const directory_entry&) = default;
17
- directory_entry& operator=(directory_entry&&) noexcept = default;
18
-
19
- // [fs.dir.entry.mods], modifiers
20
- void assign(const path& p);
21
- void assign(const path& p, error_code& ec);
22
- void replace_filename(const path& p);
23
- void replace_filename(const path& p, error_code& ec);
24
- void refresh();
25
- void refresh(error_code& ec) noexcept;
26
-
27
- // [fs.dir.entry.obs], observers
28
- const path& path() const noexcept;
29
- operator const path&() const noexcept;
30
- bool exists() const;
31
- bool exists(error_code& ec) const noexcept;
32
- bool is_block_file() const;
33
- bool is_block_file(error_code& ec) const noexcept;
34
- bool is_character_file() const;
35
- bool is_character_file(error_code& ec) const noexcept;
36
- bool is_directory() const;
37
- bool is_directory(error_code& ec) const noexcept;
38
- bool is_fifo() const;
39
- bool is_fifo(error_code& ec) const noexcept;
40
- bool is_other() const;
41
- bool is_other(error_code& ec) const noexcept;
42
- bool is_regular_file() const;
43
- bool is_regular_file(error_code& ec) const noexcept;
44
- bool is_socket() const;
45
- bool is_socket(error_code& ec) const noexcept;
46
- bool is_symlink() const;
47
- bool is_symlink(error_code& ec) const noexcept;
48
- uintmax_t file_size() const;
49
- uintmax_t file_size(error_code& ec) const noexcept;
50
- uintmax_t hard_link_count() const;
51
- uintmax_t hard_link_count(error_code& ec) const noexcept;
52
- file_time_type last_write_time() const;
53
- file_time_type last_write_time(error_code& ec) const noexcept;
54
- file_status status() const;
55
- file_status status(error_code& ec) const noexcept;
56
- file_status symlink_status() const;
57
- file_status symlink_status(error_code& ec) const noexcept;
58
-
59
- bool operator< (const directory_entry& rhs) const noexcept;
60
- bool operator==(const directory_entry& rhs) const noexcept;
61
- bool operator!=(const directory_entry& rhs) const noexcept;
62
- bool operator<=(const directory_entry& rhs) const noexcept;
63
- bool operator> (const directory_entry& rhs) const noexcept;
64
- bool operator>=(const directory_entry& rhs) const noexcept;
65
-
66
- private:
67
- path pathobject; // exposition only
68
- friend class directory_iterator; // exposition only
69
- };
70
- }
71
- ```
72
-
73
- A `directory_entry` object stores a `path` object and may store
74
- additional objects for file attributes such as hard link count, status,
75
- symlink status, file size, and last write time.
76
-
77
- Implementations are encouraged to store such additional file attributes
78
- during directory iteration if their values are available and storing the
79
- values would allow the implementation to eliminate file system accesses
80
- by `directory_entry` observer functions ([[fs.op.funcs]]). Such stored
81
- file attribute values are said to be *cached*.
82
-
83
- [*Note 1*: For purposes of exposition, class `directory_iterator` (
84
- [[fs.class.directory_iterator]]) is shown above as a friend of class
85
- `directory_entry`. Friendship allows the `directory_iterator`
86
- implementation to cache already available attribute values directly into
87
- a `directory_entry` object without the cost of an unneeded call to
88
- `refresh()`. — *end note*]
89
-
90
- [*Example 1*:
91
-
92
- ``` cpp
93
- using namespace std::filesystem;
94
-
95
- // use possibly cached last write time to minimize disk accesses
96
- for (auto&& x : directory_iterator("."))
97
- {
98
- std::cout << x.path() << " " << x.last_write_time() << std::endl;
99
- }
100
-
101
- // call refresh() to refresh a stale cache
102
- for (auto&& x : directory_iterator("."))
103
- {
104
- lengthy_function(x.path()); // cache becomes stale
105
- x.refresh();
106
- std::cout << x.path() << " " << x.last_write_time() << std::endl;
107
- }
108
- ```
109
-
110
- On implementations that do not cache the last write time, both loops
111
- will result in a potentially expensive call to the
112
- `std::filesystem::last_write_time` function. On implementations that do
113
- cache the last write time, the first loop will use the cached value and
114
- so will not result in a potentially expensive call to the
115
- `std::filesystem::last_write_time` function. The code is portable to any
116
- implementation, regardless of whether or not it employs caching.
117
-
118
- — *end example*]
119
-
120
- #### `directory_entry` constructors <a id="fs.dir.entry.cons">[[fs.dir.entry.cons]]</a>
121
-
122
- ``` cpp
123
- explicit directory_entry(const path& p);
124
- directory_entry(const path& p, error_code& ec);
125
- ```
126
-
127
- *Effects:* Constructs an object of type `directory_entry`, then
128
- `refresh()` or `refresh(ec)`, respectively.
129
-
130
- *Postconditions:* `path() == p` if no error occurs, otherwise
131
- `path() == std::filesystem::path()`.
132
-
133
- *Throws:* As specified in  [[fs.err.report]].
134
-
135
- #### `directory_entry` modifiers <a id="fs.dir.entry.mods">[[fs.dir.entry.mods]]</a>
136
-
137
- ``` cpp
138
- void assign(const path& p);
139
- void assign(const path& p, error_code& ec);
140
- ```
141
-
142
- *Effects:* Equivalent to `pathobject = p`, then `refresh()` or
143
- `refresh(ec)`, respectively. If an error occurs, the values of any
144
- cached attributes are unspecified.
145
-
146
- *Throws:* As specified in  [[fs.err.report]].
147
-
148
- ``` cpp
149
- void replace_filename(const path& p);
150
- void replace_filename(const path& p, error_code& ec);
151
- ```
152
-
153
- *Effects:* Equivalent to `pathobject.replace_filename(p)`, then
154
- `refresh()` or `refresh(ec)`, respectively. If an error occurs, the
155
- values of any cached attributes are unspecified.
156
-
157
- *Throws:* As specified in  [[fs.err.report]].
158
-
159
- ``` cpp
160
- void refresh();
161
- void refresh(error_code& ec) noexcept;
162
- ```
163
-
164
- *Effects:* Stores the current values of any cached attributes of the
165
- file `p` resolves to. If an error occurs, an error is
166
- reported ([[fs.err.report]]) and the values of any cached attributes
167
- are unspecified.
168
-
169
- *Throws:* As specified in  [[fs.err.report]].
170
-
171
- [*Note 1*: Implementations of
172
- `directory_iterator` ([[fs.class.directory_iterator]]) are prohibited
173
- from directly or indirectly calling the `refresh` function since it must
174
- access the external file system, and the objective of caching is to
175
- avoid unnecessary file system accesses. — *end note*]
176
-
177
- #### `directory_entry` observers <a id="fs.dir.entry.obs">[[fs.dir.entry.obs]]</a>
178
-
179
- Unqualified function names in the *Returns:* elements of the
180
- `directory_entry` observers described below refer to members of the
181
- `std::filesystem` namespace.
182
-
183
- ``` cpp
184
- const path& path() const noexcept;
185
- operator const path&() const noexcept;
186
- ```
187
-
188
- *Returns:* `pathobject`.
189
-
190
- ``` cpp
191
- bool exists() const;
192
- bool exists(error_code& ec) const noexcept;
193
- ```
194
-
195
- *Returns:* `exists(this->status())` or `exists(this->status(), ec)`,
196
- respectively.
197
-
198
- *Throws:* As specified in  [[fs.err.report]].
199
-
200
- ``` cpp
201
- bool is_block_file() const;
202
- bool is_block_file(error_code& ec) const noexcept;
203
- ```
204
-
205
- *Returns:* `is_block_file(this->status())` or
206
- `is_block_file(this->status(), ec)`, respectively.
207
-
208
- *Throws:* As specified in  [[fs.err.report]].
209
-
210
- ``` cpp
211
- bool is_character_file() const;
212
- bool is_character_file(error_code& ec) const noexcept;
213
- ```
214
-
215
- *Returns:* `is_character_file(this->status())` or
216
- `is_character_file(this->status(), ec)`, respectively.
217
-
218
- *Throws:* As specified in  [[fs.err.report]].
219
-
220
- ``` cpp
221
- bool is_directory() const;
222
- bool is_directory(error_code& ec) const noexcept;
223
- ```
224
-
225
- *Returns:* `is_directory(this->status())` or
226
- `is_directory(this->status(), ec)`, respectively.
227
-
228
- *Throws:* As specified in  [[fs.err.report]].
229
-
230
- ``` cpp
231
- bool is_fifo() const;
232
- bool is_fifo(error_code& ec) const noexcept;
233
- ```
234
-
235
- *Returns:* `is_fifo(this->status())` or `is_fifo(this->status(), ec)`,
236
- respectively.
237
-
238
- *Throws:* As specified in  [[fs.err.report]].
239
-
240
- ``` cpp
241
- bool is_other() const;
242
- bool is_other(error_code& ec) const noexcept;
243
- ```
244
-
245
- *Returns:* `is_other(this->status())` or `is_other(this->status(), ec)`,
246
- respectively.
247
-
248
- *Throws:* As specified in  [[fs.err.report]].
249
-
250
- ``` cpp
251
- bool is_regular_file() const;
252
- bool is_regular_file(error_code& ec) const noexcept;
253
- ```
254
-
255
- *Returns:* `is_regular_file(this->status())` or
256
- `is_regular_file(this->status(), ec)`, respectively.
257
-
258
- *Throws:* As specified in  [[fs.err.report]].
259
-
260
- ``` cpp
261
- bool is_socket() const;
262
- bool is_socket(error_code& ec) const noexcept;
263
- ```
264
-
265
- *Returns:* `is_socket(this->status())` or
266
- `is_socket(this->status(), ec)`, respectively.
267
-
268
- *Throws:* As specified in  [[fs.err.report]].
269
-
270
- ``` cpp
271
- bool is_symlink() const;
272
- bool is_symlink(error_code& ec) const noexcept;
273
- ```
274
-
275
- *Returns:* `is_symlink(this->symlink_status())` or
276
- `is_symlink(this->symlink_status(), ec)`, respectively.
277
-
278
- *Throws:* As specified in  [[fs.err.report]].
279
-
280
- ``` cpp
281
- uintmax_t file_size() const;
282
- uintmax_t file_size(error_code& ec) const noexcept;
283
- ```
284
-
285
- *Returns:* If cached, the file size attribute value. Otherwise,
286
- `file_size(path())` or `file_size(path(), ec)`, respectively.
287
-
288
- *Throws:* As specified in  [[fs.err.report]].
289
-
290
- ``` cpp
291
- uintmax_t hard_link_count() const;
292
- uintmax_t hard_link_count(error_code& ec) const noexcept;
293
- ```
294
-
295
- *Returns:* If cached, the hard link count attribute value. Otherwise,
296
- `hard_link_count(path())` or `hard_link_count(path(), ec)`,
297
- respectively.
298
-
299
- *Throws:* As specified in  [[fs.err.report]].
300
-
301
- ``` cpp
302
- file_time_type last_write_time() const;
303
- file_time_type last_write_time(error_code& ec) const noexcept;
304
- ```
305
-
306
- *Returns:* If cached, the last write time attribute value. Otherwise,
307
- `last_write_time(path())` or `last_write_time(path(), ec)`,
308
- respectively.
309
-
310
- *Throws:* As specified in  [[fs.err.report]].
311
-
312
- ``` cpp
313
- file_status status() const;
314
- file_status status(error_code& ec) const noexcept;
315
- ```
316
-
317
- *Returns:* If cached, the status attribute value. Otherwise,
318
- `status(path())` or `status(path(), ec)`, respectively.
319
-
320
- *Throws:* As specified in  [[fs.err.report]].
321
-
322
- ``` cpp
323
- file_status symlink_status() const;
324
- file_status symlink_status(error_code& ec) const noexcept;
325
- ```
326
-
327
- *Returns:* If cached, the symlink status attribute value. Otherwise,
328
- `symlink_status(path())` or `symlink_status(path(), ec)`, respectively.
329
-
330
- *Throws:* As specified in  [[fs.err.report]].
331
-
332
- ``` cpp
333
- bool operator==(const directory_entry& rhs) const noexcept;
334
- ```
335
-
336
- *Returns:* `pathobject == rhs.pathobject`.
337
-
338
- ``` cpp
339
- bool operator!=(const directory_entry& rhs) const noexcept;
340
- ```
341
-
342
- *Returns:* `pathobject != rhs.pathobject`.
343
-
344
- ``` cpp
345
- bool operator< (const directory_entry& rhs) const noexcept;
346
- ```
347
-
348
- *Returns:* `pathobject < rhs.pathobject`.
349
-
350
- ``` cpp
351
- bool operator<=(const directory_entry& rhs) const noexcept;
352
- ```
353
-
354
- *Returns:* `pathobject <= rhs.pathobject`.
355
-
356
- ``` cpp
357
- bool operator> (const directory_entry& rhs) const noexcept;
358
- ```
359
-
360
- *Returns:* `pathobject > rhs.pathobject`.
361
-
362
- ``` cpp
363
- bool operator>=(const directory_entry& rhs) const noexcept;
364
- ```
365
-
366
- *Returns:* `pathobject >= rhs.pathobject`.
367
-