liblcf
LcfReader Class Reference

#include <reader_lcf.h>

+ Collaboration diagram for LcfReader:

Classes

struct  Chunk
 

Public Types

enum  SeekMode {
  FromStart ,
  FromEnd ,
  FromCurrent
}
 

Public Member Functions

 LcfReader (std::istream &filestream, std::string encoding="")
 
 ~LcfReader ()
 
size_t Read0 (void *ptr, size_t size, size_t nmemb)
 
void Read (void *ptr, size_t size, size_t nmemb)
 
template<class T >
void Read (T &ref)
 
template<class T >
void Read (std::vector< T > &buffer, size_t size)
 
int ReadInt ()
 
void ReadString (std::string &ref, size_t size)
 
bool IsOk () const
 
bool Eof () const
 
void Seek (size_t pos, SeekMode mode=FromStart)
 
uint32_t Tell ()
 
int Peek ()
 
void Skip (const struct LcfReader::Chunk &chunk_info)
 
void Encode (std::string &str)
 
std::vector< int32_t > & IntBuffer ()
 
template<>
void Read (bool &ref)
 
template<>
void Read (int8_t &ref)
 
template<>
void Read (uint8_t &ref)
 
template<>
void Read (int16_t &ref)
 
template<>
void Read (uint32_t &ref)
 
template<>
void Read (int32_t &ref)
 
template<>
void Read (double &ref)
 
template<>
void Read (std::vector< bool > &buffer, size_t size)
 
template<>
void Read (std::vector< uint8_t > &buffer, size_t size)
 
template<>
void Read (std::vector< int16_t > &buffer, size_t size)
 
template<>
void Read (std::vector< int32_t > &buffer, size_t size)
 
template<>
void Read (std::vector< uint32_t > &buffer, size_t size)
 

Static Public Member Functions

static const std::string & GetError ()
 
static void SetError (const char *fmt,...)
 
static int IntSize (unsigned int x)
 

Static Private Member Functions

static void SwapByteOrder (int16_t &us)
 
static void SwapByteOrder (uint16_t &us)
 
static void SwapByteOrder (int32_t &us)
 
static void SwapByteOrder (uint32_t &ui)
 
static void SwapByteOrder (double &d)
 

Private Attributes

std::istream & stream
 
int64_t offset
 
Encoder encoder
 
std::vector< int32_t > buffer
 

Static Private Attributes

static std::string error_str
 

Detailed Description

LcfReader class.

Definition at line 35 of file reader_lcf.h.

Member Enumeration Documentation

◆ SeekMode

Defines the Seek start position for the Seek function.

Enumerator
FromStart 
FromEnd 
FromCurrent 

Definition at line 82 of file reader_lcf.h.

Constructor & Destructor Documentation

◆ LcfReader()

LcfReader::LcfReader ( std::istream &  filestream,
std::string  encoding = "" 
)

Constructs a new File Reader.

Parameters
filestreamalready opened filestream.
encodingname of the encoding.

Definition at line 20 of file reader_lcf.cpp.

References offset.

◆ ~LcfReader()

LcfReader::~LcfReader ( )

Destructor. Closes the opened file.

Definition at line 27 of file reader_lcf.cpp.

Member Function Documentation

◆ Encode()

void LcfReader::Encode ( std::string &  str)

Encodes a string to UTF-8 using the set encoding in the reader constructor.

Parameters
strto convert from encoding to UTF-8

Definition at line 295 of file reader_lcf.cpp.

References Encoder::Encode(), and encoder.

Referenced by ReadString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Eof()

bool LcfReader::Eof ( ) const

Checks if the end of the file has been reached.

Returns
If the end of file is reached.

Definition at line 196 of file reader_lcf.cpp.

References stream.

Referenced by Read0(), Struct< S >::ReadLcf(), and RawStruct< std::vector< RPG::EventCommand > >::ReadLcf().

+ Here is the caller graph for this function:

◆ GetError()

const std::string & LcfReader::GetError ( )
static

Returns the last set error.

Returns
Error Message.

Definition at line 291 of file reader_lcf.cpp.

References error_str.

◆ IntBuffer()

std::vector< int32_t > & LcfReader::IntBuffer ( )
inline
Returns
a buffer which can be reused for parsing

Definition at line 267 of file reader_lcf.h.

References buffer.

Referenced by RawStruct< RPG::EventCommand >::ReadLcf().

+ Here is the caller graph for this function:

◆ IntSize()

int LcfReader::IntSize ( unsigned int  x)
static

Calculates the size of a compressed integer.

Parameters
xthe integer.
Returns
the compressed size.

Definition at line 299 of file reader_lcf.cpp.

Referenced by IDReaderT< S, true >::IDSize(), Primitive< int32_t >::LcfSize(), RawStruct< RPG::EventCommand >::LcfSize(), RawStruct< RPG::MoveCommand >::LcfSize(), CountField< S, T >::LcfSize(), Struct< S >::LcfSize(), and SizeField< S, T >::LcfSize().

+ Here is the caller graph for this function:

◆ IsOk()

bool LcfReader::IsOk ( ) const

Checks if the file is readable and if no error occured.

Returns
true if the stream is okay.

Definition at line 192 of file reader_lcf.cpp.

References encoder, Encoder::IsOk(), and stream.

Referenced by LDB_Reader::Load(), LMT_Reader::Load(), LMU_Reader::Load(), and LSD_Reader::Load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Peek()

int LcfReader::Peek ( )

Returns the next char in the stream and doesn't advance the position.

Returns
next char in the buffer or EOF

Definition at line 239 of file reader_lcf.cpp.

References stream.

Referenced by RawStruct< std::vector< RPG::EventCommand > >::ReadLcf().

+ Here is the caller graph for this function:

◆ Read() [1/15]

template<>
void LcfReader::Read ( bool &  ref)

Definition at line 58 of file reader_lcf.cpp.

References ReadInt().

+ Here is the call graph for this function:

◆ Read() [2/15]

template<>
void LcfReader::Read ( double &  ref)

Definition at line 111 of file reader_lcf.cpp.

References Read(), and SwapByteOrder().

+ Here is the call graph for this function:

◆ Read() [3/15]

template<>
void LcfReader::Read ( int16_t &  ref)

Definition at line 73 of file reader_lcf.cpp.

References Read(), and SwapByteOrder().

+ Here is the call graph for this function:

◆ Read() [4/15]

template<>
void LcfReader::Read ( int32_t &  ref)

Definition at line 106 of file reader_lcf.cpp.

References ReadInt().

+ Here is the call graph for this function:

◆ Read() [5/15]

template<>
void LcfReader::Read ( int8_t &  ref)

Definition at line 63 of file reader_lcf.cpp.

References Read().

+ Here is the call graph for this function:

◆ Read() [6/15]

template<>
void LcfReader::Read ( std::vector< bool > &  buffer,
size_t  size 
)

Definition at line 117 of file reader_lcf.cpp.

References buffer, and Read().

+ Here is the call graph for this function:

◆ Read() [7/15]

template<>
void LcfReader::Read ( std::vector< int16_t > &  buffer,
size_t  size 
)

Definition at line 139 of file reader_lcf.cpp.

References buffer, FromCurrent, Data::items, Read(), Seek(), and SwapByteOrder().

+ Here is the call graph for this function:

◆ Read() [8/15]

template<>
void LcfReader::Read ( std::vector< int32_t > &  buffer,
size_t  size 
)

Definition at line 155 of file reader_lcf.cpp.

References buffer, FromCurrent, Data::items, Read(), Seek(), and SwapByteOrder().

+ Here is the call graph for this function:

◆ Read() [9/15]

template<class T >
void LcfReader::Read ( std::vector< T > &  buffer,
size_t  size 
)

Reads a vector of primitive type.

Parameters
buffervector to fill.
sizehow many bytes to read.

◆ Read() [10/15]

template<>
void LcfReader::Read ( std::vector< uint32_t > &  buffer,
size_t  size 
)

Definition at line 171 of file reader_lcf.cpp.

References buffer, FromCurrent, Data::items, Read(), Seek(), and SwapByteOrder().

+ Here is the call graph for this function:

◆ Read() [11/15]

template<>
void LcfReader::Read ( std::vector< uint8_t > &  buffer,
size_t  size 
)

