 |
Gorgon Game Engine
|
Go to the documentation of this file.
9 #include "../Utils/Assert.h"
10 #include "../Filesystem.h"
11 #include "../IO/Stream.h"
12 #include "../Geometry/Point.h"
14 namespace Gorgon {
namespace Resource {
85 Marker(
unsigned long pos) : pos(pos) { }
87 unsigned long pos = -1;
92 ASSERT(
stream==
nullptr,
"Stream is not closed by the opener");
118 return (
unsigned long)
stream->tellp();
126 stream->seekp((std::streampos)pos, std::ios::beg);
292 IO::WriteArray<T_>(*
stream, data, size);
335 ASSERT(base,
"Object cannot be nullptr");
346 ASSERT(base,
"Object cannot be nullptr");
379 ASSERT(pos>=marker.pos+4,
"Seeking before the start of the file.");
380 ASSERT(marker.pos<=pos,
"Marker is after the current position.");
382 auto size=pos-marker.pos-4;
399 virtual bool open(
bool thrw) = 0;
412 FileWriter(
const std::string &filename) : filename(filename) {
427 virtual bool open(
bool thrw)
override {
428 file.open(filename, std::ios::binary);
429 if(!file.is_open()) {
444 std::string filename;
This error is fired to a write operations.
Definition: Writer.h:19
WriteError(ErrorType number, const std::string &text)
A constructor to allow custom text for the error.
Definition: Writer.h:43
void WriteRGBAf(Graphics::RGBAf value)
Writes a RGBAf color, R will be saved first. RGBAf takes 4 x 4 bytes.
Definition: Writer.h:236
void WriteInt16(std::ostream &stream, int value)
Writes a 16-bit integer from the stream.
Definition: Stream.h:211
Marker WriteObjectStart(const Base *base)
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
Definition: Writer.h:334
void save(Writer &writer) const override
Definition: TintedObject.cpp:128
This class stores animations as a part of itself so that it can be moved around as a value rather tha...
Definition: Storage.h:21
~Marker()
Definition: Writer.h:79
void WriteString(const std::string &value)
Writes a string without its size.
Definition: Writer.h:276
This class represents a color information.
Definition: Color.h:91
std::string GetFilename(std::string path)
Returns the filename portion of a file path.
Definition: Filesystem.h:183
This object creates an object that has two subobjects drawn on top of each other.
Definition: StackedObject.h:116
constexpr uint32_t AsInteger() const
Returns the value of the GID as an integer.
Definition: GID.h:32
std::ostream & GetStream()
This should be last resort, use if the actual stream is needed.
Definition: Writer.h:96
basic_TextureAnimationProvider< Bitmap, basic_TextureAnimation, basic_AnimationFrame< Bitmap > > BitmapAnimationProvider
Definition: TextureAnimation.h:520
constexpr Type Null
Null resource.
Definition: GID.h:105
basic_StackedObjectProvider< RectangularAnimationProvider > StackedObjectProvider
Definition: StackedObject.h:357
std::ostream * stream
This is the stream that will be used to write data to.
Definition: Writer.h:403
void WriteInt32(std::ostream &stream, long value)
Writes a 32-bit integer to the stream.
Definition: Stream.h:197
void WriteStringWithSize(const std::string &value)
Writes a string from a given stream.
Definition: Writer.h:268
constexpr Type StackedObject
Definition: GID.h:250
void SaveAnimation(Writer &writer, const Graphics::RectangularAnimationProvider &object)
Saves a given generic rectangular animation as resource.
Definition: Resource.cpp:22
void SetTop(A_ *value)
Sets the top provider, ownership semantics will not be changed.
Definition: StackedObject.h:225
void WriteBool(std::ostream &stream, bool value)
Writes a boolean value. In resource 1.0, booleans are stored as 32bit integers.
Definition: Stream.h:256
Marker(Marker &&other)
Definition: Writer.h:67
std::enable_if< std::is_same< F_, float >::value, void >::type WritePointf(std::ostream &stream, Geometry::Pointf p)
Saves the point as two consecutive floats. This function will not work if float type is double.
Definition: Stream.h:321
void WriteChunkHeader(GID::Type type, unsigned long size)
Writes the header of a chunk.
Definition: Writer.h:364
void WritePointf(Geometry::Pointf value)
Writes a point to the stream, point takes 2 x 4 bytes.
Definition: Writer.h:251
void WriteUInt16(std::ostream &stream, unsigned value)
Writes a 16-bit unsigned integer from the stream.
Definition: Stream.h:218
static void SaveThis(Writer &writer, const Graphics::IStackedObjectProvider &provider)
Definition: StackedObject.cpp:151
void SetBottom(A_ *value)
Sets the bottom provider, ownership semantics will not be changed.
Definition: StackedObject.h:233
void WriteEnum32(std::ostream &stream, E_ v)
Writes an enumeration as a 32-bit integer.
Definition: Stream.h:191
Allows data to be written to a file.
Definition: Writer.h:409
void Close()
Definition: Writer.h:108
Represents a four channel 32 bit float per channel color information.
Definition: Color.h:373
constexpr Type Image
Image resource.
Definition: GID.h:149
Marker WriteObjectStart(const Base &base)
Writes the start of an object. Should have a matching WriteEnd with the returned marker.
Definition: File.cpp:211
virtual bool open(bool thrw)=0
This function should open the stream and set stream member.
std::string GetDirectory(std::string filepath)
Returns the directory portion of a file path.
Definition: Filesystem.h:167
void WriteChunkSize(unsigned long value)
Writes chunk size to the stream.
Definition: Writer.h:319
virtual bool open(bool thrw) override
This function should open the stream and set stream member.
Definition: Writer.h:427
constexpr Type TintedObject
Definition: GID.h:244
std::string Join(std::string path1, const std::string &path2)
Joins two given paths or a path and filename.
Definition: Filesystem.h:154
void WriteUInt32(unsigned long value)
Writes a 32-bit unsigned integer to the stream.
Definition: Writer.h:158
This object creates a scalable object from a graphic object.
Definition: TintedObject.h:124
ErrorType number
The type of loading error occurred.
Definition: Writer.h:48
Marker WriteObjectStart(const Base *base, GID::Type type)
Writes the start of an object.
Definition: Writer.h:345
void WriteGuid(const SGuid &value)
Writes a GUID to the given stream.
Definition: Writer.h:311
void WriteVector(std::ostream &stream, const std::vector< T_ > &data)
Writes a vector to the stream.
Definition: Stream.h:302
For ease of use in resource system.
Definition: TintedObject.h:11
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
bool IsGood() const
Checks if the stream is open and it can be written to.
Definition: Writer.h:104
void WriteRGBA(std::ostream &stream, Graphics::RGBA value)
Writes a RGBA color, R will be saved first.
Definition: Stream.h:261
A_ * GetTop() const
Returns the top component. Could return nullptr.
Definition: StackedObject.h:215
This is a tinted object resource.
Definition: TintedObject.h:16
Marker & operator=(Marker &&other)
Definition: Writer.h:72
A_ * GetBottom() const
Returns the bottom component. Could return nullptr.
Definition: StackedObject.h:220
Marker(const Marker &)=delete
virtual ~Writer()
Any writer implementation should close and set the stream to nullptr in destructor.
Definition: Writer.h:91
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
constexpr Type TintedObject_Props
Definition: GID.h:245
constexpr Type StackedObject_Props
Definition: GID.h:251
static const std::string ErrorStrings[3]
Strings for error codes.
Definition: Writer.h:51
Marker WriteChunkStart(GID::Type type)
Writes the start of a chunk. Should have a matching WriteEnd.
Definition: Writer.h:351
void WriteUInt32(std::ostream &stream, unsigned long value)
Writes a 32-bit unsigned integer from the stream.
Definition: Stream.h:204
This is a stacked object resource.
Definition: StackedObject.h:15
ITintedObjectProvider & MoveOutProvider() override
This function moves this animation provider into a new provider.
Definition: TintedObject.cpp:204
WriteError(ErrorType number=Unknown)
Regular constructor, creates error text to error number.
Definition: Writer.h:38
FileWriter(const std::string &filename)
Constructs a new object with the given filename.
Definition: Writer.h:412
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Collection is a container for reference typed objects.
Definition: Collection.h:21
This class represents a logical resource file.
Definition: File.h:53
void WriteArray(const T_ *data, unsigned long size)
Writes an array to the file.
Definition: Writer.h:288
This object contains an bitmap image.
Definition: Bitmap.h:25
constexpr Type Animation
Definition: GID.h:187
This class is the base for all Gorgon Resources.
Definition: Base.h:20
For ease of use in resource system.
Definition: StackedObject.h:10
void WriteUInt8(std::ostream &stream, Byte value)
Writes an 8-bit unsigned integer from the stream.
Definition: Stream.h:231
@ Unknown
The cause of the error cannot be determined.
Definition: Writer.h:26
basic_TintedObjectProvider< BitmapAnimationProvider > TintedBitmapAnimationProvider
Definition: TintedObject.h:280
void WriteSize(Geometry::Size value)
Writes a size to the stream, size takes 2 x 4 bytes.
Definition: Writer.h:259
void WriteRGBA(Graphics::RGBA value)
Writes a RGBA color, R will be saved first. RGBA takes 4 x 1 bytes.
Definition: Writer.h:228
long GetCount() const
Returns number of elements.
Definition: Collection.h:236
void WriteSize(std::ostream &stream, Geometry::Size s)
Saves the size as two consecutive 32bit integers.
Definition: Stream.h:327
This class represents a 2D point.
Definition: Point.h:32
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
basic_TintedObjectProvider< RectangularAnimationProvider > TintedObjectProvider
Definition: TintedObject.h:277
TintedObject()
Creates a new empty tinted object.
Definition: TintedObject.h:43
void WriteUInt16(unsigned value)
Writes a 16-bit unsigned integer to the stream.
Definition: Writer.h:176
void save(Writer &writer) const override
Definition: StackedObject.cpp:132
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
void WriteEnd(Marker &marker)
This function performs writes necessary to end a chunk that is represented by the marker.
Definition: Writer.h:373
RGBAf GetColor() const override
Returns the tint color.
Definition: TintedObject.h:183
virtual Graphics::RectangularAnimationStorage animmoveout() override
Definition: TintedObject.cpp:200
Geometry::Point GetOffset() const override
Returns the offset of the top image.
Definition: StackedObject.h:241
void WriteInt8(std::ostream &stream, char value)
Writes an 8-bit integer from the stream.
Definition: Stream.h:225
Gorgon::Animation::basic_Storage< RectangularAnimationProvider > RectangularAnimationStorage
Definition: Animations.h:374
void WriteInt16(int value)
Writes a 16-bit integer to the stream.
Definition: Writer.h:167
static void SaveThis(Writer &writer, const Graphics::ITintedObjectProvider &provider)
Definition: TintedObject.cpp:147
A_ * GetBase() const
Returns the base component. Could return nullptr.
Definition: TintedObject.h:178
void Seek(unsigned long pos)
Seeks to the given position.
Definition: Writer.h:122
@ NoData
There is no data to save.
Definition: Writer.h:33
void SetBase(A_ *value)
Sets the base provider, ownership semantics will not be changed.
Definition: TintedObject.h:193
void WriteInt32(long value)
Writes a 32-bit integer to the stream.
Definition: Writer.h:149
virtual void close()=0
This function should close the stream.
void WriteBool(bool value)
Writes a boolean value. In resource 1.0, booleans are stored as 32bit integers.
Definition: Writer.h:220
virtual void close() override
This function should close the stream.
Definition: Writer.h:423
void WriteDouble(std::ostream &stream, double value)
Writes a 64 bit IEEE double precision floating point number from the stream.
Definition: Stream.h:247
ErrorType
Error types.
Definition: Writer.h:23
Type to store GID information.
Definition: GID.h:23
This class represents a short globally unique identifier.
Definition: SGuid.h:22
Containers::Collection< Base > children
Child objects that this resource object have.
Definition: Base.h:162
void WriteEnum32(E_ value)
Writes an enumeration as 32-bit integer to the stream.
Definition: Writer.h:140
IStackedObjectProvider & MoveOutProvider() override
This function moves this animation provider into a new provider.
Definition: StackedObject.cpp:211
@ CannotOpenFile
The given file cannot be opened, probably its path does not exists or the operation is denied.
Definition: Writer.h:30
basic_StackedObjectProvider< BitmapAnimationProvider > StackedBitmapAnimationProvider
Definition: StackedObject.h:360
void WriteDouble(double value)
Writes a 64 bit IEEE double precision floating point number to the file.
Definition: Writer.h:212
std::string Canonical(const std::string &path)
Canonicalizes a given relative path.
Definition: Linux.cpp:94
void WriteUInt8(Byte value)
Writes an 8-bit unsigned integer to the stream.
Definition: Writer.h:194
void WriteGID(GID::Type value)
Writes a GID to the given stream.
Definition: Writer.h:303
void WritePoint(std::ostream &stream, Geometry::Point p)
Saves the point as two consecutive 32bit integers.
Definition: Stream.h:313
void WriteGuid(std::ostream &stream, const SGuid &value)
Writes a GUID from the given stream.
Definition: Stream.h:308
static StackedObject * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a stacked object resource from the file.
Definition: StackedObject.cpp:36
void WriteFloat(std::ostream &stream, float value)
Writes a 32 bit IEEE floating point number from the stream.
Definition: Stream.h:237
virtual Graphics::RectangularAnimationStorage animmoveout() override
Definition: StackedObject.cpp:207
unsigned long Tell() const
Tells the current position.
Definition: Writer.h:114
StackedObject()
Creates a new empty stacked object.
Definition: StackedObject.h:42
void WriteFloat(float value)
Writes a 32 bit IEEE floating point number to the file.
Definition: Writer.h:203
void WriteInt8(char value)
Writes an 8-bit integer to the stream.
Definition: Writer.h:185
void WriteString(std::ostream &stream, const std::string &value)
Writes a string without its size.
Definition: Stream.h:285
void WritePoint(Geometry::Point value)
Writes a point to the stream, point takes 2 x 4 bytes.
Definition: Writer.h:244
void WriteStringWithSize(std::ostream &stream, const std::string &value)
Writes a string from a given stream.
Definition: Stream.h:278
void WriteRGBAf(std::ostream &stream, Graphics::RGBAf value)
Writes a RGBAf color, R will be saved first.
Definition: Stream.h:269
void WriteVector(const std::vector< T_ > &data)
Writes a vector to the stream.
Definition: Writer.h:298
static TintedObject * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a tinted object resource from the file.
Definition: TintedObject.cpp:35