diff options
author | Brad King <brad.king@kitware.com> | 2016-02-03 18:18:37 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-02-03 18:19:42 (GMT) |
commit | f9487ac7971a668ddf142d5adc741f789c7bbb68 (patch) | |
tree | c46c5c7d4fdd747a6e7b1f1a4ed251f6020c35d7 /src/disk_interface.h | |
parent | 94086e990cac21451a98d949afec0b705b1c4d88 (diff) | |
download | Ninja-f9487ac7971a668ddf142d5adc741f789c7bbb68.zip Ninja-f9487ac7971a668ddf142d5adc741f789c7bbb68.tar.gz Ninja-f9487ac7971a668ddf142d5adc741f789c7bbb68.tar.bz2 |
Factor a `FileReader` base class out of `DiskInterface`
Some clients will need only the ability to read files, so provide this
as a more narrow interface than the full disk interface.
Diffstat (limited to 'src/disk_interface.h')
-rw-r--r-- | src/disk_interface.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/disk_interface.h b/src/disk_interface.h index b61d192..94f25dc 100644 --- a/src/disk_interface.h +++ b/src/disk_interface.h @@ -21,13 +21,20 @@ using namespace std; #include "timestamp.h" +/// Interface for reading files from disk. See DiskInterface for details. +/// This base offers the minimum interface needed just to read files. +struct FileReader { + virtual ~FileReader() {} + + /// Read a file to a string. Fill in |err| on error. + virtual string ReadFile(const string& path, string* err) = 0; +}; + /// Interface for accessing the disk. /// /// Abstract so it can be mocked out for tests. The real implementation /// is RealDiskInterface. -struct DiskInterface { - virtual ~DiskInterface() {} - +struct DiskInterface: public FileReader { /// stat() a file, returning the mtime, or 0 if missing and -1 on /// other errors. virtual TimeStamp Stat(const string& path, string* err) const = 0; @@ -39,9 +46,6 @@ struct DiskInterface { /// Returns true on success, false on failure virtual bool WriteFile(const string& path, const string& contents) = 0; - /// Read a file to a string. Fill in |err| on error. - virtual string ReadFile(const string& path, string* err) = 0; - /// Remove the file named @a path. It behaves like 'rm -f path' so no errors /// are reported if it does not exists. /// @returns 0 if the file has been removed, |