![]() |
Gorgon Game Engine
|
This class allows resource objects to read data from a stream. More...
Classes | |
class | Mark |
Marks a target position in file. More... | |
Public Member Functions | |
Reader () | |
virtual | ~Reader () |
std::istream & | GetStream () |
This should be last resort, use if the actual stream is needed. More... | |
bool | IsFailed () const |
Checks if the stream is open and it can be read from. More... | |
bool | IsGood () const |
Checks if the stream is open and it can be read from. More... | |
bool | IsOpen () const |
Checks if the stream is open. More... | |
void | KeepOpen () |
Request reader to keep reading stream open. More... | |
void | NoLongerNeeded () |
Marks that this reader is no longer needed. More... | |
void | Open () |
Opens the reader. If this operation fails, it will throw LoadError. More... | |
bool | ReadCommonChunk (Base &self, GID::Type gid, unsigned long size) |
void | Seek (const Mark &pos) |
Seeks to the given position. More... | |
void | Seek (unsigned long pos) |
Seeks to the given position. More... | |
Mark | Target (unsigned long delta) |
Creates mark to the the target that is delta distance from current point in file. More... | |
unsigned long | Tell () const |
Tells the current position. More... | |
bool | TryOpen () |
Tries to open the stream, if it fails, this function returns false. More... | |
Protected Member Functions | |
virtual void | close ()=0 |
This function should close the stream. More... | |
virtual bool | open (bool thrw)=0 |
This function should open the stream and set stream member. More... | |
Protected Attributes | |
std::istream * | stream |
This is the stream that will be used to read data from. More... | |
Platform independent data readers | |
These functions allow platform independent data reading capability. In worst case, where the platform cannot be supported, they stop compilation instead of generating incorrectly working system. These functions might differ in encoding depending on the file version. Make sure a file is open before invoking these functions no runtime checks will be performed during release. | |
template<class E_ > | |
E_ | ReadEnum32 () |
Reads an enumeration as 32-bit integer from the stream. More... | |
long | ReadInt32 () |
Reads a 32-bit integer from the stream. More... | |
unsigned long | ReadUInt32 () |
Reads a 32-bit unsigned integer from the stream. More... | |
int | ReadInt16 () |
Reads a 16-bit integer from the stream. More... | |
unsigned | ReadUInt16 () |
Reads a 16-bit unsigned integer from the stream. More... | |
char | ReadInt8 () |
Reads an 8-bit integer from the stream. More... | |
Byte | ReadUInt8 () |
Reads an 8-bit unsigned integer from the stream. More... | |
float | ReadFloat () |
Reads a 32 bit IEEE floating point number from the file. More... | |
double | ReadDouble () |
Reads a 64 bit IEEE double precision floating point number from the file. More... | |
bool | ReadBool () |
Reads a boolean value. In resource 1.0, booleans are stored as 32bit integers. More... | |
Graphics::RGBA | ReadRGBA () |
Reads a RGBA color, R will be read first. More... | |
Graphics::RGBAf | ReadRGBAf () |
Reads a RGBAf color, R will be read first. More... | |
std::string | ReadString () |
Reads a string from a given stream. More... | |
std::string | ReadString (unsigned long size) |
Reads a string with the given size. More... | |
template<class T_ > | |
void | ReadArray (T_ *data, unsigned long size) |
Reads an array from the file. More... | |
GID::Type | ReadGID () |
Reads a GID from the given stream. More... | |
SGuid | ReadGuid () |
Reads a GUID from the given stream. More... | |
Geometry::Point | ReadPoint () |
Reads a Point from the given stream. More... | |
Geometry::Point | ReadPointf () |
Reads a Pointf from the given stream. More... | |
Geometry::Size | ReadSize () |
Reads a Size from the given stream. More... | |
unsigned long | ReadChunkSize () |
Reads chunk size from a stream. More... | |
void | EatChunk (long size) |
Removes a chunk of data with the given size from the stream. More... | |
void | EatChunk () |
Removes a chunk of data from the stream, the size will be read from the stream. More... | |
This class allows resource objects to read data from a stream.
It provides functionality to read data platform independently.
Reader | ( | ) |
|
virtual |
|
protectedpure virtual |
This function should close the stream.
The pointer will be unset by Reader class
Implemented in FileReader.
void EatChunk | ( | ) |
Removes a chunk of data from the stream, the size will be read from the stream.
References ASSERT, Reader::IsGood(), Reader::ReadUInt32(), and Reader::stream.
void EatChunk | ( | long | size | ) |
Removes a chunk of data with the given size from the stream.
References ASSERT, Reader::IsGood(), and Reader::stream.
std::istream& GetStream | ( | ) |
This should be last resort, use if the actual stream is needed.
References ASSERT, and Reader::stream.
bool IsFailed | ( | ) | const |
Checks if the stream is open and it can be read from.
References Reader::stream.
bool IsGood | ( | ) | const |
Checks if the stream is open and it can be read from.
References Reader::stream.
bool IsOpen | ( | ) | const |
Checks if the stream is open.
References Reader::stream.
void KeepOpen | ( | ) |
Request reader to keep reading stream open.
There is an internal counter that makes sure that the reader is closed when it is no longer needed.
void NoLongerNeeded | ( | ) |
Marks that this reader is no longer needed.
This action will decrement requests made to keep the stream open. If no object requires this reader, it is closed. Note that some readers cannot be reopened.
References Reader::close(), and Reader::stream.
void Open | ( | ) |
Opens the reader. If this operation fails, it will throw LoadError.
References ASSERT, Reader::open(), and Reader::stream.
|
protectedpure virtual |
This function should open the stream and set stream member.
If thrw is set to true and stream cannot be opened, a LoadError should be thrown. Otherwise this function is not allowed to throw.
Implemented in FileReader.
void ReadArray | ( | T_ * | data, |
unsigned long | size | ||
) |
Reads an array from the file.
Array type should be given a fixed size construct, otherwise a mismatch between binary formats will cause trouble.
data | is the data to be read from the file |
size | is the number of elements to be read |
References ASSERT, Reader::IsGood(), and Reader::stream.
bool ReadBool | ( | ) |
Reads a boolean value. In resource 1.0, booleans are stored as 32bit integers.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadBool(), and Reader::stream.
unsigned long ReadChunkSize | ( | ) |
Reads chunk size from a stream.
References ASSERT, Reader::IsGood(), Reader::ReadUInt32(), and Reader::stream.
double ReadDouble | ( | ) |
Reads a 64 bit IEEE double precision floating point number from the file.
This function only works on systems that have native 64 bit doubles.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadDouble(), and Reader::stream.
E_ ReadEnum32 | ( | ) |
Reads an enumeration as 32-bit integer from the stream.
References ASSERT, Reader::IsGood(), and Reader::stream.
float ReadFloat | ( | ) |
Reads a 32 bit IEEE floating point number from the file.
This function only works on systems that that have native 32 bit floats.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadFloat(), and Reader::stream.
GID::Type ReadGID | ( | ) |
Reads a GID from the given stream.
References ASSERT, Reader::IsGood(), Reader::ReadUInt32(), and Reader::stream.
SGuid ReadGuid | ( | ) |
Reads a GUID from the given stream.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadGuid(), and Reader::stream.
int ReadInt16 | ( | ) |
Reads a 16-bit integer from the stream.
An int is at least 16 bits, could be more however, only 2 bytes will be read from the stream
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadInt16(), and Reader::stream.
long ReadInt32 | ( | ) |
Reads a 32-bit integer from the stream.
A long is at least 32 bits, could be more however, only 4 bytes will be read from the stream
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadInt32(), and Reader::stream.
char ReadInt8 | ( | ) |
Reads an 8-bit integer from the stream.
A char is at least 8 bits, could be more however, only 1 byte will be read from the stream
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadInt8(), and Reader::stream.
Geometry::Point ReadPoint | ( | ) |
Reads a Point from the given stream.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadPoint(), and Reader::stream.
Geometry::Point ReadPointf | ( | ) |
Reads a Pointf from the given stream.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadPointf(), and Reader::stream.
Graphics::RGBA ReadRGBA | ( | ) |
Reads a RGBA color, R will be read first.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadRGBA(), and Reader::stream.
Graphics::RGBAf ReadRGBAf | ( | ) |
Reads a RGBAf color, R will be read first.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadRGBAf(), and Reader::stream.
Geometry::Size ReadSize | ( | ) |
Reads a Size from the given stream.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadSize(), and Reader::stream.
std::string ReadString | ( | ) |
Reads a string from a given stream.
Assumes the size of the string is appended before the string as 32-bit unsigned value.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadString(), and Reader::stream.
std::string ReadString | ( | unsigned long | size | ) |
Reads a string with the given size.
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadString(), and Reader::stream.
unsigned ReadUInt16 | ( | ) |
Reads a 16-bit unsigned integer from the stream.
An unsigned int is at least 32 bits, could be more however, only 2 bytes will be read from the stream
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadUInt16(), and Reader::stream.
unsigned long ReadUInt32 | ( | ) |
Reads a 32-bit unsigned integer from the stream.
An unsigned long is at least 32 bits, could be more however, only 4 bytes will be read from the stream
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadUInt32(), and Reader::stream.
Byte ReadUInt8 | ( | ) |
Reads an 8-bit unsigned integer from the stream.
A char is at least 8 bits, could be more however, only 1 byte will be read from the stream
References ASSERT, Reader::IsGood(), Gorgon::IO::ReadUInt8(), and Reader::stream.
void Seek | ( | const Mark & | pos | ) |
Seeks to the given position.
References ASSERT, Reader::IsFailed(), Reader::stream, and Reader::Mark::Tell().
void Seek | ( | unsigned long | pos | ) |
Seeks to the given position.
References ASSERT, Reader::IsFailed(), and Reader::stream.
Mark Target | ( | unsigned long | delta | ) |
Creates mark to the the target that is delta distance from current point in file.
References Reader::Tell().
unsigned long Tell | ( | ) | const |
Tells the current position.
References ASSERT, Reader::IsFailed(), and Reader::stream.
bool TryOpen | ( | ) |
Tries to open the stream, if it fails, this function returns false.
If this function returns true, read operations can be carried.
References Reader::open(), and Reader::stream.
|
protected |
This is the stream that will be used to read data from.
Underlying readers can have specialized copies of this member.