Definition at line 128 of file reader_lcf.cpp.

References buffer, and Read().

+ Here is the call graph for this function:

◆ Read() [12/15]

template<class T >
void LcfReader::Read ( T &  ref)

Reads a primitive type.

Parameters
refreference to store result.

◆ Read() [13/15]

template<>
void LcfReader::Read ( uint32_t &  ref)

Definition at line 79 of file reader_lcf.cpp.

References Read(), and SwapByteOrder().

+ Here is the call graph for this function:

◆ Read() [14/15]

template<>
void LcfReader::Read ( uint8_t &  ref)

Definition at line 68 of file reader_lcf.cpp.

References Read().

+ Here is the call graph for this function:

◆ Read() [15/15]

void LcfReader::Read ( void *  ptr,
size_t  size,
size_t  nmemb 
)

Reads raw data from the stream (fread() wrapper).

Parameters
ptrpointer to buffer.
sizesize of each element.
nmembnumber of elements.

Definition at line 47 of file reader_lcf.cpp.

References Read0(), and Tell().

Referenced by Read(), RawStruct< RPG::Equipment >::ReadLcf(), RawStruct< RPG::EventCommand >::ReadLcf(), RawStruct< RPG::MoveCommand >::ReadLcf(), RawStruct< RPG::Parameters >::ReadLcf(), RawStruct< RPG::Rect >::ReadLcf(), Flags< S >::ReadLcf(), RawStruct< std::vector< RPG::EventCommand > >::ReadLcf(), Primitive< std::vector< T > >::ReadLcf(), Primitive< T >::ReadLcf(), and ReadString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Read0()

size_t LcfReader::Read0 ( void *  ptr,
size_t  size,
size_t  nmemb 
)

Reads raw data from the stream (fread() wrapper).

Parameters
ptrpointer to buffer.
sizesize of each element.
nmembnumber of elements.
Returns
number of elements read.

Definition at line 30 of file reader_lcf.cpp.

References Eof(), offset, and stream.

Referenced by Read(), and ReadInt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadInt()

int LcfReader::ReadInt ( )

Reads a compressed integer from the stream.

Returns
The decompressed integer.

Definition at line 84 of file reader_lcf.cpp.

References Read0(), and Tell().

Referenced by LDB_Reader::Load(), LMT_Reader::Load(), LMU_Reader::Load(), LSD_Reader::Load(), Read(), IDReaderT< S, true >::ReadID(), Primitive< int32_t >::ReadLcf(), RawStruct< RPG::EventCommand >::ReadLcf(), RawStruct< RPG::MoveCommand >::ReadLcf(), RawStruct< RPG::TreeMap >::ReadLcf(), and Struct< S >::ReadLcf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadString()

void LcfReader::ReadString ( std::string &  ref,
size_t  size 
)

Reads a string.

Parameters
sizestring length.
refreference to store result. Note: The string is converted to UTF-8.

Definition at line 186 of file reader_lcf.cpp.

References Encode(), and Read().

Referenced by LDB_Reader::Load(), LMT_Reader::Load(), LMU_Reader::Load(), LSD_Reader::Load(), RawStruct< RPG::EventCommand >::ReadLcf(), RawStruct< RPG::MoveCommand >::ReadLcf(), and Primitive< std::string >::ReadLcf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Seek()

void LcfReader::Seek ( size_t  pos,
SeekMode  mode = FromStart 
)

Moves the read pointer to a different position in the stream.

Parameters
posnew position.
modeseek mode.

Definition at line 200 of file reader_lcf.cpp.

References FromCurrent, FromEnd, FromStart, offset, and stream.

Referenced by Read(), Primitive< int32_t >::ReadLcf(), Struct< S >::ReadLcf(), RawStruct< std::vector< RPG::EventCommand > >::ReadLcf(), Primitive< T >::ReadLcf(), and Skip().

+ Here is the caller graph for this function:

◆ SetError()

void LcfReader::SetError ( const char *  fmt,
  ... 
)
static

Sets the error message of the Reader. This is not used by the Reader directly but by the classes that are using the Reader.

Parameters
fmterror message.

Definition at line 278 of file reader_lcf.cpp.

References error_str.

