LibCppBinary
Modern cross-platform C++ binary parsing library
Loading...
Searching...
No Matches
Binary::Stream Class Referenceabstract

Abstract base class representing a binary stream. More...

#include <Stream.h>

Inheritance diagram for Binary::Stream:
Binary::BufferStream Binary::FileStream Binary::StandardFileStream

Public Member Functions

virtual ~Stream ()=default
 Default destructor; properly destroys the instance.
virtual void Read (DataField *field) const =0
 Reads data from the stream into the specified field.
virtual void Read (DataStructure *structure) const =0
 Reads data from stream into the specified data structure.
virtual std::shared_ptr< ChunkHeaderFindNextChunk (std::string id) const =0
 Finds the next chunk header with the specified ID.
virtual void Write (const DataField *field)=0
 Writes data to the stream from the specified field.
virtual void Write (const DataStructure *structure)=0
 Writes the specified structure to the stream.
virtual size_t Position () const =0
 Gets the current position in the stream.
virtual void SetPosition (size_t position) const =0
 Sets the current position in the stream.
virtual size_t Beginning () const =0
 Gets the beginning position of the file.
virtual size_t End () const =0
 Gets the end position of the file.

Detailed Description

Abstract base class representing a binary stream.

Classes that represent a binary stream should derive from this class. This class accepts pointers to instances of DataField and other types composed of data fields for reading and writing to and from the binary data source.

Constructor & Destructor Documentation

◆ ~Stream()

virtual Binary::Stream::~Stream ( )
virtualdefault

Default destructor; properly destroys the instance.

Member Function Documentation

◆ Beginning()

virtual size_t Binary::Stream::Beginning ( ) const
pure virtual

Gets the beginning position of the file.

Returns
A size_t value representing the beginning position.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ End()

virtual size_t Binary::Stream::End ( ) const
pure virtual

Gets the end position of the file.

Returns
A size_t value representing the end position.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ FindNextChunk()

virtual std::shared_ptr< ChunkHeader > Binary::Stream::FindNextChunk ( std::string id) const
pure virtual

Finds the next chunk header with the specified ID.

Parameters
idThe ID of the chunk to find.
Returns
A pointer to the chunk header if found, otherwise nullptr.
Precondition
id must be exactly 4 characters long.
Postcondition
Position is advanced to the beginning of found chunk header.
Exceptions
std::invalid_argumentif id is not 4 characters long.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ Position()

virtual size_t Binary::Stream::Position ( ) const
pure virtual

Gets the current position in the stream.

Returns
A size_t representing the position.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ Read() [1/2]

virtual void Binary::Stream::Read ( DataField * field) const
pure virtual

Reads data from the stream into the specified field.

Parameters
fieldA pointer to the field to read data into.
Precondition
Field must not be null.
Field size must be <= remaining buffer size.
Postcondition
Position is advanced by field size.
Specified field is updated with the data read from the buffer.
Exceptions
std::out_of_rangeif field size > remaining buffer size.
std::invalid_argumentif field is null.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ Read() [2/2]

virtual void Binary::Stream::Read ( DataStructure * structure) const
pure virtual

Reads data from stream into the specified data structure.

Parameters
structureA pointer to the data structure to read data into.
Precondition
Structure must not be null.
Structure size must be <= remaining buffer size.
Postcondition
Position is advanced by structure size.
Specified structure is updated with the data read from buffer.
Exceptions
std::out_of_rangeif structure size > remaining buffer size.
std::invalid_argumentif structure is null.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ SetPosition()

virtual void Binary::Stream::SetPosition ( size_t position) const
pure virtual

Sets the current position in the stream.

Parameters
positionThe position value to set.
Precondition
Position must be between 0 and size, inclusive.
Postcondition
Position is updated to the specified value.
Exceptions
std::out_of_rangeif position > size.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ Write() [1/2]

virtual void Binary::Stream::Write ( const DataField * field)
pure virtual

Writes data to the stream from the specified field.

Parameters
fieldA pointer to the field to write to the stream.
Precondition
Field must not be null.
Field size must be <= remaining buffer size.
Postcondition
Position is advanced by field size.
Buffer is updated with the data from the specified field.
Exceptions
std::out_of_rangeif field size > remaining buffer size.
std::invalid_argumentif field is null.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.

◆ Write() [2/2]

virtual void Binary::Stream::Write ( const DataStructure * structure)
pure virtual

Writes the specified structure to the stream.

Parameters
structureA pointer to the structure to write to the stream.
Precondition
Structure must not be null.
Structure size must be <= remaining buffer size.
Postcondition
Position is advanced by structure size.
Buffer is updated with the data from the specified structure.
Exceptions
std::out_of_rangeif structure size > remaining buffer size.
std::invalid_argumentif structure is null.

Implemented in Binary::BufferStream, and Binary::StandardFileStream.


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