cpp-mate  0.7
Helpful library for C++.
CppMate::ReadStream Class Referencefinal

Represents the byte stream reader with custom byte order. More...

#include <ReadStream.hpp>

Public Member Functions

 ReadStream (std::shared_ptr< BinaryData > data, ByteOrder byteOrder=ByteOrder::Unknown)
 Constructor. More...
 
 ReadStream (const BinaryData *data, ByteOrder byteOrder=ByteOrder::Unknown)
 Constructor. More...
 
const BinaryDatagetData () const
 Returns binary data of stream. More...
 
uint64_t getSize () const
 Returns size of the stream. More...
 
uint64_t getAvailable () const
 Returns number of bytes available to read. More...
 
ByteOrder getByteOrder () const
 Returns byte order of the stream. More...
 
uint64_t getPosition () const
 Returns current position of the stream. More...
 
void setPosition (uint64_t position)
 Sets a new absolute position of the stream. More...
 
void reset ()
 Resets stream position to begin of the source data. More...
 
void seek (uint64_t offset, bool forward=true)
 Changes position of the stream by increase the offset value with the current position. The offset can be negative to move the current position back. More...
 
template<typename T >
void seek (uint64_t count=1)
 Seeks stream over a specified number of items. More...
 
void seekAlign (unsigned align)
 Changes position of stream to the closest position divisible by the provided parameter. More...
 
bool canRead (uint64_t bytes) const
 Checks the ability to read a specified number of bytes. More...
 
template<typename T >
bool canRead (uint64_t count=1) const
 Checks the ability to read a specified number of items. More...
 
template<typename T >
read ()
 Reads item from the stream. The method doesn't validate bounds, see canRead. More...
 
std::string readString (uint64_t length)
 Reads string from the stream. More...
 
uint64_t readBytes (uint8_t *buffer, uint64_t bufferSize)
 Reads a particular number of bytes from the stream. More...
 
void transfer (BinarySink &sink, uint64_t bytes)
 Transfer arbitrary block of bytes from stream to binary sink. More...
 
bool operator== (const ReadStream &other) const
 operator == More...
 
bool operator!= (const ReadStream &other) const
 operator != More...
 
template<>
uint8_t read ()
 
template<>
char read ()
 

Friends

template<typename T >
ReadStreamoperator>> (ReadStream &stream, T &result)
 operator >> More...
 

Detailed Description

Represents the byte stream reader with custom byte order.

Constructor & Destructor Documentation

◆ ReadStream() [1/2]

CppMate::ReadStream::ReadStream ( std::shared_ptr< BinaryData data,
ByteOrder  byteOrder = ByteOrder::Unknown 
)
inline

Constructor.

Parameters
datathe source binary data.
byteOrderthe byte order of the stream. If the byte order is ByteOrder::Unknown the platform byte order will be used.
Exceptions
std::invalid_argument

◆ ReadStream() [2/2]

CppMate::ReadStream::ReadStream ( const BinaryData data,
ByteOrder  byteOrder = ByteOrder::Unknown 
)
inline

Constructor.

Parameters
datathe source binary data.
byteOrderthe byte order of the stream. If the byte order is ByteOrder::Unknown the platform byte order will be used.
Exceptions
std::invalid_argument

Member Function Documentation

◆ canRead() [1/2]

bool CppMate::ReadStream::canRead ( uint64_t  bytes) const
inline

Checks the ability to read a specified number of bytes.

Parameters
bytesthe number of bytes to check.
Returns
true if bytes might be read; false otherwise.

◆ canRead() [2/2]

template<typename T >
bool CppMate::ReadStream::canRead ( uint64_t  count = 1) const
inline

Checks the ability to read a specified number of items.

Parameters
countthe number of items to check.
Returns
true if items might be read; false otherwise.

◆ getAvailable()

uint64_t CppMate::ReadStream::getAvailable ( ) const
inline

Returns number of bytes available to read.

Returns
number of bytes available to read.

◆ getByteOrder()

ByteOrder CppMate::ReadStream::getByteOrder ( ) const
inline

Returns byte order of the stream.

Returns
byte order of the stream.

◆ getData()

const BinaryData* CppMate::ReadStream::getData ( ) const
inline

Returns binary data of stream.

Returns
binary data of stream.

◆ getPosition()

uint64_t CppMate::ReadStream::getPosition ( ) const
inline

Returns current position of the stream.

Returns
current position of the stream.

◆ getSize()

uint64_t CppMate::ReadStream::getSize ( ) const
inline

Returns size of the stream.

Returns
size of the stream.

◆ operator!=()

bool CppMate::ReadStream::operator!= ( const ReadStream other) const
inline

operator !=

Parameters
otherthe instance to compare.
Returns
false if instances is equal; true otherwise.

◆ operator==()

bool CppMate::ReadStream::operator== ( const ReadStream other) const
inline

operator ==

Parameters
otherthe instance to compare.
Returns
true if instances is equal; false otherwise.

◆ read() [1/3]

template<typename T >
T CppMate::ReadStream::read ( )
inline

Reads item from the stream. The method doesn't validate bounds, see canRead.

Returns
item from the stream.

◆ read() [2/3]

template<>
uint8_t CppMate::ReadStream::read ( )
inline

◆ read() [3/3]

template<>
char CppMate::ReadStream::read ( )
inline

◆ readBytes()

uint64_t CppMate::ReadStream::readBytes ( uint8_t *  buffer,
uint64_t  bufferSize 
)
inline

Reads a particular number of bytes from the stream.

Parameters
bufferbuffer to receive bytes.
bufferSizesize of the buffer.
Returns
number of bytes read.
Exceptions
std::invalid_argument

◆ readString()

std::string CppMate::ReadStream::readString ( uint64_t  length)
inline

Reads string from the stream.

Parameters
lengththe length of the string to read.
Returns
string read from stream.

◆ reset()

void CppMate::ReadStream::reset ( )
inline

Resets stream position to begin of the source data.

◆ seek() [1/2]

template<typename T >
void CppMate::ReadStream::seek ( uint64_t  count = 1)
inline

Seeks stream over a specified number of items.

Parameters
countthe number of items.

◆ seek() [2/2]

void CppMate::ReadStream::seek ( uint64_t  offset,
bool  forward = true 
)
inline

Changes position of the stream by increase the offset value with the current position. The offset can be negative to move the current position back.

Parameters
offsetthe offset from the current position of the stream.
forwardindicates that offset should be calculated forward; otherwise backward.

◆ seekAlign()

void CppMate::ReadStream::seekAlign ( unsigned  align)
inline

Changes position of stream to the closest position divisible by the provided parameter.

Parameters
alignthe align to calculate.

◆ setPosition()

void CppMate::ReadStream::setPosition ( uint64_t  position)
inline

Sets a new absolute position of the stream.

Parameters
position

◆ transfer()

void CppMate::ReadStream::transfer ( BinarySink sink,
uint64_t  bytes 
)
inline

Transfer arbitrary block of bytes from stream to binary sink.

Parameters
sinkthe sink to transfer.
bytesthe number of bytes to transfer.

Friends And Related Function Documentation

◆ operator>>

template<typename T >
ReadStream& operator>> ( ReadStream stream,
T &  result 
)
friend

operator >>

Parameters
streamthe read stream.
resultthe result of read.
Returns
this

The documentation for this class was generated from the following file: