persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
IOManager Class Reference

#include <IOManager.hpp>

Inheritance diagram for IOManager:
Collaboration diagram for IOManager:

Public Member Functions

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.

Private Member Functions

 IOManager ()=default

Private Attributes

std::string basePath

Friends

class Singleton< IOManager >

Detailed Description

Definition at line 121 of file IOManager.hpp.

Constructor & Destructor Documentation

◆ IOManager()

IOManager::IOManager ( )
privatedefault
Here is the caller graph for this function:

Member Function Documentation

◆ 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
pathRelative asset path, e.g. "textures/rock".
suffixSuffix/extension to append, e.g. ".img.bin".
Returns
std::string Resolved file path.

Definition at line 72 of file IOManager.cpp.

◆ init()

void IOManager::init ( )
override

Definition at line 5 of file IOManager.cpp.

◆ loadToRAM()

void * IOManager::loadToRAM ( const std::string & filePath,
u32 * outSize )

Loads an entire file into a buffer.

Parameters
filePathPath relative to the base path.
outSizeOptional. 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.

Here is the call graph for this function:

◆ openFile() [1/2]

void * IOManager::openFile ( const std::string & path)

Open a file and return a pointer to its contents.

Parameters
pathThe 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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
pathThe path to the file to open.
sizeReference 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.

Here is the call graph for this function:

◆ openFileBuffer()

FileBuffer IOManager::openFileBuffer ( const std::string & path)

Definition at line 164 of file IOManager.cpp.

Here is the call graph for this function:

◆ process()

void IOManager::process ( )
inlineoverride

Definition at line 126 of file IOManager.hpp.

◆ 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
TTrivially-copyable type to read into.
Parameters
dataObject to read into.
filePathPath 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.

Here is the call graph for this function:

◆ shutdown()

void IOManager::shutdown ( )
inlineoverride

Definition at line 130 of file IOManager.hpp.

◆ unloadFromRAM()

void IOManager::unloadFromRAM ( void * buffer)

Releases a buffer previously returned by loadToRAM().

Parameters
bufferPointer 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
TTrivially-copyable type to write.
Parameters
dataObject to write.
filePathPath 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.

Here is the call graph for this function:

◆ Singleton< IOManager >

friend class Singleton< IOManager >
friend

Definition at line 271 of file IOManager.hpp.

Member Data Documentation

◆ basePath

std::string IOManager::basePath
private

Definition at line 277 of file IOManager.hpp.


The documentation for this class was generated from the following files: