![]() |
Gorgon Game Engine
|
This class allows resource objects to save their data to a stream. More...
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... | |
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.
|
virtual |
Any writer implementation should close and set the stream to nullptr in destructor.
References ASSERT, and Writer::stream.
void Close | ( | ) |
References Writer::close(), and Writer::stream.
|
protectedpure virtual |
This function should close the stream.
The pointer will be unset by Writeer class
Implemented in FileWriter.
std::ostream& GetStream | ( | ) |
This should be last resort, use if the actual stream is needed.
References ASSERT, Writer::IsGood(), and Writer::stream.
bool IsGood | ( | ) | const |
Checks if the stream is open and it can be written to.
References Writer::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 WriteError should be thrown. Otherwise this function is not allowed to throw.
Implemented in FileWriter.
void Seek | ( | unsigned long | pos | ) |
Seeks to the given position.
References ASSERT, Writer::IsGood(), and Writer::stream.
unsigned long Tell | ( | ) | const |
Tells the current position.
References ASSERT, Writer::IsGood(), and Writer::stream.
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.
data | is the data to be written to the file |
size | is the number of elements to be read |
References ASSERT, Writer::IsGood(), and Writer::stream.
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().
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
void WriteChunkSize | ( | unsigned long | value | ) |
Writes chunk size to the stream.
References ASSERT, Writer::IsGood(), Writer::stream, and Writer::WriteUInt32().
Writes the start of a chunk. Should have a matching WriteEnd.
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().
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().
void WriteEnum32 | ( | E_ | value | ) |
Writes an enumeration as 32-bit integer to the stream.
References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteEnum32().
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().
void WriteGID | ( | GID::Type | value | ) |
Writes a GID to the given stream.
References Type::AsInteger(), ASSERT, Writer::IsGood(), Writer::stream, and Writer::WriteUInt32().
void WriteGuid | ( | const SGuid & | value | ) |
Writes a GUID to the given stream.
References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteGuid().
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().
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().
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().
Writer::Marker WriteObjectStart | ( | const Base & | base | ) |
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
References ASSERT, Base::GetGID(), Base::GetGuid(), Base::GetName(), Writer::IsGood(), Gorgon::Resource::GID::Name, Gorgon::Resource::GID::SGuid, Writer::stream, Writer::Tell(), Writer::WriteChunkSize(), Writer::WriteGID(), Writer::WriteGuid(), and Writer::WriteStringWithSize().
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.
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
References ASSERT, and Writer::WriteObjectStart().
Writes the start of an object.
Should have a matching WriteEnd with the returned marker. This variant allows a replacement GID.
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().
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().
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().
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().
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().
void WriteString | ( | const std::string & | value | ) |
Writes a string without its size.
References ASSERT, Writer::IsGood(), Writer::stream, and Gorgon::IO::WriteString().
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().
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().
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().
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().
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().
|
protected |
This is the stream that will be used to write data to.
Underlying writers can have specialized copies of this member.