97 lines
2.6 KiB
C++
97 lines
2.6 KiB
C++
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright © 2025 Medusa Slockbower
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
#ifndef FENNEC_FPROC_IO_FILE_H
|
|
#define FENNEC_FPROC_IO_FILE_H
|
|
|
|
#include <fennec/fproc/strings/cstring.h>
|
|
#include <fennec/fproc/strings/string.h>
|
|
#include <fennec/fproc/filesystem/path.h>
|
|
|
|
struct FILE;
|
|
|
|
namespace fennec
|
|
{
|
|
|
|
///
|
|
/// \brief Mode flags for opening a file
|
|
enum fmode : uint8_t
|
|
{
|
|
read = 0b00000001
|
|
, write = 0b00000010
|
|
, append = 0b00000100
|
|
, no_overwrite = 0b00001000
|
|
};
|
|
|
|
class file
|
|
{
|
|
public:
|
|
file();
|
|
~file();
|
|
|
|
///
|
|
/// \brief Opens a file at the provided path using the provided mode
|
|
/// \param path the path to the provided file
|
|
/// \param mode the flags for opening the file
|
|
file(const cstring& path, fmode mode);
|
|
file(const string& path, fmode mode);
|
|
file(const path& path, fmode mode);
|
|
|
|
file(const file&) = delete;
|
|
|
|
|
|
// File Access =========================================================================================================
|
|
|
|
void open(const cstring& filename, fmode mode);
|
|
void open(const string& filename, fmode mode);
|
|
void open(const path& filename, fmode mode);
|
|
void close();
|
|
void commit();
|
|
|
|
|
|
// File Operations =====================================================================================================
|
|
|
|
void erase();
|
|
void rename(const cstring& str);
|
|
void rename(const string& str);
|
|
|
|
|
|
// File Positioning ====================================================================================================
|
|
|
|
size_t get_pos();
|
|
void set_pos(size_t i);
|
|
void rewind();
|
|
|
|
|
|
// Error Handling ======================================================================================================
|
|
|
|
bool check_error();
|
|
string get_error();
|
|
void clear_error();
|
|
|
|
|
|
//
|
|
|
|
private:
|
|
FILE* _handle;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // FENNEC_FPROC_IO_FILE_H
|