Referenced by LDB_Reader::Load(), LMT_Reader::Load(), LMU_Reader::Load(), LSD_Reader::Load(), LDB_Reader::LoadXml(), LMT_Reader::LoadXml(), LMU_Reader::LoadXml(), LSD_Reader::LoadXml(), LMU_Reader::Save(), LSD_Reader::Save(), LDB_Reader::Save(), LMT_Reader::Save(), LDB_Reader::SaveXml(), LMT_Reader::SaveXml(), LMU_Reader::SaveXml(), and LSD_Reader::SaveXml().

+ Here is the caller graph for this function:

◆ Skip()

void LcfReader::Skip ( const struct LcfReader::Chunk chunk_info)

Skips a chunk (seeks chunk_info.length bytes from the current stream position). In debug builds, dumps the content of the skipped chunk to stderr.

Parameters
chunk_infochunk that will be skipped.

Definition at line 273 of file reader_lcf.cpp.

References FromCurrent, LcfReader::Chunk::length, and Seek().

Referenced by RawStruct< RPG::Equipment >::ReadLcf(), and Struct< S >::ReadLcf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SwapByteOrder() [1/5]

void LcfReader::SwapByteOrder ( double &  d)
staticprivate

Converts a double to/from little-endian.

Parameters
ddouble to convert.

Definition at line 335 of file reader_lcf.cpp.

◆ SwapByteOrder() [2/5]

void LcfReader::SwapByteOrder ( int16_t &  us)
staticprivate

Converts a 16bit signed integer to/from little-endian.

Parameters
usinteger to convert.

Definition at line 338 of file reader_lcf.cpp.

Referenced by Read(), and SwapByteOrder().

+ Here is the caller graph for this function:

◆ SwapByteOrder() [3/5]

void LcfReader::SwapByteOrder ( int32_t &  us)
staticprivate

Converts a 32bit signed integer to/from little-endian.

Parameters
usinteger to convert.

Definition at line 343 of file reader_lcf.cpp.

References SwapByteOrder().

+ Here is the call graph for this function:

◆ SwapByteOrder() [4/5]

void LcfReader::SwapByteOrder ( uint16_t &  us)
staticprivate

Converts a 16bit unsigned integer to/from little-endian.

Parameters
usinteger to convert.

Definition at line 333 of file reader_lcf.cpp.

◆ SwapByteOrder() [5/5]

void LcfReader::SwapByteOrder ( uint32_t &  ui)
staticprivate

Converts a 32bit unsigned integer to/from little-endian.

Parameters
uiinteger to convert.

Definition at line 334 of file reader_lcf.cpp.

◆ Tell()

uint32_t LcfReader::Tell ( )

Returns the current position of the read pointer in the stream.

Returns
current location in the stream.

Definition at line 228 of file reader_lcf.cpp.

References offset.

Referenced by Read(), ReadInt(), Primitive< int32_t >::ReadLcf(), Struct< S >::ReadLcf(), RawStruct< std::vector< RPG::EventCommand > >::ReadLcf(), RawStruct< std::vector< RPG::MoveCommand > >::ReadLcf(), and Primitive< T >::ReadLcf().

+ Here is the caller graph for this function:

Member Data Documentation

◆ buffer

std::vector<int32_t> LcfReader::buffer
private

A temporary buffer to be used in parsing

Definition at line 229 of file reader_lcf.h.

Referenced by IntBuffer(), and Read().

◆ encoder

Encoder LcfReader::encoder
private

The internal Encoder

Definition at line 227 of file reader_lcf.h.

Referenced by Encode(), and IsOk().

◆ error_str

std::string LcfReader::error_str
staticprivate

Contains the last set error.

Definition at line 225 of file reader_lcf.h.

Referenced by GetError(), and SetError().

◆ offset

int64_t LcfReader::offset
private

Cached file stream offset

Definition at line 223 of file reader_lcf.h.

Referenced by LcfReader(), Read0(), Seek(), and Tell().

◆ stream

std::istream& LcfReader::stream
private

File-stream managed by this Reader.

Definition at line 221 of file reader_lcf.h.

Referenced by Eof(), IsOk(), Peek(), Read0(), and Seek().


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