Gorgon Game Engine
Reader Class Referenceabstract

This class allows resource objects to read data from a stream. More...

Inheritance diagram for Reader:
[legend]

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...
 

Detailed Description

This class allows resource objects to read data from a stream.

It provides functionality to read data platform independently.

Constructor & Destructor Documentation

◆ Reader()

Reader ( )

◆ ~Reader()

virtual ~Reader ( )
virtual

Member Function Documentation

◆ close()

virtual void close ( )
protectedpure virtual

This function should close the stream.

The pointer will be unset by Reader class

Implemented in FileReader.

◆ EatChunk() [1/2]

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.

◆ EatChunk() [2/2]

void EatChunk ( long  size)

Removes a chunk of data with the given size from the stream.

References ASSERT, Reader::IsGood(), and Reader::stream.

◆ GetStream()

std::istream& GetStream ( )

This should be last resort, use if the actual stream is needed.

References ASSERT, and Reader::stream.

◆ IsFailed()

bool IsFailed ( ) const

Checks if the stream is open and it can be read from.

References Reader::stream.

◆ IsGood()

bool IsGood ( ) const

Checks if the stream is open and it can be read from.

References Reader::stream.

◆ IsOpen()

bool IsOpen ( ) const

Checks if the stream is open.

References Reader::stream.

◆ KeepOpen()

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.

◆ NoLongerNeeded()

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.

◆ Open()

void Open ( )

Opens the reader. If this operation fails, it will throw LoadError.

References ASSERT, Reader::open(), and Reader::stream.

◆ open()

virtual bool open ( bool  thrw)
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.

◆ ReadArray()

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.

Parameters
datais the data to be read from the file
sizeis the number of elements to be read

References ASSERT, Reader::IsGood(), and Reader::stream.

◆ ReadBool()

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.

◆ ReadChunkSize()

unsigned long ReadChunkSize ( )

Reads chunk size from a stream.

References ASSERT, Reader::IsGood(), Reader::ReadUInt32(), and Reader::stream.

◆ ReadCommonChunk()

bool ReadCommonChunk ( Base self,
GID::Type  gid,
unsigned long  size 
)

◆ ReadDouble()

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.

◆ ReadEnum32()

E_ ReadEnum32 ( )

Reads an enumeration as 32-bit integer from the stream.

References ASSERT, Reader::IsGood(), and Reader::stream.

◆ ReadFloat()

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.

◆ ReadGID()

GID::Type ReadGID ( )

Reads a GID from the given stream.

References ASSERT, Reader::IsGood(), Reader::ReadUInt32(), and Reader::stream.

◆ ReadGuid()

SGuid ReadGuid ( )

Reads a GUID from the given stream.

References ASSERT, Reader::IsGood(), Gorgon::IO::ReadGuid(), and Reader::stream.

◆ ReadInt16()

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.

◆ ReadInt32()

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.

◆ ReadInt8()

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.

◆ ReadPoint()

Geometry::Point ReadPoint ( )

Reads a Point from the given stream.

References ASSERT, Reader::IsGood(), Gorgon::IO::ReadPoint(), and Reader::stream.

◆ ReadPointf()

Geometry::Point ReadPointf ( )

Reads a Pointf from the given stream.

References ASSERT, Reader::IsGood(), Gorgon::IO::ReadPointf(), and Reader::stream.

◆ ReadRGBA()

Graphics::RGBA ReadRGBA ( )

Reads a RGBA color, R will be read first.

References ASSERT, Reader::IsGood(), Gorgon::IO::ReadRGBA(), and Reader::stream.

◆ ReadRGBAf()

Graphics::RGBAf ReadRGBAf ( )

Reads a RGBAf color, R will be read first.

References ASSERT, Reader::IsGood(), Gorgon::IO::ReadRGBAf(), and Reader::stream.

◆ ReadSize()

Geometry::Size ReadSize ( )

Reads a Size from the given stream.

References ASSERT, Reader::IsGood(), Gorgon::IO::ReadSize(), and Reader::stream.

◆ ReadString() [1/2]

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.

◆ ReadString() [2/2]

std::string ReadString ( unsigned long  size)

Reads a string with the given size.

References ASSERT, Reader::IsGood(), Gorgon::IO::ReadString(), and Reader::stream.

◆ ReadUInt16()

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.

◆ ReadUInt32()

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.

◆ ReadUInt8()

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.

◆ Seek() [1/2]

void Seek ( const Mark pos)

Seeks to the given position.

References ASSERT, Reader::IsFailed(), Reader::stream, and Reader::Mark::Tell().

◆ Seek() [2/2]

void Seek ( unsigned long  pos)

Seeks to the given position.

References ASSERT, Reader::IsFailed(), and Reader::stream.

◆ Target()

Mark Target ( unsigned long  delta)

Creates mark to the the target that is delta distance from current point in file.

References Reader::Tell().

◆ Tell()

unsigned long Tell ( ) const

Tells the current position.

References ASSERT, Reader::IsFailed(), and Reader::stream.

◆ TryOpen()

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.

Member Data Documentation

◆ stream

std::istream* stream
protected

This is the stream that will be used to read data from.

Underlying readers can have specialized copies of this member.


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