#include <IOManager.hpp>
|
| void | init () override |
| void | process () override |
| void | shutdown () override |
template<typename T>
requires std::is_trivially_copyable_v<T> |
| bool | readFile (T *data, std::string filePath) |
| | Reads raw data of type T from a file into data.
|
template<typename T>
requires std::is_trivially_copyable_v<T> |
| bool | writeFile (T *data, std::string filePath) |
| | Writes raw data of type T to a file, atomically via a temp file.
|
| void * | loadToRAM (const std::string &filePath, u32 *outSize) |
| | Loads an entire file into a buffer.
|
| 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.
|
| void * | openFile (const std::string &path, u32 &size) |
| | Open a file and return a pointer to its contents, along with the size of the file.
|
| FileBuffer | openFileBuffer (const std::string &path) |
| 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 its own subdirectory.
|
Definition at line 121 of file IOManager.hpp.
◆ IOManager()
◆ getAssetFilePath()
| std::string IOManager::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 its own subdirectory.
Tries basePath + path + suffix first. If that file doesn't exist, falls back to treating path as a directory and looking for <path>/<leaf> + suffix, where <leaf> is the last path component (e.g. "textures/rock" -> "textures/rock/rock" + suffix). This lets related asset files (e.g. multiple suffixes for one logical asset) be grouped in a subfolder when needed.
- Note
- The fallback path is returned unconditionally, without checking it actually exists.
- Parameters
-
| path | Relative asset path, e.g. "textures/rock". |
| suffix | Suffix/extension to append, e.g. ".img.bin". |
- Returns
- std::string Resolved file path.
Definition at line 72 of file IOManager.cpp.
◆ init()
◆ loadToRAM()
| void * IOManager::loadToRAM |
( |
const std::string & | filePath, |
|
|
u32 * | outSize ) |
Loads an entire file into a buffer.
- Parameters
-
| filePath | Path relative to the base path. |
| outSize | Optional. Receives the loaded size in bytes (0 on failure). |
- Returns
- Pointer to the loaded data, or nullptr on failure.
Definition at line 11 of file IOManager.cpp.
◆ openFile() [1/2]
| void * IOManager::openFile |
( |
const std::string & | path | ) |
|
Open a file and return a pointer to its contents.
- Parameters
-
| path | The path to the file to open. |
- Returns
- Pointer to the contents of the file, or nullptr if opening failed.
Definition at line 96 of file IOManager.cpp.
◆ openFile() [2/2]
| void * IOManager::openFile |
( |
const std::string & | path, |
|
|
u32 & | size ) |
Open a file and return a pointer to its contents, along with the size of the file.
- Parameters
-
| path | The path to the file to open. |
| size | Reference to a variable to store the size of the file. |
- Returns
- Pointer to the contents of the file, or nullptr if opening failed.
- Note
- This function is useful when you need to know the size of the file being opened.
Definition at line 131 of file IOManager.cpp.
◆ openFileBuffer()
| FileBuffer IOManager::openFileBuffer |
( |
const std::string & | path | ) |
|
◆ process()
| void IOManager::process |
( |
| ) |
|
|
inlineoverride |
◆ readFile()
template<typename T>
requires std::is_trivially_copyable_v<T>
| bool IOManager::readFile |
( |
T * | data, |
|
|
std::string | filePath ) |
|
inline |
Reads raw data of type T from a file into data.
- Template Parameters
-
| T | Trivially-copyable type to read into. |
- Parameters
-
| data | Object to read into. |
| filePath | Path relative to the base path. |
- Returns
- true on success, false if the file could not be opened.
Definition at line 143 of file IOManager.hpp.
◆ shutdown()
| void IOManager::shutdown |
( |
| ) |
|
|
inlineoverride |
◆ unloadFromRAM()
| void IOManager::unloadFromRAM |
( |
void * | buffer | ) |
|
Releases a buffer previously returned by loadToRAM().
- Parameters
-
| buffer | Pointer to release. Safe to call with nullptr. |
Definition at line 63 of file IOManager.cpp.
◆ writeFile()
template<typename T>
requires std::is_trivially_copyable_v<T>
| bool IOManager::writeFile |
( |
T * | data, |
|
|
std::string | filePath ) |
|
inline |
Writes raw data of type T to a file, atomically via a temp file.
- Template Parameters
-
| T | Trivially-copyable type to write. |
- Parameters
-
| data | Object to write. |
| filePath | Path relative to the base path. |
- Returns
- true on success, false if the temp file could not be opened.
Definition at line 184 of file IOManager.hpp.
◆ Singleton< IOManager >
◆ basePath
| std::string IOManager::basePath |
|
private |
The documentation for this class was generated from the following files: