V-Gears 0
Free Final Fantasy VII engine.
BinaryReader Class Reference

Reader for binary files. More...

#include <BinaryReader.h>

Public Member Functions

 BinaryReader (std::vector< unsigned char > &&data)
 Constructor. More...
 
size_t GetSize () const
 Retrieves the size of the data in the reader. More...
 
void Seek (unsigned int position)
 Moves the stream cursor. More...
 
unsigned int GetPosition ()
 Retrieves the current stream cursor position. More...
 
unsigned int ReadU32 ()
 Reads 32 bits of data as an unsigned integer. More...
 
signed int ReadS32 ()
 Reads 32 bits of data as a signed integer. More...
 
signed short int ReadS16 ()
 Reads 16 bits of data as an unsigned integer. More...
 
unsigned short int ReadU16 ()
 Reads 16 bits of data as a signed integer. More...
 
unsigned char ReadU8 ()
 Reads 8 bits of data as an unsigned integer. More...
 
signed char ReadS8 ()
 Reads 8 bits of data as a signed integer. More...
 

Static Public Member Functions

static std::vector< unsigned char > ReadAll (std::string file_name)
 Reads a file, from start to end. More...
 

Private Member Functions

template<class T >
InternalRead ()
 Reads T bits of data as a signed integer. More...
 

Private Attributes

std::stringstream stream_
 The data stream. More...
 
size_t size_ = 0
 The size of the data, in bytes. More...
 

Detailed Description

Reader for binary files.

Constructor & Destructor Documentation

◆ BinaryReader()

BinaryReader::BinaryReader ( std::vector< unsigned char > &&  data)
inline

Constructor.

Parameters
[in]dataBytes for the reader

Member Function Documentation

◆ GetPosition()

unsigned int BinaryReader::GetPosition ( )
inline

Retrieves the current stream cursor position.

Returns
position[in] Position (offset) of the cursor.

◆ GetSize()

size_t BinaryReader::GetSize ( ) const
inline

Retrieves the size of the data in the reader.

Returns
The size of the data in bytes.

◆ InternalRead()

template<class T >
T BinaryReader::InternalRead ( )
inlineprivate

Reads T bits of data as a signed integer.

It advances the stream cursor.

Returns
Read bits.
Exceptions
DecompilerExceptionif there is not enough data.

◆ ReadAll()

static std::vector< unsigned char > BinaryReader::ReadAll ( std::string  file_name)
inlinestatic

Reads a file, from start to end.

Parameters
[in]file_namePath and name of the file to read.
Returns
Read bytes.
Exceptions
std::runtime_errorif the file can't be opened for reading.

◆ ReadS16()

signed short int BinaryReader::ReadS16 ( )
inline

Reads 16 bits of data as an unsigned integer.

It advances the stream cursor.

Returns
Read bits.
Exceptions
DecompilerExceptionif there is not enough data.

◆ ReadS32()

signed int BinaryReader::ReadS32 ( )
inline

Reads 32 bits of data as a signed integer.

It advances the stream cursor.

Returns
Read bits.
Exceptions
DecompilerExceptionif there is not enough data.

◆ ReadS8()

signed char BinaryReader::ReadS8 ( )
inline

Reads 8 bits of data as a signed integer.

It advances the stream cursor.

Returns
Read bits.
Exceptions
DecompilerExceptionif there is not enough data.

◆ ReadU16()

unsigned short int BinaryReader::ReadU16 ( )
inline

Reads 16 bits of data as a signed integer.

It advances the stream cursor.

Returns
Read bits.
Exceptions
DecompilerExceptionif there is not enough data.

◆ ReadU32()

unsigned int BinaryReader::ReadU32 ( )
inline

Reads 32 bits of data as an unsigned integer.

It advances the stream cursor.

Returns
Read bits.
Exceptions
DecompilerExceptionif there is not enough data.

◆ ReadU8()

unsigned char BinaryReader::ReadU8 ( )
inline

Reads 8 bits of data as an unsigned integer.

It advances the stream cursor.

Returns
Read bits.
Exceptions
DecompilerExceptionif there is not enough data.

◆ Seek()

void BinaryReader::Seek ( unsigned int  position)
inline

Moves the stream cursor.

Parameters
[in]positionPosition (offset) of the cursor.
Exceptions
DecompilerExceptionif the position is invalid.

Member Data Documentation

◆ size_

size_t BinaryReader::size_ = 0
private

The size of the data, in bytes.

◆ stream_

std::stringstream BinaryReader::stream_
private

The data stream.


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