11#include <aegis/manager.hpp>
121class IOManager :
public ae::Manager,
public ae::Singleton<IOManager>
124 void init()
override;
141 template <
typename T>
142 requires std::is_trivially_copyable_v<T>
152 std::string path =
basePath + filePath;
153 FILE* file = fopen(path.c_str(),
"rb");
161 size_t readCount = fread(data,
sizeof(T), 1, file);
182 template <
typename T>
183 requires std::is_trivially_copyable_v<T>
193 std::string tempPath =
basePath + filePath +
".tmp";
194 std::string path =
basePath + filePath;
196 FILE* file = fopen(tempPath.c_str(),
"wb");
204 size_t written = fwrite(data,
sizeof(T), 1, file);
216 remove(path.c_str());
217 rename(tempPath.c_str(), path.c_str());
228 void*
loadToRAM(
const std::string& filePath, u32* outSize);
241 void*
openFile(
const std::string& path);
250 void*
openFile(
const std::string& path, u32& size);
Owns a heap-allocated file buffer and its length.
FileBuffer & operator=(const FileBuffer &)=delete
Copy assignment is disabled to preserve unique ownership.
void * release()
Releases the file data to the caller.
void * get() const
Gets the owned file data without transferring ownership.
FileBuffer(FileBuffer &&other) noexcept
Transfers ownership from another file buffer.
u32 length() const
Gets the file data length.
~FileBuffer()
Releases the owned file data.
FileBuffer(void *data, u32 size)
Constructs a file buffer that takes ownership of data.
FileBuffer()=default
Constructs an empty file buffer.
FileBuffer & operator=(FileBuffer &&other) noexcept
Releases current data and transfers ownership from another buffer.
FileBuffer(const FileBuffer &)=delete
Copy construction is disabled to preserve unique ownership.
void * loadToRAM(const std::string &filePath, u32 *outSize)
Loads an entire file into a buffer.
bool writeFile(T *data, std::string filePath)
Writes raw data of type T to a file, atomically via a temp file.
FileBuffer openFileBuffer(const std::string &path)
void unloadFromRAM(void *buffer)
Releases a buffer previously returned by loadToRAM().
void * openFile(const std::string &path)
Open a file and return a pointer to its contents.
std::string getAssetFilePath(const std::string &path, const char *suffix)
Resolves the on-disk path for an asset, allowing it to be stored either as a flat file or grouped in ...
bool readFile(T *data, std::string filePath)
Reads raw data of type T from a file into data.
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Util to handle error logging.