FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::RawData Class Reference

Used to access diffrent kinds of data. More...

#include <rawdata.h>

+ Collaboration diagram for FIFE::RawData:

Public Member Functions

 RawData (RawDataSource *datasource)
 
virtual ~RawData ()
 
std::vector< uint8_t > getDataInBytes ()
 get the data as a vector of bytes This does not append a null terminator to the end More...
 
std::vector< std::string > getDataInLines ()
 get the data in distinct lines More...
 
uint32_t getDataLength () const
 get the complete datalength More...
 
uint32_t getCurrentIndex () const
 get the current index More...
 
void setIndex (uint32_t index)
 set the current index More...
 
void moveIndex (int32_t offset)
 move the current index More...
 
template<typename T >
readSingle ()
 helper-function More...
 
void readInto (uint8_t *buffer, size_t len)
 read len bytes into buffer More...
 
uint8_t read8 ()
 reads 1 byte More...
 
uint16_t read16Little ()
 reads a uint16_t littleEndian and converts them to the host-byteorder More...
 
uint32_t read32Little ()
 reads a uint16_t littleEndian and converts them to the host-byteorder More...
 
uint16_t read16Big ()
 reads a uint16_t bigEndian and converts them to the host-byteorder More...
 
uint32_t read32Big ()
 reads a uint16_t bigEndian and converts them to the host-byteorder More...
 
std::string readString (size_t len)
 read a string with len bytes, not assuming a terminating 0 Appends a null terminator character to the end More...
 
void read (std::string &outbuffer, int32_t size=-1)
 Reads all data into the buffer This does not append a null terminator to the end Created to especially fulfill python file interface requirements. More...
 
bool getLine (std::string &buffer)
 reads until a \n is encountered or no more data is available More...
 

Private Member Functions

template<typename T >
littleToHost (T value) const
 
template<typename T >
bigToHost (T value) const
 
template<typename T >
revert (T value) const
 
 RawData (const RawData &)
 
RawDataoperator= (const RawData &)
 

Static Private Member Functions

static bool littleEndian ()
 

Private Attributes

RawDataSourcem_datasource
 
size_t m_index_current
 

Detailed Description

Used to access diffrent kinds of data.

RawData uses RawDataSource to get the real data - that way the user doesn't have to know where the data comes from (real files, files inside archives etc.)

Definition at line 48 of file rawdata.h.

Constructor & Destructor Documentation

◆ RawData() [1/2]

FIFE::RawData::RawData ( RawDataSource datasource)

Definition at line 41 of file rawdata.cpp.

Referenced by revert().

+ Here is the caller graph for this function:

◆ ~RawData()

FIFE::RawData::~RawData ( )
virtual

Definition at line 45 of file rawdata.cpp.

References m_datasource.

◆ RawData() [2/2]

FIFE::RawData::RawData ( const RawData )
private

Member Function Documentation

◆ bigToHost()

template<typename T >
T FIFE::RawData::bigToHost ( value) const
inlineprivate

Definition at line 167 of file rawdata.h.

References littleEndian(), and revert().

Referenced by read16Big(), and read32Big().

+ Here is the caller graph for this function:

◆ getCurrentIndex()

uint32_t FIFE::RawData::getCurrentIndex ( ) const

get the current index

Returns
the current index

Definition at line 79 of file rawdata.cpp.

References m_index_current.

Referenced by getLine(), moveIndex(), FIFE::OGG_cb::read(), FIFE::ZipSource::readFileToIndex(), and FIFE::OGG_cb::tell().

+ Here is the caller graph for this function:

◆ getDataInBytes()

std::vector< uint8_t > FIFE::RawData::getDataInBytes ( )

get the data as a vector of bytes This does not append a null terminator to the end

Definition at line 49 of file rawdata.cpp.

References getDataLength(), and readInto().

◆ getDataInLines()

std::vector< std::string > FIFE::RawData::getDataInLines ( )

get the data in distinct lines

Definition at line 65 of file rawdata.cpp.

References getLine().

◆ getDataLength()

◆ getLine()

bool FIFE::RawData::getLine ( std::string &  buffer)

reads until a \n is encountered or no more data is available

