An in-memory byte stream designed for I/O performance.
More...
#include <ByteBufferInputStream.h>
|
| ByteBufferInputStream () |
|
| ByteBufferInputStream (const std::byte *srcByteBuffer, std::size_t numBytes) |
|
| ByteBufferInputStream (const char *srcCharBuffer, std::size_t numChars) |
|
| ByteBufferInputStream (const unsigned char *srcUCharBuffer, std::size_t numUChars) |
|
| ByteBufferInputStream (std::size_t numBytes) |
|
| ByteBufferInputStream (ByteBufferInputStream &&other)=default |
|
void | read (std::size_t numBytes, std::byte *out_bytes) override |
| Read specific number of raw bytes in one go. The method does not return before finishing the reading process.
|
|
void | readString (std::string *out_string, char delimiter) override |
| Read a string in one go. Note the EOF is also considered a delimiter (the final one).
|
|
void | seekGet (std::size_t pos) override |
| Set the input position of the stream. The unit of the position is defined by the implementation.
|
|
std::optional< std::size_t > | tellGet () override |
| Get the current input position of the stream. The unit of the position is defined by the implementation.
|
|
| operator bool () const override |
|
std::size_t | readSome (std::size_t numBytes, std::byte *out_bytes) override |
| Read some data in the form of raw bytes. The method may return before finish reading all bytes. In such case, the method returns how many bytes were actually read.
|
|
template<typename T > |
void | readData (T *out_data) |
|
std::size_t | numBufferBytes () const |
| Get the size of the underlying byte buffer.
|
|
bool | canRead (std::size_t numBytes) const |
| Whether we can read numBytes of bytes from the stream.
|
|
bool | canRead () const |
| Whether we can read any number (non-zero) of bytes from the stream.
|
|
ByteBufferInputStream & | operator= (ByteBufferInputStream &&rhs)=default |
|
|
std::byte * | byteBuffer () |
| Direct access to the underlying byte buffer.
|
|
const std::byte * | byteBuffer () const |
|
|
Helpers for accessing the underlying buffer using an aliased type (char or unsigned char). Note that the aliasing does not violate strict aliasing rules as it is specifically allowed by the standard to use char and unsigned char to alias any other types (in our case it is std::byte).
|
char * | charBuffer () |
|
const char * | charBuffer () const |
|
unsigned char * | ucharBuffer () |
|
const unsigned char * | ucharBuffer () const |
|
void | readLine (std::string *out_string) |
| Read a line. Equivalent to calling readString(std::string*, char) with '
' as the delimiter.
|
|
virtual | ~IDataStream ()=default |
|
virtual std::string | acquireName () const |
| Access to the stream's name. This method is not meant to be used in a high performance context, unless otherwise stated by the overridder. Stream name is not always available.
|
|
An in-memory byte stream designed for I/O performance.
◆ ByteBufferInputStream() [1/6]
ph::ByteBufferInputStream::ByteBufferInputStream |
( |
| ) |
|
◆ ByteBufferInputStream() [2/6]
ph::ByteBufferInputStream::ByteBufferInputStream |
( |
const std::byte * | srcByteBuffer, |
|
|
std::size_t | numBytes ) |
◆ ByteBufferInputStream() [3/6]
ph::ByteBufferInputStream::ByteBufferInputStream |
( |
const char * | srcCharBuffer, |
|
|
std::size_t | numChars ) |
◆ ByteBufferInputStream() [4/6]
ph::ByteBufferInputStream::ByteBufferInputStream |
( |
const unsigned char * | srcUCharBuffer, |
|
|
std::size_t | numUChars ) |
◆ ByteBufferInputStream() [5/6]
ph::ByteBufferInputStream::ByteBufferInputStream |
( |
std::size_t | numBytes | ) |
|
|
explicit |
◆ ByteBufferInputStream() [6/6]
◆ byteBuffer() [1/2]
std::byte * ph::ByteBufferInputStream::byteBuffer |
( |
| ) |
|
|
inline |
Direct access to the underlying byte buffer.
◆ byteBuffer() [2/2]
const std::byte * ph::ByteBufferInputStream::byteBuffer |
( |
| ) |
const |
|
inline |
◆ canRead() [1/2]
bool ph::ByteBufferInputStream::canRead |
( |
| ) |
const |
|
inline |
Whether we can read any number (non-zero) of bytes from the stream.
◆ canRead() [2/2]
bool ph::ByteBufferInputStream::canRead |
( |
std::size_t | numBytes | ) |
const |
|
inline |
Whether we can read numBytes
of bytes from the stream.
◆ charBuffer() [1/2]
char * ph::ByteBufferInputStream::charBuffer |
( |
| ) |
|
|
inline |
◆ charBuffer() [2/2]
const char * ph::ByteBufferInputStream::charBuffer |
( |
| ) |
const |
|
inline |
◆ numBufferBytes()
std::size_t ph::ByteBufferInputStream::numBufferBytes |
( |
| ) |
const |
|
inline |
Get the size of the underlying byte buffer.
◆ operator bool()
ph::ByteBufferInputStream::operator bool |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ operator=()
◆ read()
void ph::ByteBufferInputStream::read |
( |
std::size_t | numBytes, |
|
|
std::byte * | out_bytes ) |
|
inlineoverridevirtual |
Read specific number of raw bytes in one go. The method does not return before finishing the reading process.
- Parameters
-
| numBytes | Number of bytes to read. |
[out] | out_bytes | The read bytes. Must contain storage for at least numBytes bytes. |
- Exceptions
-
IOException | If the read operation failed. |
Implements ph::IInputStream.
◆ readData()
template<typename T >
void ph::ByteBufferInputStream::readData |
( |
T * | out_data | ) |
|
|
inline |
◆ readSome()
std::size_t ph::ByteBufferInputStream::readSome |
( |
std::size_t | numBytes, |
|
|
std::byte * | out_bytes ) |
|
inlineoverridevirtual |
Read some data in the form of raw bytes. The method may return before finish reading all bytes. In such case, the method returns how many bytes were actually read.
- Parameters
-
| numBytes | Maximum number of bytes to read. |
[out] | out_bytes | The read bytes. Must contain storage for at least numBytes bytes. |
- Returns
- How many bytes were actually read.
- Exceptions
-
IOException | If the read operation failed. |
Reimplemented from ph::IInputStream.
◆ readString()
void ph::ByteBufferInputStream::readString |
( |
std::string * | out_string, |
|
|
char | delimiter ) |
|
inlineoverridevirtual |
Read a string in one go. Note the EOF is also considered a delimiter (the final one).
- Parameters
-
out_string | The read string. Does not include the delimiter . |
delimiter | The character that denotes the ending of a line. |
- Exceptions
-
IOException | If the read operation failed. |
Implements ph::IInputStream.
◆ seekGet()
void ph::ByteBufferInputStream::seekGet |
( |
std::size_t | pos | ) |
|
|
inlineoverridevirtual |
Set the input position of the stream. The unit of the position is defined by the implementation.
- Parameters
-
pos | The position to set to. |
- Exceptions
-
IOException | If the seeking process failed. |
Implements ph::IInputStream.
◆ tellGet()
std::optional< std::size_t > ph::ByteBufferInputStream::tellGet |
( |
| ) |
|
|
inlineoverridevirtual |
Get the current input position of the stream. The unit of the position is defined by the implementation.
- Returns
- Current input position. Empty if the position is unavailable.
Implements ph::IInputStream.
◆ ucharBuffer() [1/2]
unsigned char * ph::ByteBufferInputStream::ucharBuffer |
( |
| ) |
|
|
inline |
◆ ucharBuffer() [2/2]
const unsigned char * ph::ByteBufferInputStream::ucharBuffer |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following files: