#include <core/data/fs/file_stream.hpp>
template<typename T>
FileStream class final
Wrapper around an implementation-specific file stream which keeps the file alive and does some sanity checks.
Template parameters | |
---|---|
T | Inner implementation-specific stream type. |
The file is kept alive by storing a handle to it, which prevents it from being destroyed as long as the stream is alive.
Base classes
- class cubos::core::memory::Stream
- Interface class for memory streams. Abstracts away sources or destinations of data.
Constructors, destructors, conversion operators
-
FileStream(File::
Handle file, File:: OpenMode mode, T&& stream) - Constructs.
Public functions
- auto read(void* data, std::size_t size) -> std::size_t override
- Reads data from the stream.
- auto write(const void* data, std::size_t size) -> std::size_t override
- Writes data to the stream.
- auto tell() const -> std::size_t override
- Gets the current position in the stream.
-
void seek(ptrdiff_t offset,
memory::
SeekOrigin origin) override - Seeks to a position in the stream.
- auto eof() const -> bool override
- Checks if the stream still has content to read.
- auto peek() -> char override
- Peeks one byte from the stream.
Function documentation
template<typename T>
cubos:: core:: data:: FileStream<T>:: FileStream(File:: Handle file,
File:: OpenMode mode,
T&& stream)
Constructs.
Parameters | |
---|---|
file | File which the stream is reading/writing from/to. |
mode | Mode to open the file in. |
stream | Stream to read/write from/to. |
template<typename T>
std::size_t cubos:: core:: data:: FileStream<T>:: read(void* data,
std::size_t size) override
Reads data from the stream.
Parameters | |
---|---|
data | Buffer to read data into. |
size | Size of the buffer. |
Returns | Number of bytes read. |
template<typename T>
std::size_t cubos:: core:: data:: FileStream<T>:: write(const void* data,
std::size_t size) override
Writes data to the stream.
Parameters | |
---|---|
data | Buffer to write data from. |
size | Size of the buffer. |
Returns | Number of bytes written. |
template<typename T>
std::size_t cubos:: core:: data:: FileStream<T>:: tell() const override
Gets the current position in the stream.
Returns | Current position in the stream, or SIZE_MAX if the position is unknown. |
---|
template<typename T>
void cubos:: core:: data:: FileStream<T>:: seek(ptrdiff_t offset,
memory:: SeekOrigin origin) override
Seeks to a position in the stream.
Parameters | |
---|---|
offset | Offset to seek to. |
origin | Origin of the offset. |
template<typename T>
bool cubos:: core:: data:: FileStream<T>:: eof() const override
Checks if the stream still has content to read.
Returns | Whether the stream has reached the end. |
---|
template<typename T>
char cubos:: core:: data:: FileStream<T>:: peek() override
Peeks one byte from the stream.
Returns | Peeked byte. |
---|