Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::ByteBufferInputStream Class Reference

An in-memory byte stream designed for I/O performance. More...

#include <ByteBufferInputStream.h>

Inheritance diagram for ph::ByteBufferInputStream:
ph::IInputStream ph::IDataStream

Public Member Functions

 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.
 
ByteBufferInputStreamoperator= (ByteBufferInputStream &&rhs)=default
 
std::byte * byteBuffer ()
 Direct access to the underlying byte buffer.
 
const std::byte * byteBuffer () const
 
Aliased buffer accessors.

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
 
- Public Member Functions inherited from ph::IInputStream
void readLine (std::string *out_string)
 Read a line. Equivalent to calling readString(std::string*, char) with '
' as the delimiter.
 
- Public Member Functions inherited from ph::IDataStream
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.
 

Detailed Description

An in-memory byte stream designed for I/O performance.

Constructor & Destructor Documentation

◆ 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]

ph::ByteBufferInputStream::ByteBufferInputStream ( ByteBufferInputStream && other)
inlinedefault

Member Function Documentation

◆ 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
Returns
Whether the stream is good for read.

Implements ph::IInputStream.

◆ operator=()

ByteBufferInputStream & ph::ByteBufferInputStream::operator= ( ByteBufferInputStream && rhs)
inlinedefault

◆ 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
numBytesNumber of bytes to read.
[out]out_bytesThe read bytes. Must contain storage for at least numBytes bytes.
Exceptions
IOExceptionIf 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
numBytesMaximum number of bytes to read.
[out]out_bytesThe read bytes. Must contain storage for at least numBytes bytes.
Returns
How many bytes were actually read.
Exceptions
IOExceptionIf 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_stringThe read string. Does not include the delimiter.
delimiterThe character that denotes the ending of a line.
Exceptions
IOExceptionIf 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
posThe position to set to.
Exceptions
IOExceptionIf 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: