Gorgon Game Engine
Writer Class Referenceabstract

This class allows resource objects to save their data to a stream. More...

Inheritance diagram for Writer:
[legend]

Classes

class  Marker
 

Public Member Functions

virtual ~Writer ()
 Any writer implementation should close and set the stream to nullptr in destructor. More...
 
void Close ()
 
std::ostream & GetStream ()
 This should be last resort, use if the actual stream is needed. More...
 
bool IsGood () const
 Checks if the stream is open and it can be written to. More...
 
void Seek (unsigned long pos)
 Seeks to the given position. More...
 
unsigned long Tell () const
 Tells the current position. More...
 
void WriteChunkHeader (GID::Type type, unsigned long size)
 Writes the header of a chunk. More...
 
Marker WriteChunkStart (GID::Type type)
 Writes the start of a chunk. Should have a matching WriteEnd. More...
 
void WriteEnd (Marker &marker)
 This function performs writes necessary to end a chunk that is represented by the marker. More...
 
Marker WriteObjectStart (const Base &base)
 Writes the start of an object. Should have a matching WriteEnd with the returned marker. More...
 
Marker WriteObjectStart (const Base &base, GID::Type type)
 Writes the start of an object. More...
 
Marker WriteObjectStart (const Base *base)
 Writes the start of an object. Should have a matching WriteEnd with the returned marker. More...
 
Marker WriteObjectStart (const Base *base, GID::Type type)
 Writes the start of an object. 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::ostream * stream
 This is the stream that will be used to write data to. 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_ >
void WriteEnum32 (E_ value)
 Writes an enumeration as 32-bit integer to the stream. More...
 
void WriteInt32 (long value)
 Writes a 32-bit integer to the stream. More...
 
void WriteUInt32 (unsigned long value)
 Writes a 32-bit unsigned integer to the stream. More...
 
void WriteInt16 (int value)
 Writes a 16-bit integer to the stream. More...
 
void WriteUInt16 (unsigned value)
 Writes a 16-bit unsigned integer to the stream. More...
 
void WriteInt8 (char value)
 Writes an 8-bit integer to the stream. More...
 
void WriteUInt8 (Byte value)
 Writes an 8-bit unsigned integer to the stream. More...
 
void WriteFloat (float value)
 Writes a 32 bit IEEE floating point number to the file. More...
 
void WriteDouble (double value)
 Writes a 64 bit IEEE double precision floating point number to the file. More...
 
void WriteBool (bool value)
 Writes a boolean value. In resource 1.0, booleans are stored as 32bit integers. More...
 
void WriteRGBA (Graphics::RGBA value)
 Writes a RGBA color, R will be saved first. RGBA takes 4 x 1 bytes. More...
 
void WriteRGBAf (Graphics::RGBAf value)
 Writes a RGBAf color, R will be saved first. RGBAf takes 4 x 4 bytes. More...
 
void WritePoint (Geometry::Point value)
 Writes a point to the stream, point takes 2 x 4 bytes. More...
 
void WritePointf (Geometry::Pointf value)
 Writes a point to the stream, point takes 2 x 4 bytes. More...
 
void WriteSize (Geometry::Size value)
 Writes a size to the stream, size takes 2 x 4 bytes. More...
 
void WriteStringWithSize (const std::string &value)
 Writes a string from a given stream. More...
 
void WriteString (const std::string &value)
 Writes a string without its size. More...
 
template<class T_ >
void WriteArray (const T_ *data, unsigned long size)
 Writes an array to the file. More...
 
template<class T_ >
void WriteVector (const std::vector< T_ > &data)
 Writes a vector to the stream. More...
 
void WriteGID (GID::Type value)
 Writes a GID to the given stream. More...
 
void WriteGuid (const SGuid &value)
 Writes a GUID to the given stream. More...
 
void WriteChunkSize (unsigned long value)
 Writes chunk size to the stream. More...
 

Detailed Description

This class allows resource objects to save their data to a stream.

It provides functionality to write data platform independently. This class also allows back and forth writing to easy writing Gorgon resources.

Constructor & Destructor Documentation

◆ ~Writer()

virtual ~Writer ( )
virtual

Any writer implementation should close and set the stream to nullptr in destructor.

References ASSERT, and Writer::stream.

Member Function Documentation

◆ Close()

void Close ( )

References Writer::close(), and Writer::stream.

◆ close()

virtual void close ( )
protectedpure virtual

This function should close the stream.

The pointer will be unset by Writeer class

Implemented in FileWriter.

◆ GetStream()

std::ostream& GetStream ( )

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

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

◆ IsGood()

bool IsGood ( ) const

Checks if the stream is open and it can be written to.

References Writer::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 WriteError should be thrown. Otherwise this function is not allowed to throw.

Implemented in FileWriter.

◆ Seek()

void Seek ( unsigned long  pos)

Seeks to the given position.

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

◆ Tell()

unsigned long Tell ( ) const

Tells the current position.

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

◆ WriteArray()

void WriteArray ( const T_ *  data,
unsigned long  size 
)

Writes an array to 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 written to the file
sizeis the number of elements to be read

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

◆ WriteBool()

void WriteBool ( bool  value)

Writes a boolean value. In resource 1.0, booleans are stored as 32bit integers.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteBool().

◆ WriteChunkHeader()

void WriteChunkHeader ( GID::Type  type,
unsigned long  size 
)

Writes the header of a chunk.

If the size of the chunk is hard to compute, it is possible to use WriteChunkStart

◆ WriteChunkSize()

void WriteChunkSize ( unsigned long  value)

Writes chunk size to the stream.

References ASSERT, Writer::IsGood(), Writer::stream, and Writer::WriteUInt32().

◆ WriteChunkStart()

Marker WriteChunkStart ( GID::Type  type)

Writes the start of a chunk. Should have a matching WriteEnd.

◆ WriteDouble()

void WriteDouble ( double  value)

Writes a 64 bit IEEE double precision floating point number to the file.

This function only works on systems that have native 64 bit doubles.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteDouble().

◆ WriteEnd()

void WriteEnd ( Marker marker)

This function performs writes necessary to end a chunk that is represented by the marker.

References ASSERT, Writer::IsGood(), Writer::Seek(), Writer::stream, Writer::Tell(), and Writer::WriteChunkSize().

◆ WriteEnum32()

void WriteEnum32 ( E_  value)

Writes an enumeration as 32-bit integer to the stream.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteEnum32().

◆ WriteFloat()

void WriteFloat ( float  value)

Writes a 32 bit IEEE floating point number to the file.

This function only works on systems that that have native 32 bit floats.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteFloat().

◆ WriteGID()

void WriteGID ( GID::Type  value)

Writes a GID to the given stream.

References Type::AsInteger(), ASSERT, Writer::IsGood(), Writer::stream, and Writer::WriteUInt32().

◆ WriteGuid()

void WriteGuid ( const SGuid value)

Writes a GUID to the given stream.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteGuid().

◆ WriteInt16()

void WriteInt16 ( int  value)

Writes a 16-bit integer to the stream.

An int is at least 16 bits, could be more however, only 2 bytes will be written to the stream

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteInt16().

◆ WriteInt32()

void WriteInt32 ( long  value)

Writes a 32-bit integer to the stream.

A long is at least 32 bits, could be more however, only 4 bytes will be written to the stream

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteInt32().

◆ WriteInt8()

void WriteInt8 ( char  value)

Writes an 8-bit integer to the stream.

A char is at least 8 bits, could be more however, only 1 byte will be written to the stream

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteInt8().

◆ WriteObjectStart() [1/4]

◆ WriteObjectStart() [2/4]

Writer::Marker WriteObjectStart ( const Base base,
GID::Type  type 
)

Writes the start of an object.

Should have a matching WriteEnd with the returned marker. This variant allows a replacement GID.

◆ WriteObjectStart() [3/4]

Marker WriteObjectStart ( const Base base)

Writes the start of an object. Should have a matching WriteEnd with the returned marker.

References ASSERT, and Writer::WriteObjectStart().

◆ WriteObjectStart() [4/4]

Marker WriteObjectStart ( const Base base,
GID::Type  type 
)

Writes the start of an object.

Should have a matching WriteEnd with the returned marker. This variant allows a replacement GID.

◆ WritePoint()

void WritePoint ( Geometry::Point  value)

Writes a point to the stream, point takes 2 x 4 bytes.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WritePoint().

◆ WritePointf()

void WritePointf ( Geometry::Pointf  value)

Writes a point to the stream, point takes 2 x 4 bytes.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WritePointf().

◆ WriteRGBA()

void WriteRGBA ( Graphics::RGBA  value)

Writes a RGBA color, R will be saved first. RGBA takes 4 x 1 bytes.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteRGBA().

◆ WriteRGBAf()

void WriteRGBAf ( Graphics::RGBAf  value)

Writes a RGBAf color, R will be saved first. RGBAf takes 4 x 4 bytes.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteRGBAf().

◆ WriteSize()

void WriteSize ( Geometry::Size  value)

Writes a size to the stream, size takes 2 x 4 bytes.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteSize().

◆ WriteString()

void WriteString ( const std::string &  value)

Writes a string without its size.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteString().

◆ WriteStringWithSize()

void WriteStringWithSize ( const std::string &  value)

Writes a string from a given stream.

The size of the string is appended before the string as 32-bit unsigned value.

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteStringWithSize().

◆ WriteUInt16()

void WriteUInt16 ( unsigned  value)

Writes a 16-bit unsigned integer to the stream.

An unsigned int is at least 32 bits, could be more however, only 2 bytes will be written to the stream

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteUInt16().

◆ WriteUInt32()

void WriteUInt32 ( unsigned long  value)

Writes a 32-bit unsigned integer to the stream.

An unsigned long is at least 32 bits, could be more however, only 4 bytes will be written to the stream

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteUInt32().

◆ WriteUInt8()

void WriteUInt8 ( Byte  value)

Writes an 8-bit unsigned integer to the stream.

A char is at least 8 bits, could be more however, only 1 byte will be written to the stream

References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteUInt8().

◆ WriteVector()

void WriteVector ( const std::vector< T_ > &  data)

Writes a vector to the stream.

Type of vector elements should be given a fixed size construct, otherwise a mismatch between binary formats will cause trouble.

References Writer::stream, and Gorgon::IO::WriteVector().

Member Data Documentation

◆ stream

std::ostream* stream
protected

This is the stream that will be used to write data to.

Underlying writers can have specialized copies of this member.


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