CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::BinaryReader Class Referencefinal

A reader that parses data from an underlying input stream as binary data. More...

#include <CeresEngine/Foundation/IO/Stream.hpp>

Public Types

using Seek = Stream::Seek
 

Public Member Functions

 BinaryReader (InputStream inputStream)
 
 BinaryReader (IInputStream &inputStream)
 
template<typename T , typename... Args>
T read (Args &&... args)
 Reads a binary representation of T from the stream.
 
template<typename T , typename... Args>
Optional< TtryRead (Args &&... args)
 Tries to read a data type from the stream.
 
size_t read (void *data, const size_t n)
 Reads data from the data stream to a buffer of raw memory data with length n.
 
bool isSeekable (const Seek mode=Seek::Start) const noexcept
 Checks if the stream is seekable.
 
void seek (const std::streamsize position, const Seek mode=Seek::Start)
 Changes the position of the data stream.
 
void skip (const size_t n)
 Skips n bytes from the data stream.
 
bool isTellable () const noexcept
 Checks if the stream knows it's current absolute position.
 
size_t tell ()
 Gets the absolute stream position, in bytes.
 
bool isSizeKnown () const noexcept
 Checks if the stream knows the size of the data.
 
size_t size ()
 Gets the number of bytes available on the stream.
 
InputStreamgetInputStream ()
 The input stream to which data will be read from.
 
const InputStreamgetInputStream () const
 The input stream to which data will be read from.
 

Private Attributes

InputStream mInputStream
 The input stream to which data will be read from.
 

Detailed Description

A reader that parses data from an underlying input stream as binary data.

Member Typedef Documentation

◆ Seek

Constructor & Destructor Documentation

◆ BinaryReader() [1/2]

CeresEngine::BinaryReader::BinaryReader ( InputStream  inputStream)
inlineexplicit

◆ BinaryReader() [2/2]

CeresEngine::BinaryReader::BinaryReader ( IInputStream inputStream)
inlineexplicit

Member Function Documentation

◆ getInputStream() [1/2]

InputStream & CeresEngine::BinaryReader::getInputStream ( )
inline

The input stream to which data will be read from.

◆ getInputStream() [2/2]

const InputStream & CeresEngine::BinaryReader::getInputStream ( ) const
inline

The input stream to which data will be read from.

◆ isSeekable()

bool CeresEngine::BinaryReader::isSeekable ( const Seek  mode = Seek::Start) const
inlinenoexcept

Checks if the stream is seekable.

If this method returns true, seek() is safe to be called on this stream.

◆ isSizeKnown()

bool CeresEngine::BinaryReader::isSizeKnown ( ) const
inlinenoexcept

Checks if the stream knows the size of the data.

If this method returns true, size() is safe to be called on this stream.

◆ isTellable()

bool CeresEngine::BinaryReader::isTellable ( ) const
inlinenoexcept

Checks if the stream knows it's current absolute position.

If this method returns true, tell() is safe to be called on this stream.

◆ read() [1/2]

template<typename T , typename... Args>
T CeresEngine::BinaryReader::read ( Args &&...  args)
inline

Reads a binary representation of T from the stream.

Note
The actual decoding of the data is done by BinaryCodec.

◆ read() [2/2]

size_t CeresEngine::BinaryReader::read ( void data,
const size_t  n 
)
inline

Reads data from the data stream to a buffer of raw memory data with length n.

Note
This method is only callable if isReadable() returns true.
Parameters
dataThe memory location to which read data should be placed.
nThe maximum number of bytes to be read from the data stream.
Returns
The number of bytes actually read. Can be smaller than n. If 0, indicates that the stream has ended.

◆ seek()

void CeresEngine::BinaryReader::seek ( const std::streamsize  position,
const Seek  mode = Seek::Start 
)
inline

Changes the position of the data stream.

Note
This method is only callable if isSeekable() returns true.
Parameters
positionThe position to set the data stream to.
modeThe mode to change the data stream position.

◆ size()

size_t CeresEngine::BinaryReader::size ( )
inline

Gets the number of bytes available on the stream.

Note
This method is only callable if isSizeKnown() returns true.

◆ skip()

void CeresEngine::BinaryReader::skip ( const size_t  n)
inline

Skips n bytes from the data stream.

◆ tell()

size_t CeresEngine::BinaryReader::tell ( )
inline

Gets the absolute stream position, in bytes.

Note
This method is only callable if isTellable() returns true.

◆ tryRead()

template<typename T , typename... Args>
Optional< T > CeresEngine::BinaryReader::tryRead ( Args &&...  args)
inline

Tries to read a data type from the stream.

If the read fails, returns an empty optional.

Member Data Documentation

◆ mInputStream

InputStream CeresEngine::BinaryReader::mInputStream
private

The input stream to which data will be read from.


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