xoreos
0.0.5
|
A simple streaming file reading class. More...
#include <readfile.h>
Public Member Functions | |
ReadFile () | |
ReadFile (const UString &fileName) | |
~ReadFile () | |
bool | open (const UString &fileName) |
Try to open the file with the given fileName. More... | |
void | close () |
Close the file, if open. More... | |
bool | isOpen () const |
Checks if the object opened a file successfully. More... | |
bool | eos () const |
Returns true if a read failed because the stream has been reached. More... | |
size_t | pos () const |
Obtains the current value of the stream position indicator of the stream. More... | |
size_t | size () const |
Obtains the total size of the stream, measured in bytes. More... | |
size_t | seek (ptrdiff_t offset, Origin whence=kOriginBegin) |
Sets the stream position indicator for the stream. More... | |
size_t | read (void *dataPtr, size_t dataSize) |
Read data from the stream. More... | |
Public Member Functions inherited from Common::SeekableReadStream | |
SeekableReadStream () | |
~SeekableReadStream () | |
virtual size_t | skip (ptrdiff_t offset) |
Skip the specified number of bytes, adding that offset to the current position in the stream. More... | |
Public Member Functions inherited from Common::ReadStream | |
ReadStream () | |
virtual | ~ReadStream () |
byte | readByte () |
Read an unsigned byte from the stream and return it. More... | |
FORCEINLINE int8 | readSByte () |
Read a signed byte from the stream and return it. More... | |
uint32 | readChar () |
Reads the next character from stream and returns it as an unsigned char cast to an uint32, or kEOF on end of file or error. More... | |
uint16 | readUint16LE () |
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it. More... | |
uint32 | readUint32LE () |
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it. More... | |
uint64 | readUint64LE () |
Read an unsigned 64-bit word stored in little endian (LSB first) order from the stream and return it. More... | |
uint16 | readUint16BE () |
Read an unsigned 16-bit word stored in big endian (MSB first) order from the stream and return it. More... | |
uint32 | readUint32BE () |
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it. More... | |
uint64 | readUint64BE () |
Read an unsigned 64-bit word stored in big endian (MSB first) order from the stream and return it. More... | |
FORCEINLINE int16 | readSint16LE () |
Read a signed 16-bit word stored in little endian (LSB first) order from the stream and return it. More... | |
FORCEINLINE int32 | readSint32LE () |
Read a signed 32-bit word stored in little endian (LSB first) order from the stream and return it. More... | |
FORCEINLINE int64 | readSint64LE () |
Read a signed 64-bit word stored in little endian (LSB first) order from the stream and return it. More... | |
FORCEINLINE int16 | readSint16BE () |
Read a signed 16-bit word stored in big endian (MSB first) order from the stream and return it. More... | |
FORCEINLINE int32 | readSint32BE () |
Read a signed 32-bit word stored in big endian (MSB first) order from the stream and return it. More... | |
FORCEINLINE int64 | readSint64BE () |
Read a signed 64-bit word stored in big endian (MSB first) order from the stream and return it. More... | |
FORCEINLINE float | readIEEEFloatLE () |
Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it. More... | |
FORCEINLINE float | readIEEEFloatBE () |
Read a 32-bit IEEE float stored in big endian (MSB first) order from the stream and return it. More... | |
FORCEINLINE double | readIEEEDoubleLE () |
Read a 64-bit IEEE double stored in little endian (LSB first) order from the stream and return it. More... | |
FORCEINLINE double | readIEEEDoubleBE () |
Read a 64-bit IEEE double stored in big endian (MSB first) order from the stream and return it. More... | |
MemoryReadStream * | readStream (size_t dataSize) |
Read the specified amount of data into a new[]'ed buffer which then is wrapped into a MemoryReadStream. More... | |
Protected Attributes | |
std::FILE * | _handle |
The actual file handle. More... | |
size_t | _size |
The file's size. More... | |
Additional Inherited Members | |
Public Types inherited from Common::SeekableReadStream | |
enum | Origin { kOriginBegin = 0, kOriginCurrent = 1, kOriginEnd = 2, kOriginMAX } |
The position a seeking offset takes as a base. More... | |
Static Public Member Functions inherited from Common::SeekableReadStream | |
static size_t | evalSeek (ptrdiff_t offset, Origin whence, size_t pos, size_t begin, size_t size) |
Evaluate the seek offset relative to whence into a position from the beginning. More... | |
Static Public Attributes inherited from Common::ReadStream | |
static const uint32 | kEOF = 0xFFFFFFFF |
Return value for end-of-file. More... | |
static const size_t | kSizeInvalid = SIZE_MAX |
static const size_t | kPositionInvalid = SIZE_MAX |
A simple streaming file reading class.
Definition at line 40 of file readfile.h.
Common::ReadFile::ReadFile | ( | ) |
Definition at line 34 of file readfile.cpp.
Common::ReadFile::ReadFile | ( | const UString & | fileName | ) |
Definition at line 37 of file readfile.cpp.
References Common::UString::c_str(), and open().
Common::ReadFile::~ReadFile | ( | ) |
Definition at line 42 of file readfile.cpp.
References close().
void Common::ReadFile::close | ( | ) |
Close the file, if open.
Definition at line 84 of file readfile.cpp.
References _handle, _size, and Common::ReadStream::kSizeInvalid.
Referenced by open(), and ~ReadFile().
|
virtual |
Returns true if a read failed because the stream has been reached.
For a SeekableReadStream, it is cleared by a successful seek.
Implements Common::ReadStream.
Definition at line 96 of file readfile.cpp.
References _handle.
bool Common::ReadFile::isOpen | ( | ) | const |
Checks if the object opened a file successfully.
Definition at line 92 of file readfile.cpp.
References _handle.
bool Common::ReadFile::open | ( | const UString & | fileName | ) |
Try to open the file with the given fileName.
fileName | the name of the file to open |
Definition at line 61 of file readfile.cpp.
References _handle, _size, Common::UString::c_str(), close(), Common::getInitialSize(), Common::Platform::kFileModeRead, Common::Platform::openFile(), and warning().
Referenced by Aurora::TalkTable_TLK::getLanguageID(), Common::ConfigManager::load(), Engines::GameInstanceEngine::probe(), ReadFile(), Engines::KotOR::Version::readFile(), and Engines::NWN::Version::readFile().
|
virtual |
Obtains the current value of the stream position indicator of the stream.
Implements Common::SeekableReadStream.
Definition at line 103 of file readfile.cpp.
References _handle, and Common::ReadStream::kPositionInvalid.
Referenced by seek().
|
virtual |
Read data from the stream.
Subclasses must implement this method; all other read methods are implemented using it.
dataPtr | pointer to a buffer into which the data is read. |
dataSize | number of bytes to be read. |
Implements Common::ReadStream.
Definition at line 134 of file readfile.cpp.
References _handle.
Referenced by Engines::KotOR::Version::readFile(), and Engines::NWN::Version::readFile().
|
virtual |
Sets the stream position indicator for the stream.
The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence. If whence is set to kOriginBegin, kOriginCurrent, or kOriginEnd, the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively. A successful call to the seek() method clears the end-of-file indicator for the stream.
On error, or when trying to seek outside the stream, a kSeekError exception is thrown.
offset | the relative offset in bytes. |
whence | the seek reference: kOriginBegin, kOriginCurrent or kOriginEnd. |
Implements Common::SeekableReadStream.
Definition at line 114 of file readfile.cpp.
References _handle, _size, Common::SeekableReadStream::kOriginMAX, Common::kSeekError, and pos().
|
virtual |
Obtains the total size of the stream, measured in bytes.
If this value is unknown or can not be computed, kSizeInvalid is returned.
Implements Common::SeekableReadStream.
Definition at line 110 of file readfile.cpp.
References _size.
Referenced by Engines::KotOR::Version::readFile(), and Engines::NWN::Version::readFile().
|
protected |
|
protected |