File include/brisk/core/Stream.hpp
¶
Transferred
class¶
Transferred
TransferredRepresents the result of a read or write operation, indicating success, failure, or end-of-file (EOF), along with the number of bytes transferred.
This struct is used to encapsulate the result of I/O operations in a way that clearly distinguishes between successful data transfers, errors, and EOF conditions.
Transferred
function (Transferred::Transferred
)¶
constexpr Transferred() noexcept = default
Default constructor.
constexpr Transferred(const Transferred &) noexcept =
default
Copy constructor.
Param other
Another Transferred object to copy from.
constexpr Transferred(size_t bytes) noexcept
: m_bytes(bytes)
Constructs a Transferred object with a specified number of bytes.
Param bytes
Number of bytes transferred.
(unnamed)
enum (Transferred::(unnamed enum at /src/include/brisk/core/Stream.hpp:62:5)
)¶
enum : size_t
Special values for indicating EOF and error conditions.
SpecialValues
enumerator (Transferred::(unnamed enum at /src/include/brisk/core/Stream.hpp:62:5)::SpecialValues
)¶
*/
Eof
enumerator (Transferred::(unnamed enum at /src/include/brisk/core/Stream.hpp:62:5)::Eof
)¶
*/
Error
enumerator (Transferred::(unnamed enum at /src/include/brisk/core/Stream.hpp:62:5)::Error
)¶
*/
isEOF
function (Transferred::isEOF
)¶
bool isEOF() const noexcept
Checks if the result indicates an EOF condition.
Returns True if the result is EOF, false otherwise.
isError
function (Transferred::isError
)¶
bool isError() const noexcept
Checks if the result indicates an error.
Returns True if the result is an error, false otherwise.
bytes
function (Transferred::bytes
)¶
size_t bytes() const noexcept
Retrieves the number of bytes successfully transferred.
Returns Number of bytes transferred. If the result indicates EOF or error,
the returned value is 0.
operator bool
function (Transferred::operator bool
)¶
explicit operator bool() const noexcept
Converts the Transferred object to a boolean value indicating
whether at least one byte was transferred.
Returns True if at least one byte was transferred, false otherwise.
operator+=
function (Transferred::operator+=
)¶
Transferred &operator+=(Transferred other) noexcept
Adds the number of bytes from another Transferred object to this one.
If either Transferred object represents an error or EOF, the result
will be the error or EOF accordingly.
Param other
Another Transferred object to add.
Returns Reference to this Transferred object with the updated byte count.
operator==
function (Transferred::operator==
)¶
bool operator==(const Transferred &t) const noexcept =
default
Compares this Transferred object with another for equality.
Param t
Another Transferred object to compare with.
Returns True if both Transferred objects represent the same result (bytes count),
false otherwise.
SeekOrigin
enum¶
enum class SeekOrigin
SeekOriginSpecifies the reference point for a seek operation in a stream.
This enumeration is used to indicate the starting point from which a seek operation should be performed.
Beginning
enumerator (SeekOrigin::Beginning
)¶
*/
End
enumerator (SeekOrigin::End
)¶
*/
Current
enumerator (SeekOrigin::Current
)¶
*/
invalidPosition
variable¶
constexpr inline uintmax_t invalidPosition = UINTMAX_MAX
Constant representing an invalid position in a stream.
This value is used to indicate an invalid or undefined position when working with stream operations.
invalidSize
variable¶
constexpr inline uintmax_t invalidSize = UINTMAX_MAX
Constant representing an invalid size for a stream.
This value is used to indicate an invalid or undefined size when working with stream operations.
StreamCapabilities
enum¶
enum class StreamCapabilities
StreamCapabilitiesDescribes the capabilities of a stream.
This enumeration specifies various capabilities that a stream may support, allowing for querying and conditional operations based on the stream's features.
CanRead
enumerator (StreamCapabilities::CanRead
)¶
*/
CanWrite
enumerator (StreamCapabilities::CanWrite
)¶
*/
CanSeek
enumerator (StreamCapabilities::CanSeek
)¶
*/
CanFlush
enumerator (StreamCapabilities::CanFlush
)¶
*/
CanTruncate
enumerator (StreamCapabilities::CanTruncate
)¶
*/
HasSize
enumerator (StreamCapabilities::HasSize
)¶
*/
operator+
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator&&
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator|
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator&
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator|=
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator^=
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator^
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator~
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator&=
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator>>
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator<<=
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator>>=
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator+
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
operator+=
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
toggle
function¶
BRISK_FLAGS(StreamCapabilities)
Macro to enable bitwise operations for StreamCapabilities.
This macro allows for the use of bitwise operations on the StreamCapabilities enumeration, such as bitwise OR, AND, and NOT operations.
Stream
class¶
Stream
StreamAbstract base class representing a stream with read, write, seek, and other operations.
This class provides a common interface for stream operations such as reading, writing, seeking, and querying stream properties. Concrete implementations should override the pure virtual functions to provide specific behavior for different types of streams.
~Stream
function (Stream::~Stream
)¶
virtual ~Stream()
Virtual destructor for the Stream class.
caps
function (Stream::caps
)¶
virtual StreamCapabilities caps() const noexcept = 0
Retrieves the capabilities of the stream.
Returns StreamCapabilities A bitmask representing the capabilities of the stream.
read
function (Stream::read
)¶
virtual Transferred read(uint8_t *data, size_t size) = 0
Reads up to size
bytes from the stream into the provided buffer.
The read
function attempts to read size
bytes of data from the stream and stores it in the
buffer pointed to by data
.
If the stream reaches the end of the file (EOF) before the requested number of bytes
are read, the function will return the number of bytes successfully read.
Param data
Pointer to the buffer where the read data will be stored.
Param size
Number of bytes to attempt to read from the stream.
Returns Transferred
- The total number of bytes read if successful.
- Transferred::Eof
if EOF is encountered before any data is read.
- Transferred::Error
if an error occurs during the read operation.
Details - If EOF is reached, the function returns the number of bytes read before EOF.
- If EOF is reached before any bytes are read, Transferred::Eof
is returned.
write
function (Stream::write
)¶
virtual Transferred write(const uint8_t *data,
size_t size) = 0
Writes up to size
bytes from the provided buffer to the stream.
The write
function attempts to write size
bytes of data from the buffer pointed to by data
into the stream.
Param data
Pointer to the buffer containing the data to be written.
Param size
Number of bytes to attempt to write to the stream.
Returns Transferred
- The total number of bytes written if successful.
- Transferred::Error
if an error occurs during the write operation.
Details - If any error occurs during the WriteFile
call or no bytes are written, the function
returns Transferred::Error
.
flush
function (Stream::flush
)¶
virtual bool flush() = 0
Flushes the stream, ensuring that all buffered data is written to the underlying storage.
Returns True if the flush operation was successful, false otherwise.
seek
function (Stream::seek
)¶
virtual bool
seek(intmax_t position,
SeekOrigin origin = SeekOrigin::Beginning) = 0
Seeks to a specific position in the stream.
Param position
The position to seek to.
Param origin
The reference point for the seek operation.
Returns True if the seek operation was successful, false otherwise.
tell
function (Stream::tell
)¶
virtual uintmax_t tell() const = 0
Retrieves the current position of the stream.
Returns The current position of the stream or invalidPosition
if an error occurs.
size
function (Stream::size
)¶
virtual uintmax_t size() const = 0
Retrieves the size of the stream.
Returns The size of the stream or invalidSize
if an error occurs.
truncate
function (Stream::truncate
)¶
virtual bool truncate() = 0
Truncates the stream to the current position.
Returns True if the truncate operation was successful, false otherwise.
canRead
function (Stream::canRead
)¶
bool canRead() const noexcept
Checks if the stream supports read operations.
Returns True if the stream supports reading, false otherwise.
canWrite
function (Stream::canWrite
)¶
bool canWrite() const noexcept
Checks if the stream supports write operations.
Returns True if the stream supports writing, false otherwise.
canSeek
function (Stream::canSeek
)¶
bool canSeek() const noexcept
Checks if the stream supports seek operations.
Returns True if the stream supports seeking, false otherwise.
canFlush
function (Stream::canFlush
)¶
bool canFlush() const noexcept
Checks if the stream supports flush operations.
Returns True if the stream supports flushing, false otherwise.
canTruncate
function (Stream::canTruncate
)¶
bool canTruncate() const noexcept
Checks if the stream supports truncation operations.
Returns True if the stream supports truncating, false otherwise.
hasSize
function (Stream::hasSize
)¶
bool hasSize() const noexcept
Checks if the stream has a size property.
Returns True if the stream has a size property, false otherwise.
read
function (Stream::read
)¶
Transferred read(std::span<uint8_t> data)
Reads data into a std::span<uint8_t\>
buffer.
Param data
A std::span<uint8_t\>
representing the buffer to read into.
Returns Transferred The result of the read operation.
readUntilEnd
function (Stream::readUntilEnd
)¶
optional<std::vector<uint8_t>>
readUntilEnd(bool incompleteOk = false)
Reads data from the stream until the end is reached or an error occurs.
The readUntilEnd
function reads data in chunks into a std::vector<uint8_t\>
from the stream. It
continues reading until EOF is encountered or an error occurs. If an error occurs before all requested
data is read and incompleteOk
is set to false
, the function returns std::nullopt
to indicate that
the read operation failed.
Param incompleteOk
If set to true
, allows returning partial data if error occurs before the buffer
is completely filled.
Returns std::optional<std::vector<uint8_t>>
- A std::vector<uint8_t\>
containing the data read from the stream if successful.
- std::nullopt
if an error occurs and incompleteOk
is false
.
writeAll
function (Stream::writeAll
)¶
bool writeAll(std::span<const uint8_t> data)
Writes all data from the given span to the stream.
The writeAll
function attempts to write the entire range of data specified by data
to the
stream. It ensures that the number of bytes written matches the size of the data
span.
Param data
A std::span<const uint8_t\>
containing the data to be written.
Returns bool True if the entire data was written successfully; otherwise, false.
write
function (Stream::write
)¶
Transferred write(string_view data)
Writes the contents of a string_view
to the stream.
The write
function writes the data pointed to by data
, interpreted as a sequence of bytes, to the
stream.
Param data
A string_view
representing the data to be written.
Returns Transferred The result of the write operation, indicating the number of bytes written or an
error.
SequentialReader
class¶
SequentialReader
SequentialReaderStream reader with restricted capabilities.
Supports read operations only. Other operations throw ENotImplemented.
SequentialWriter
class¶
SequentialWriter
SequentialWriterStream writer with restricted capabilities.
Supports write and flush operations only. Other operations throw ENotImplemented.
Reader
class¶
Reader
ReaderStream reader with additional seek capabilities.
Inherits from SequentialReader and supports seek operations.
Writer
class¶
Writer
WriterStream writer with additional seek capabilities.
Inherits from SequentialWriter and supports seek operations.
MemoryStream
class¶
MemoryStream
MemoryStreamIn-memory stream with full read/write capabilities.
Internally stores data as a std::vector<uint8_t\>
and grows as new data is written to the stream.
Supports all stream operations, including read, write, seek, and size queries.
MemoryStream
function (MemoryStream::MemoryStream
)¶
MemoryStream()
Default constructor for MemoryStream
.
Initializes an empty stream.
MemoryStream(std::vector<uint8_t> data)
Constructs a MemoryStream
with the given initial data.
Param data
A std::vector<uint8_t\>
containing the initial data for the stream.
data
function (MemoryStream::data
)¶
const std::vector<uint8_t> &data() const
Returns a const reference to the internal data buffer.
Returns A constant reference to the std::vector<uint8_t\>
holding the stream's data.
std::vector<uint8_t> &data()
Returns a non-const reference to the internal data buffer.
Returns A non-constant reference to the std::vector<uint8_t\>
holding the stream's data.
SpanStream
class¶
template <typename T> SpanStream
SpanStreamStream based on a span of data with read/write capabilities.
Supports read/write operations depending on whether the T is const-qualified.
SpanStream<T>
function (SpanStream::SpanStream<T>
)¶
SpanStream(std::span<T> data) : m_data(std::move(data))
Constructs a SpanStream
with the given data span.
Param data
A std::span<T\>
representing the initial data for the stream.
data
function (SpanStream::data
)¶
std::span<T> data() const
Returns a std::span<T\>
representing the data in the stream.
Returns A std::span<T\>
containing the current data in the stream.
Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/