A RAII wrapper for SDL3 file operations supporting read/write access.
More...
#include <file_system.h>
|
static bool | file_exists (const std::string &file_path) |
| Check if a file exists at the given path. More...
|
|
A RAII wrapper for SDL3 file operations supporting read/write access.
res://
(assets) and user://
(writable user data) paths.
◆ FileAccess() [1/3]
Construct and optionally open a file.
- Parameters
-
file_path | Path to the file (can be res:// or user://) |
mode_flags | Mode of access (default: READ) |
◆ FileAccess() [2/3]
FileAccess::FileAccess |
( |
| ) |
|
|
default |
Default constructor (empty, file not opened)
◆ ~FileAccess()
FileAccess::~FileAccess |
( |
| ) |
|
Destructor automatically closes the file if it is open.
◆ FileAccess() [3/3]
◆ close()
void FileAccess::close |
( |
| ) |
|
Close the file if it is open.
◆ file_exists()
bool FileAccess::file_exists |
( |
const std::string & |
file_path | ) |
|
|
static |
Check if a file exists at the given path.
- Parameters
-
file_path | Path to the file |
- Returns
- true if the file exists, false otherwise
◆ get_absolute_path()
std::string FileAccess::get_absolute_path |
( |
| ) |
const |
Get the absolute resolved path to the file.
- Returns
- Full path on the filesystem
◆ get_file_as_bytes()
std::vector< char > FileAccess::get_file_as_bytes |
( |
| ) |
|
Read the entire file as a vector of bytes.
- Returns
- File contents as Array of Bytes.
◆ get_file_as_str()
std::string FileAccess::get_file_as_str |
( |
| ) |
|
Read the entire file as a String.
- Returns
- File contents as String
◆ get_path()
std::string FileAccess::get_path |
( |
| ) |
const |
Get the path relative to the base (removes res:// or user:// prefix)
- Returns
- Relative path string
◆ is_open()
bool FileAccess::is_open |
( |
| ) |
const |
Check if the file is currently open.
- Returns
- true if open, false otherwise
◆ open()
Open a file for reading/writing.
- Parameters
-
file_path | Path to the file (res:// or user://) |
mode_flags | Access mode |
By default, get from res://
- Returns
- true if the file was successfully opened, false otherwise
◆ operator=()
◆ seek()
void FileAccess::seek |
( |
int |
length | ) |
|
Move the file pointer to the given offset from the beginning.
- Parameters
-
◆ seek_end()
void FileAccess::seek_end |
( |
int |
position | ) |
|
Move the file pointer relative to the end of the file.
- Parameters
-
position | Offset in bytes from the end |
◆ store_bytes()
bool FileAccess::store_bytes |
( |
const std::vector< char > & |
content | ) |
|
Write a byte array to the file.
- Parameters
-
content | Vector of bytes to write |
- Returns
- true if successful
◆ store_string()
bool FileAccess::store_string |
( |
const std::string & |
content = "" | ) |
|
Write a string to the file.
- Parameters
-
content | String content to write |
- Returns
- true if successful
The documentation for this class was generated from the following files: