OpenTTD Source 15.0-beta2
ByteReader Class Reference

Class to read from a NewGRF file. More...

#include <newgrf_bytereader.h>

Public Member Functions

 ByteReader (const uint8_t *data, const uint8_t *end)
 
const uint8_t * ReadBytes (size_t size)
 
uint8_t ReadByte ()
 Read a single byte (8 bits).
 
uint16_t ReadWord ()
 Read a single Word (16 bits).
 
uint16_t ReadExtendedByte ()
 Read a single Extended Byte (8 or 16 bits).
 
uint32_t ReadDWord ()
 Read a single DWord (32 bits).
 
uint32_t PeekDWord ()
 Read a single DWord (32 bits).
 
uint32_t ReadVarSize (uint8_t size)
 Read a value of the given number of bytes.
 
std::string_view ReadString ()
 Read a string.
 
size_t Remaining () const
 
bool HasData (size_t count=1) const
 
void Skip (size_t len)
 

Private Attributes

const uint8_t * data
 Current position within data.
 
const uint8_t * end
 Last position of data.
 

Detailed Description

Class to read from a NewGRF file.

Definition at line 16 of file newgrf_bytereader.h.

Constructor & Destructor Documentation

◆ ByteReader()

ByteReader::ByteReader ( const uint8_t *  data,
const uint8_t *  end 
)
inline

Definition at line 18 of file newgrf_bytereader.h.

Member Function Documentation

◆ HasData()

bool ByteReader::HasData ( size_t  count = 1) const
inline

Definition at line 82 of file newgrf_bytereader.h.

◆ PeekDWord()

uint32_t ByteReader::PeekDWord ( )

Read a single DWord (32 bits).

Note
The buffer is NOT advanced.
Returns
Value read from buffer.

Definition at line 22 of file newgrf_bytereader.cpp.

References data, and ReadDWord().

Referenced by StationChangeInfo().

◆ ReadByte()

◆ ReadBytes()

const uint8_t * ByteReader::ReadBytes ( size_t  size)
inline

Definition at line 20 of file newgrf_bytereader.h.

◆ ReadDWord()

◆ ReadExtendedByte()

uint16_t ByteReader::ReadExtendedByte ( )
inline

Read a single Extended Byte (8 or 16 bits).

Returns
Value read from buffer.

Definition at line 57 of file newgrf_bytereader.h.

References ReadByte(), and ReadWord().

Referenced by AircraftVehicleChangeInfo(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), ShipVehicleChangeInfo(), and StationChangeInfo().

◆ ReadString()

std::string_view ByteReader::ReadString ( )

Read a string.

Returns
Sting read from the buffer.

Definition at line 48 of file newgrf_bytereader.cpp.

References data, and ttd_strnlen().

Referenced by ChangeGRFParamValueNames(), FeatureTownName(), GlobalVarChangeInfo(), HandleNode(), SkipUnknownInfo(), and TranslateGRFStrings().

◆ ReadVarSize()

uint32_t ByteReader::ReadVarSize ( uint8_t  size)

Read a value of the given number of bytes.

Returns
Value read from buffer.

Definition at line 32 of file newgrf_bytereader.cpp.

References ReadByte(), ReadDWord(), and ReadWord().

◆ ReadWord()

◆ Remaining()

size_t ByteReader::Remaining ( ) const
inline

Definition at line 77 of file newgrf_bytereader.h.

◆ Skip()

void ByteReader::Skip ( size_t  len)
inline

Definition at line 87 of file newgrf_bytereader.h.

Field Documentation

◆ data

const uint8_t* ByteReader::data
private

Current position within data.

Definition at line 96 of file newgrf_bytereader.h.

Referenced by PeekDWord(), and ReadString().

◆ end

const uint8_t* ByteReader::end
private

Last position of data.

Definition at line 97 of file newgrf_bytereader.h.

Referenced by ReadByte().


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