MAGE  v0.171.0
Matthias Advanced Game Engine
mage::BinaryReader Class Referenceabstract

#include <binary_reader.hpp>

Public Member Functions

BinaryReaderoperator= (const BinaryReader &reader)=delete
 
BinaryReaderoperator= (BinaryReader &&reader) noexcept
 
void ReadFromFile (std::filesystem::path path, bool big_endian)
 
void ReadFromMemory (gsl::span< const U8 > input, bool big_endian)
 

Protected Member Functions

 BinaryReader ()
 
 BinaryReader (const BinaryReader &reader)=delete
 
 BinaryReader (BinaryReader &&reader) noexcept
 
 ~BinaryReader ()
 
const std::filesystem::path & GetPath () const noexcept
 
bool ContainsChars () const noexcept
 
NotNull< const_zstringReadChars (std::size_t size)
 
template<typename T >
const T Read ()
 

Private Member Functions

virtual void ReadData ()=0
 

Private Attributes

std::filesystem::path m_path
 
bool m_big_endian
 
const U8m_pos
 
const U8m_end
 
UniquePtr< U8[] > m_data
 

Detailed Description

A class of readers for reading binary files.

Constructor & Destructor Documentation

◆ BinaryReader() [1/3]

mage::BinaryReader::BinaryReader ( )
protected

Constructs a binary reader.

◆ BinaryReader() [2/3]

mage::BinaryReader::BinaryReader ( const BinaryReader reader)
protecteddelete

Constructs a binary reader from the given binary reader.

Parameters
[in]readerA reference to the binary reader to copy.

◆ BinaryReader() [3/3]

mage::BinaryReader::BinaryReader ( BinaryReader &&  reader)
protecteddefaultnoexcept

Constructs a binary reader by moving the given binary reader.

Parameters
[in]readerA reference to the binary reader to move.

◆ ~BinaryReader()

mage::BinaryReader::~BinaryReader ( )
protecteddefault

Destructs this binary reader.

Member Function Documentation

◆ ContainsChars()

bool mage::BinaryReader::ContainsChars ( ) const
protectednoexcept

Checks if there are characters left to read by this binary reader.

Returns
true if there are characters left to read by this binary reader. false otherwise.

◆ GetPath()

const std::filesystem::path& mage::BinaryReader::GetPath ( ) const
protectednoexcept

Returns the current path of this binary reader.

Returns
A reference to the current path of this binary reader.

◆ operator=() [1/2]

BinaryReader& mage::BinaryReader::operator= ( const BinaryReader reader)
delete

Copies the given binary reader to this binary reader.

Parameters
[in]readerA reference to a binary reader to copy.
Returns
A reference to the copy of the given binary reader (i.e. this binary reader).

◆ operator=() [2/2]

BinaryReader & mage::BinaryReader::operator= ( BinaryReader &&  reader)
defaultnoexcept

Moves the given binary reader to this binary reader.

Parameters
[in]readerA reference to a binary reader to move.
Returns
A reference to the moved binary reader (i.e. this binary reader).

◆ Read()

template<typename T >
const T mage::BinaryReader::Read ( )
protected

Reads a T value.

Template Parameters
TThe data type.
Returns
The T value read.
Exceptions
ExceptionFailed to read a T value.

◆ ReadChars()

NotNull< const_zstring > mage::BinaryReader::ReadChars ( std::size_t  size)
protected

Reads an array of byte characters.

Parameters
sizeThe number of bytes to read.
Returns
A pointer to the array of characters read.
Exceptions
ExceptionFailed to read size bytes.

◆ ReadData()

virtual void mage::BinaryReader::ReadData ( )
privatepure virtual

Starts reading.

Exceptions
ExceptionFailed to read from the given file.

◆ ReadFromFile()

void mage::BinaryReader::ReadFromFile ( std::filesystem::path  path,
bool  big_endian 
)

Reads from the given file associated with the given path.

Parameters
[in]pathThe path.
[in]big_endianFlag indicating whether the given byte array should be interpreted as big endian or not (i.e. little endian).
Exceptions
ExceptionFailed to read from the file.

◆ ReadFromMemory()

void mage::BinaryReader::ReadFromMemory ( gsl::span< const U8 input,
bool  big_endian 
)

Reads the input string.

Parameters
[in]inputThe input byte string.
[in]big_endianFlag indicating whether the given byte array should be interpreted as big endian or not (i.e. little endian).
Exceptions
ExceptionFailed to read from the given input string.

Member Data Documentation

◆ m_big_endian

bool mage::BinaryReader::m_big_endian
private

A flag indicating whether the current data of this binary reader should be interpreted as big endian or not (i.e. little endian).

◆ m_data

UniquePtr< U8[] > mage::BinaryReader::m_data
private

A pointer to the data to read of this binary reader.

◆ m_end

const U8* mage::BinaryReader::m_end
private

A pointer to the end position of this binary reader.

◆ m_path

std::filesystem::path mage::BinaryReader::m_path
private

The current path of this binary reader.

◆ m_pos

const U8* mage::BinaryReader::m_pos
private

A pointer to the current position of this binary reader.