The File class represents a I/O file asset.
More...
#include <headers/utility/system_io/file.hpp>
|
| enum class | Seek { Unknown = 0
, SET = 0
, CUR = 1
, END = 2
} |
| | The Seek enum represents the different seek modes for file operations. More...
|
| |
|
| | File (const std::string &path, const std::string &content) |
| | Constructs a File object with its content and size.
|
| |
| | File (const std::string &path, const std::vector< std::byte > &content) |
| | Constructs a File object with raw binary content.
|
| |
|
| ~File () |
| | Destructs the File object.
|
| |
| size_t | write (const void *ptr, size_t size, size_t nmemb) |
| | Writes data to the file.
|
| |
| size_t | read (void *ptr, size_t size, size_t count) |
| | Reads data from the file.
|
| |
| size_t | read (std::string &str, size_t size, size_t count) |
| | Reads data from the file.
|
| |
| int | seek (long offset, Seek whence) |
| | Seeks to a specific position in the file.
|
| |
| size_t | tell () const |
| | Returns the current position in the file.
|
| |
| const std::vector< std::byte > & | data () const |
| | Returns the binary content of the file.
|
| |
| std::string | content () const |
| | Returns the content of the file as a string view.
|
| |
| const std::string & | path () const |
| | Returns the path of the file.
|
| |
| size_t | size () const |
| | Returns the size of the file content.
|
| |
| void | clear () |
| | Clears the content of the file.
|
| |
| size_t | remove (size_t count) |
| | Removes a number of elements from the current position.
|
| |
|
| std::vector< std::byte > | _content |
| | In-memory content of the asset.
|
| |
| std::string | _path |
| | Path to the file.
|
| |
| size_t | _pos = 0 |
| | Current read/write cursor position in the content buffer.
|
| |
The File class represents a I/O file asset.
This class provides methods to read and write binary data to and from a file. Content is stored as raw bytes so binary assets (which may contain null bytes) are handled correctly.
Definition at line 47 of file file.hpp.
◆ Seek
The Seek enum represents the different seek modes for file operations.
| Enumerator |
|---|
| SET |
Unknown seek mode
|
| CUR |
Seek from the beginning of the file
|
| END |
Seek from the current position in the file
|
Definition at line 55 of file file.hpp.
◆ File() [1/2]
| utility::File::File |
( |
const std::string & |
path, |
|
|
const std::string & |
content |
|
) |
| |
Constructs a File object with its content and size.
- Parameters
-
| path | The path to the file. |
| content | The content of the file. |
Definition at line 30 of file file_asset.cpp.
◆ File() [2/2]
| utility::File::File |
( |
const std::string & |
path, |
|
|
const std::vector< std::byte > & |
content |
|
) |
| |
Constructs a File object with raw binary content.
- Parameters
-
| path | The path to the file. |
| content | The binary content of the file. |
Definition at line 39 of file file_asset.cpp.
◆ clear()
| void utility::File::clear |
( |
| ) |
|
Clears the content of the file.
This method clears the content of the file by resetting the _content member variable to an empty string and resetting the _pos member variable to 0. After calling this method, the file will be empty and the position will be reset to the beginning of the file. This method can be used to clear the content of the file before writing new data to it or to reset the file to an empty state.
Definition at line 139 of file file_asset.cpp.
◆ content()
| std::string utility::File::content |
( |
| ) |
const |
|
inline |
Returns the content of the file as a string view.
Convenience accessor for text-oriented consumers. For binary assets prefer data().
- Returns
- The content of the file interpreted as bytes.
Definition at line 140 of file file.hpp.
◆ data()
| const std::vector< std::byte > & utility::File::data |
( |
| ) |
const |
|
inline |
Returns the binary content of the file.
- Returns
- The content of the file as raw bytes.
Definition at line 128 of file file.hpp.
◆ path()
| const std::string & utility::File::path |
( |
| ) |
const |
|
inline |
Returns the path of the file.
This method returns the path of the file as a string. The path is stored in the _path member variable and can be accessed using this method.
- Returns
- The path of the file.
Definition at line 154 of file file.hpp.
◆ read() [1/2]
| size_t utility::File::read |
( |
std::string & |
str, |
|
|
size_t |
size, |
|
|
size_t |
count |
|
) |
| |
Reads data from the file.
- Parameters
-
| str | The string to read data into. |
| size | The size of each element to read. |
| count | The number of elements to read. |
- Returns
- The number of elements read.
Definition at line 89 of file file_asset.cpp.
◆ read() [2/2]
| size_t utility::File::read |
( |
void * |
ptr, |
|
|
size_t |
size, |
|
|
size_t |
count |
|
) |
| |
Reads data from the file.
- Parameters
-
| ptr | The pointer to the buffer to read data into. |
| size | The size of each element to read. |
| count | The number of elements to read. |
- Returns
- The number of elements read.
Definition at line 72 of file file_asset.cpp.
◆ remove()
| size_t utility::File::remove |
( |
size_t |
count | ) |
|
Removes a number of elements from the current position.
- Parameters
-
| count | The number of elements to remove. |
- Returns
- The number of elements removed.
Definition at line 145 of file file_asset.cpp.
◆ seek()
| int utility::File::seek |
( |
long |
offset, |
|
|
Seek |
whence |
|
) |
| |
Seeks to a specific position in the file.
- Parameters
-
| offset | The offset to seek to. |
| whence | The seek mode (SET, CUR, END). |
- Returns
- 0 on success, -1 on failure.
Definition at line 108 of file file_asset.cpp.
◆ size()
| size_t utility::File::size |
( |
| ) |
const |
|
inline |
Returns the size of the file content.
This method returns the size of the file content by returning the size of the _content member variable. The size is returned as a size_t value.
- Returns
- The size of the file content.
Definition at line 168 of file file.hpp.
◆ tell()
| size_t utility::File::tell |
( |
| ) |
const |
Returns the current position in the file.
- Returns
- The current position in the file.
Definition at line 134 of file file_asset.cpp.
◆ write()
| size_t utility::File::write |
( |
const void * |
ptr, |
|
|
size_t |
size, |
|
|
size_t |
nmemb |
|
) |
| |
Writes data to the file.
- Parameters
-
| ptr | The pointer to the data to write. |
| size | The size of each element to write. |
| nmemb | The number of elements to write. |
- Returns
- The number of elements written.
This method appends data at the seek position in the file.
Definition at line 48 of file file_asset.cpp.
◆ _content
| std::vector<std::byte> utility::File::_content |
|
protected |
In-memory content of the asset.
Definition at line 197 of file file.hpp.
◆ _path
| std::string utility::File::_path |
|
protected |
Path to the file.
Definition at line 202 of file file.hpp.
◆ _pos
| size_t utility::File::_pos = 0 |
|
protected |
Current read/write cursor position in the content buffer.
Definition at line 207 of file file.hpp.
The documentation for this class was generated from the following files: