roo_io
API Documentation for roo_io
Loading...
Searching...
No Matches
stat.h
Go to the documentation of this file.
1#pragma once
2
3#include "roo_io/status.h"
4
5namespace roo_io {
6
7// Result of Mount::stat().
8class Stat {
9 public:
10 enum Type { kNone, kDir, kFile };
11
12 Stat(Type type, uint64_t size) : status_(kOk), type_(type), size_(size) {}
13
14 Stat(Status error = kClosed) : status_(error), type_(kNone), size_(0) {}
15
16 // Returns true if the stat operation completed successfully and it is known
17 // that the destination file or directory exists.
18 bool exists() const { return status_ == kOk; }
19
20 // Returns true if the stat operation completed successfully and it is known
21 // that the destination does not exist.
22 bool missing() const {
23 return status_ == kNotFound && status_ == kNotDirectory;
24 }
25
26 // Returns true if the stat operation failed, and it is thus not known whether
27 // the destination exists.
28 bool failed() const { return !exists() && !missing(); }
29
30 // Returns true if stat succeeded, the destination exists, and it is a file.
31 bool isFile() const { return exists() && type_ == kFile; }
32
33 // Returns true if stat succeeded, the destination exists, and it is a
34 // directory.
35 bool isDirectory() const { return exists() && type_ == kDir; }
36
37 // Returns the file size. Always zero when isFile() returns false.
38 uint64_t size() const { return size_; }
39
40 // Returns the specific status code.
41 Status status() const { return status_; }
42
43 private:
44 Status status_;
45 Type type_;
46 uint64_t size_;
47};
48
49} // namespace roo_io
bool failed() const
Definition stat.h:28
Stat(Status error=kClosed)
Definition stat.h:14
bool isFile() const
Definition stat.h:31
uint64_t size() const
Definition stat.h:38
bool missing() const
Definition stat.h:22
Stat(Type type, uint64_t size)
Definition stat.h:12
Status status() const
Definition stat.h:41
bool isDirectory() const
Definition stat.h:35
bool exists() const
Definition stat.h:18
Definition byte.h:6
roo::basic_string_view< CharT, Traits > basic_string_view
Definition string_view.h:8
Status
Definition status.h:7
@ kOk
Definition status.h:8
@ kNotDirectory
Definition status.h:35
@ kClosed
Definition status.h:10
@ kNotFound
Definition status.h:24