Working on backing files.

Also started a sketches project to illustrate quick ideas.
This commit is contained in:
2023-10-11 23:27:42 -07:00
parent fd6e0c6899
commit 2dcc577f57
13 changed files with 590 additions and 30 deletions

36
File.h
View File

@@ -25,6 +25,7 @@
#define KEPP__FILE_H_
#include <filesystem>
#include <fstream>
#include <ios>
#include <string>
@@ -32,6 +33,12 @@
#include "Defs.h"
typedef std::optional<std::ofstream *> OptOutFileStream;
typedef std::optional<std::ifstream *> OptInFileStream;
/// Files default to being read/write.
static constexpr std::ios::openmode DefaultMode =
std::ios::in|std::ios::out;
@@ -41,18 +48,41 @@ class File {
public:
File(std::string fPath);
const std::string &Path() const;
const std::string Path();
void SetPath(const std::string &fPath);
// int Refresh(std::);
OptOutFileStream Flush();
OptInFileStream Refresh();
/// The readonly attribute on a File is a virtual write
/// protection, and does not reflect the permissions on
/// the file itself. For that, see IsWriteable.
[[nodiscard]] bool IsReadOnly() const { return this->readOnly; };
void MarkReadOnly() { this->readOnly = true; }
void ClearReadOnly() { this->readOnly = false; }
/// Size returns the size of the file on disk.
size_t Size();
/// Exists checks whether the file exists on disk.
bool Exists();
/// IsWriteable checks whether the current user has write
/// permissions for the file.
bool IsWriteable();
/// IsReadable checks whether the current user has read
/// permissions on the file.
bool IsReadable();
/// IsReadWriteable checks whether the current user has both
/// read and write permissions on the file.
bool IsReadWriteable();
private:
std::string path;
std::filesystem::path path;
bool readOnly;
std::ios::openmode mode;
};