Parameters
bufferif successfull the new string will be assigned to buffer
Returns
true if data was available, false otherwise (in that case buffer won't be touched)

Definition at line 154 of file rawdata.cpp.

References getCurrentIndex(), getDataLength(), and read8().

Referenced by getDataInLines(), and readSingle().

+ Here is the caller graph for this function:

◆ littleEndian()

bool FIFE::RawData::littleEndian ( )
staticprivate

Definition at line 166 of file rawdata.cpp.

References FIFE::_log, and FL_LOG.

Referenced by bigToHost(), littleToHost(), and operator=().

+ Here is the caller graph for this function:

◆ littleToHost()

template<typename T >
T FIFE::RawData::littleToHost ( value) const
inlineprivate

Definition at line 160 of file rawdata.h.

References littleEndian(), and revert().

Referenced by read16Little(), and read32Little().

+ Here is the caller graph for this function:

◆ moveIndex()

void FIFE::RawData::moveIndex ( int32_t  offset)

move the current index

Parameters
offsetthe offset
Exceptions
IndexOverflowif we move outside the datalength

Definition at line 90 of file rawdata.cpp.

References getCurrentIndex(), and setIndex().

Referenced by FIFE::ZipSource::readFileToIndex().

+ Here is the caller graph for this function:

◆ operator=()

RawData& FIFE::RawData::operator= ( const RawData )
inlineprivate

Definition at line 183 of file rawdata.h.

References littleEndian().

◆ read()

void FIFE::RawData::read ( std::string &  outbuffer,
int32_t  size = -1 
)

Reads all data into the buffer This does not append a null terminator to the end Created to especially fulfill python file interface requirements.

Definition at line 138 of file rawdata.cpp.

References getDataLength(), m_index_current, and readInto().

Referenced by readSingle().

+ Here is the caller graph for this function:

◆ read16Big()

uint16_t FIFE::RawData::read16Big ( )

reads a uint16_t bigEndian and converts them to the host-byteorder

Exceptions
IndexOverflow

Definition at line 118 of file rawdata.cpp.

References bigToHost().

Referenced by FIFE::LZSSDecoder::decode(), and readSingle().

+ Here is the caller graph for this function:

◆ read16Little()

uint16_t FIFE::RawData::read16Little ( )

reads a uint16_t littleEndian and converts them to the host-byteorder

Exceptions
IndexOverflow

Definition at line 108 of file rawdata.cpp.

References littleToHost().

Referenced by FIFE::ZipSource::readFileToIndex(), and readSingle().

+ Here is the caller graph for this function:

◆ read32Big()

uint32_t FIFE::RawData::read32Big ( )

reads a uint16_t bigEndian and converts them to the host-byteorder

Exceptions
IndexOverflow

Definition at line 123 of file rawdata.cpp.

References bigToHost().

Referenced by readSingle().

+ Here is the caller graph for this function:

◆ read32Little()

uint32_t FIFE::RawData::read32Little ( )

reads a uint16_t littleEndian and converts them to the host-byteorder

Exceptions
IndexOverflow

Definition at line 113 of file rawdata.cpp.

References littleToHost().

Referenced by FIFE::ZipSource::readFileToIndex(), and readSingle().

+ Here is the caller graph for this function:

◆ read8()

uint8_t FIFE::RawData::read8 ( )

reads 1 byte

Definition at line 104 of file rawdata.cpp.

Referenced by getLine(), and readSingle().

+ Here is the caller graph for this function:

◆ readInto()

void FIFE::RawData::readInto ( uint8_t *  buffer,
size_t  len 
)

read len bytes into buffer

Parameters
bufferthe data will be written into it
lenlen bytes will be written
Exceptions
IndexOverflowif currentindex + len > getCurrentIndex()

Definition at line 94 of file rawdata.cpp.

References FIFE::_log, FL_LOG, getDataLength(), m_datasource, m_index_current, and FIFE::RawDataSource::readInto().

Referenced by FIFE::LZSSDecoder::decode(), getDataInBytes(), FIFE::ZipSource::open(), FIFE::OGG_cb::read(), read(), readSingle(), and readString().

+ Here is the caller graph for this function:

◆ readSingle()

template<typename T >
T FIFE::RawData::readSingle ( )
inline

helper-function

reads sizeof(T) bytes - should be used with fixed-size datatypes like uint32_t, uint16_t, uint8_t etc.

Returns
the data

Definition at line 94 of file rawdata.h.

References getLine(), read(), read16Big(), read16Little(), read32Big(), read32Little(), read8(), readInto(), and readString().

◆ readString()

std::string FIFE::RawData::readString ( size_t  len)

read a string with len bytes, not assuming a terminating 0 Appends a null terminator character to the end

Parameters
lenthe stringlen
Returns
the string
Exceptions
IndexOverflow

Definition at line 128 of file rawdata.cpp.

References readInto().

Referenced by FIFE::AnimationLoader::isLoadable(), FIFE::ObjectLoader::isLoadable(), FIFE::MapLoader::isLoadable(), FIFE::AtlasLoader::isLoadable(), FIFE::AnimationLoader::load(), FIFE::ObjectLoader::load(), FIFE::MapLoader::load(), FIFE::AtlasLoader::load(), FIFE::AnimationLoader::loadMultiple(), FIFE::AtlasLoader::loadMultiple(), FIFE::ZipSource::readFileToIndex(), and readSingle().

+ Here is the caller graph for this function:

◆ revert()

template<typename T >
T FIFE::RawData::revert ( value) const
inlineprivate

Definition at line 174 of file rawdata.h.

References RawData().

Referenced by bigToHost(), and littleToHost().

+ Here is the caller graph for this function:

◆ setIndex()

void FIFE::RawData::setIndex ( uint32_t  index)

set the current index

Parameters
indexthe new index
Exceptions
IndexOverflowif index is >= getDataLength()

Definition at line 83 of file rawdata.cpp.

References getDataLength(), and m_index_current.

Referenced by moveIndex(), FIFE::ZipSource::open(), FIFE::ZipSource::readIndex(), and FIFE::OGG_cb::seek().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_datasource

RawDataSource* FIFE::RawData::m_datasource
private

Definition at line 157 of file rawdata.h.

Referenced by getDataLength(), readInto(), and ~RawData().

◆ m_index_current

size_t FIFE::RawData::m_index_current
private

Definition at line 158 of file rawdata.h.

Referenced by getCurrentIndex(), read(), readInto(), and setIndex().


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