BufferStream class
#include <core/memory/buffer_stream.hpp>
Stream implementation which writes to/reads from a buffer.
Base classes
- class Stream
- Interface class for memory streams. Abstracts away sources or destinations of data.
Constructors, destructors, conversion operators
- BufferStream(void* buffer, std::size_t size, bool readOnly = false)
- Constructs using an existing buffer.
- BufferStream(const void* buffer, std::size_t size)
- Constructs using a read-only buffer.
- BufferStream(std::size_t size = 16)
- Constructs using a new buffer, managed internally and which grows as needed.
- BufferStream(const BufferStream& other)
- Constructs a copy of another buffer stream. If the given buffer stream owns its buffer, the copy will also create its own buffer. Otherwise, it will share the buffer with the original.
- BufferStream(BufferStream&& other) noexcept
- Move constructs.
Public functions
- auto getBuffer() const -> const void*
- Gets the buffer of this stream.
- auto string() const -> std::string
- Creates a string from the buffer of this stream.
- 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, 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
cubos:: core:: memory:: BufferStream:: BufferStream(void* buffer,
std::size_t size,
bool readOnly = false)
Constructs using an existing buffer.
| Parameters | |
|---|---|
| buffer | Buffer to read/write from. |
| size | Size of the buffer. |
| readOnly | Whether the buffer is read-only. |
cubos:: core:: memory:: BufferStream:: BufferStream(const void* buffer,
std::size_t size)
Constructs using a read-only buffer.
| Parameters | |
|---|---|
| buffer | Buffer to read/write from. |
| size | Size of the buffer. |
cubos:: core:: memory:: BufferStream:: BufferStream(std::size_t size = 16)
Constructs using a new buffer, managed internally and which grows as needed.
| Parameters | |
|---|---|
| size | Initial size of the buffer. |
cubos:: core:: memory:: BufferStream:: BufferStream(const BufferStream& other)
Constructs a copy of another buffer stream. If the given buffer stream owns its buffer, the copy will also create its own buffer. Otherwise, it will share the buffer with the original.
| Parameters | |
|---|---|
| other | Buffer stream to copy. |
cubos:: core:: memory:: BufferStream:: BufferStream(BufferStream&& other) noexcept
Move constructs.
| Parameters | |
|---|---|
| other | Buffer stream to move. |
const void* cubos:: core:: memory:: BufferStream:: getBuffer() const
Gets the buffer of this stream.
| Returns | Buffer. |
|---|
std::string cubos:: core:: memory:: BufferStream:: string() const
Creates a string from the buffer of this stream.
| Returns | String. |
|---|
std::size_t cubos:: core:: memory:: BufferStream:: 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. |
std::size_t cubos:: core:: memory:: BufferStream:: 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. |
std::size_t cubos:: core:: memory:: BufferStream:: tell() const override
Gets the current position in the stream.
| Returns | Current position in the stream, or SIZE_MAX if the position is unknown. |
|---|
void cubos:: core:: memory:: BufferStream:: seek(ptrdiff_t offset,
SeekOrigin origin) override
Seeks to a position in the stream.
| Parameters | |
|---|---|
| offset | Offset to seek to. |
| origin | Origin of the offset. |
bool cubos:: core:: memory:: BufferStream:: eof() const override
Checks if the stream still has content to read.
| Returns | Whether the stream has reached the end. |
|---|
char cubos:: core:: memory:: BufferStream:: peek() override
Peeks one byte from the stream.
| Returns | Peeked byte. |
|---|