liblcf
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 (const char *filename, std::string encoding="")
 
 LcfReader (const std::string &filename, std::string encoding="")
 
 ~LcfReader ()
 
void Close ()
 
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 ()
 
bool Ungetch (uint8_t ch)
 
void Skip (const struct LcfReader::Chunk &chunk_info)
 
std::string Encode (const std::string &str_to_encode)
 
template<>
void Read (bool &ref)
 
template<>
void Read (uint8_t &ref)
 
template<>
void Read (int16_t &ref)
 
template<>
void Read (uint32_t &ref)
 
template<>
void Read (int &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< 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 (uint32_t &ui)
 
static void SwapByteOrder (double &d)
 

Private Attributes

std::string filename
 
std::string encoding
 
FILE * stream
 

Static Private Attributes

static std::string error_str
 

Detailed Description

LcfReader class.

Definition at line 30 of file reader_lcf.h.

Member Enumeration Documentation

Defines the Seek start position for the Seek function.

Enumerator
FromStart 
FromEnd 
FromCurrent 

Definition at line 90 of file reader_lcf.h.

Constructor & Destructor Documentation

LcfReader::LcfReader ( const char *  filename,
std::string  encoding = "" 
)

Constructs a new File Reader.

Parameters
filenamefile to open.
encodingname of the encoding.

Definition at line 18 of file reader_lcf.cpp.

LcfReader::LcfReader ( const std::string &  filename,
std::string  encoding = "" 
)

Constructs a new File Reader.

Parameters
filenamefile to open.
encodingname of the encoding.

Definition at line 25 of file reader_lcf.cpp.

LcfReader::~LcfReader ( )

Destructor. Closes the opened file.

Definition at line 32 of file reader_lcf.cpp.

References Close().

+ Here is the call graph for this function:

Member Function Documentation

void LcfReader::Close ( )

Closes the opened file.

Definition at line 36 of file reader_lcf.cpp.

References stream.

Referenced by ~LcfReader().

+ Here is the caller graph for this function:

std::string LcfReader::Encode ( const std::string &  str_to_encode)

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

Parameters
str_to_encodestring to encode.
Returns
UTF-8 version of string.

Definition at line 251 of file reader_lcf.cpp.

References encoding, and ReaderUtil::Recode().

Referenced by ReadString().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 174 of file reader_lcf.cpp.

References stream.

Referenced by Read0(), and Struct< S >::ReadLcf().

+ Here is the caller graph for this function:

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

Returns the last set error.

Returns
Error Message.

Definition at line 247 of file reader_lcf.cpp.

References error_str.

int LcfReader::IntSize ( unsigned int  x)
static

Calculates the size of a compressed integer.

Parameters
xthe integer.
Returns
the compressed size.

Definition at line 255 of file reader_lcf.cpp.

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

+ Here is the caller graph for this function:

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 170 of file reader_lcf.cpp.

References stream.

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

+ Here is the caller graph for this function:

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

Definition at line 61 of file reader_lcf.cpp.

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

Definition at line 66 of file reader_lcf.cpp.

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

Definition at line 71 of file reader_lcf.cpp.

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

Definition at line 77 of file reader_lcf.cpp.

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

Definition at line 98 of file reader_lcf.cpp.

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

Definition at line 103 of file reader_lcf.cpp.

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

Definition at line 109 of file reader_lcf.cpp.

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 52 of file reader_lcf.cpp.

References Read0().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 120 of file reader_lcf.cpp.

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

Reads a primitive type.

Parameters
refreference to store result.
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.
template<>
void LcfReader::Read ( std::vector< int16_t > &  buffer,
size_t  size 
)

Definition at line 131 of file reader_lcf.cpp.

References Data::items.

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

Definition at line 147 of file reader_lcf.cpp.

References Data::items.

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 42 of file reader_lcf.cpp.

References Eof(), and stream.

Referenced by Read(), and ReadInt().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int LcfReader::ReadInt ( )

Reads a compressed integer from the stream.

Returns
The decompressed integer.

Definition at line 82 of file reader_lcf.cpp.

References Read0().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 162 of file reader_lcf.cpp.

References Encode(), and Read().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 178 of file reader_lcf.cpp.

References FromCurrent, FromEnd, FromStart, and stream.

Referenced by RawStruct< std::vector< RPG::EventCommand > >::ReadLcf(), Primitive< int >::ReadLcf(), and Skip().

+ Here is the caller graph for this function:

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 234 of file reader_lcf.cpp.

References error_str.

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

+ Here is the caller graph for this function:

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 229 of file reader_lcf.cpp.

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

Referenced by Struct< S >::ReadLcf().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void LcfReader::SwapByteOrder ( int16_t &  us)
staticprivate

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

Parameters
usinteger to convert.

Definition at line 294 of file reader_lcf.cpp.

void LcfReader::SwapByteOrder ( uint16_t &  us)
staticprivate

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

Parameters
usinteger to convert.

Definition at line 289 of file reader_lcf.cpp.

void LcfReader::SwapByteOrder ( uint32_t &  ui)
staticprivate

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

Parameters
uiinteger to convert.

Definition at line 290 of file reader_lcf.cpp.

void LcfReader::SwapByteOrder ( double &  d)
staticprivate

Converts a double to/from little-endian.

Parameters
ddouble to convert.

Definition at line 291 of file reader_lcf.cpp.

uint32_t LcfReader::Tell ( )

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

Returns
current location in the stream.

Definition at line 194 of file reader_lcf.cpp.

References stream.

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

+ Here is the caller graph for this function:

bool LcfReader::Ungetch ( uint8_t  ch)

Puts a character (ch) back into the stream. This should usually be the last read one.

Parameters
chchar that will be readded to the stream.
Returns
true if the operation was successful.

Definition at line 198 of file reader_lcf.cpp.

References stream.

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

+ Here is the caller graph for this function:

Member Data Documentation

std::string LcfReader::encoding
private

Name of the encoding.

Definition at line 231 of file reader_lcf.h.

Referenced by Encode().

std::string LcfReader::error_str
staticprivate

Contains the last set error.

Definition at line 235 of file reader_lcf.h.

Referenced by GetError(), and SetError().

std::string LcfReader::filename
private

Name of the file that is associated with the stream.

Definition at line 229 of file reader_lcf.h.

FILE* LcfReader::stream
private

File-stream managed by this Reader.

Definition at line 233 of file reader_lcf.h.

Referenced by Close(), Eof(), IsOk(), Read0(), Seek(), Tell(), and Ungetch().


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