64 lines
1.6 KiB
C
64 lines
1.6 KiB
C
|
///
|
||
|
/// \file File.h
|
||
|
/// \author kyle
|
||
|
/// \created 10/11/23
|
||
|
/// \brief File contains configuration information for a file.
|
||
|
///
|
||
|
/// \section COPYRIGHT
|
||
|
/// Copyright 2023 K. Isom <kyle@imap.cc>
|
||
|
///
|
||
|
/// Permission to use, copy, modify, and/or distribute this software for
|
||
|
/// any purpose with or without fee is hereby granted, provided that the
|
||
|
/// above copyright notice and this permission notice appear in all copies.
|
||
|
///
|
||
|
/// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||
|
/// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||
|
/// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
|
||
|
/// BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
|
||
|
/// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||
|
/// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||
|
/// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||
|
/// SOFTWARE.
|
||
|
///
|
||
|
|
||
|
#ifndef KEPP__FILE_H_
|
||
|
#define KEPP__FILE_H_
|
||
|
|
||
|
|
||
|
#include <fstream>
|
||
|
#include <ios>
|
||
|
#include <string>
|
||
|
|
||
|
#include "Defs.h"
|
||
|
|
||
|
|
||
|
static constexpr std::ios::openmode DefaultMode =
|
||
|
std::ios::in|std::ios::out;
|
||
|
|
||
|
|
||
|
/// A File abstracts a concrete file on disk.
|
||
|
class File {
|
||
|
public:
|
||
|
File(std::string fPath);
|
||
|
|
||
|
const std::string &Path() const;
|
||
|
void SetPath(const std::string &fPath);
|
||
|
|
||
|
// int Refresh(std::);
|
||
|
|
||
|
|
||
|
[[nodiscard]] bool IsReadOnly() const { return this->readOnly; };
|
||
|
void MarkReadOnly() { this->readOnly = true; }
|
||
|
void ClearReadOnly() { this->readOnly = false; }
|
||
|
|
||
|
private:
|
||
|
std::string path;
|
||
|
bool readOnly;
|
||
|
std::ios::openmode mode;
|
||
|
};
|
||
|
|
||
|
|
||
|
typedef std::optional<File> OptFile;
|
||
|
|
||
|
#endif // KEPP__FILE_H_
|