 |
Gorgon Game Engine
|
Go to the documentation of this file.
5 #include "../Geometry/Point.h"
6 #include "../Geometry/Size.h"
7 #include "../Geometry/Rectangle.h"
8 #include "../Geometry/Bounds.h"
9 #include "../Geometry/Margin.h"
13 namespace Gorgon {
namespace Resource {
20 using LoaderFn=std::function<
DataItem *(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize)>;
41 static_assert(std::is_same<T_, int>::value,
"Unknown data type.");
97 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
99 virtual std::string
ToString()
const override {
123 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
149 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
176 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
203 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
230 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
259 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
288 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
317 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
355 if(value && value!=&v)
363 if(value && value!=v)
386 return value!=
nullptr;
393 throw std::runtime_error(
"This data does not contain any object.");
395 return dynamic_cast<T_ &
>(*value);
398 static DataItem *
Load(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
408 Base *value =
nullptr;
419 inline int DataItem::Get<int>()
const {
420 auto &item=
dynamic_cast<const IntegerData&
>(*this);
426 inline float DataItem::Get<float>()
const {
427 auto &item=
dynamic_cast<const FloatData&
>(*this);
433 inline std::string DataItem::Get<std::string>()
const {
434 auto &item=
dynamic_cast<const TextData&
>(*this);
441 auto &item=
dynamic_cast<const PointData&
>(*this);
448 auto &item=
dynamic_cast<const PointfData&
>(*this);
455 auto &item=
dynamic_cast<const SizeData&
>(*this);
469 auto &item=
dynamic_cast<const BoundsData&
>(*this);
476 auto &item=
dynamic_cast<const MarginData&
>(*this);
483 auto &item=
dynamic_cast<const ObjectData&
>(*this);
485 return item.
Get<T_>();
std::ostream & operator<<(std::ostream &out, const DataItem &item)
Definition: DataItems.h:411
bool DeleteResource()
Safely deletes the resource.
Definition: Base.cpp:34
Definition: DataItems.h:183
This class represents boundaries of 2D objects.
Definition: Bounds.h:27
BoundsData(Geometry::Bounds v)
Definition: DataItems.h:270
IntegerData(int v)
Definition: DataItems.h:82
RectangleData(const std::string &name, Geometry::Rectangle v)
Definition: DataItems.h:243
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:193
FloatData(const std::string &name, float v)
Definition: DataItems.h:110
constexpr Type File
File.
Definition: GID.h:84
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:119
std::function< DataItem *(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)> LoaderFn
Definition: DataItems.h:20
ObjectData(const std::string &name, Base *v)
Definition: DataItems.h:336
T_ Left
Left margin.
Definition: Margin.h:167
MarginData(const std::string &name, Geometry::Margin v)
Definition: DataItems.h:301
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:114
bool IsSet() const
Definition: DataItems.h:385
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:166
void WriteStringWithSize(const std::string &value)
Writes a string from a given stream.
Definition: Writer.h:268
BoundsData()
Definition: DataItems.h:268
Base & Release()
Removes the object from this data without destroying it.
Definition: DataItems.h:378
constexpr Type Data_Rectangle
Definition: GID.h:174
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:319
SizeData(const std::string &name, Geometry::Size v)
Definition: DataItems.h:216
Definition: DataItems.h:104
ObjectData(Base &v)
Definition: DataItems.h:328
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:178
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:145
T_ X
X coordinate.
Definition: Point.h:368
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:50
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:220
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:225
PointData(Geometry::Point v)
Definition: DataItems.h:160
T_ X
X coordinate of the top left corner of this rectangle.
Definition: Rectangle.h:354
SizeData()
Definition: DataItems.h:212
FloatData(float v)
Definition: DataItems.h:108
T_ Height
Height of this size object.
Definition: Size.h:261
Definition: DataItems.h:237
virtual GID::Type GetGID() const =0
Returns the Gorgon ID of this data object.
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:232
constexpr Type Data_Pointf
Definition: GID.h:173
constexpr Type Data_Margin
Definition: GID.h:180
T_ Get() const
Definition: DataItems.h:69
Definition: DataItems.h:17
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:88
constexpr Type Data_Point
Definition: GID.h:172
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:345
DataImp(T_ v)
Definition: DataItems.h:67
T_ Width
Width of the rectangle.
Definition: Rectangle.h:360
void Set(Base &v)
Changes the object that this data holds. Once set, the data owns the object.
Definition: DataItems.h:354
IntegerData(const std::string &name, int v)
Definition: DataItems.h:84
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:151
std::string Name
The name of the data item.
Definition: DataItems.h:28
basic_Size< int > Size
Definition: Size.h:385
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:99
static void InitializeLoaders()
This function will initialize data loaders.
Definition: DataItems.cpp:9
Definition: DataItems.h:130
T_ Left
Left-most boundary.
Definition: Bounds.h:399
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:261
virtual ~ObjectData()
Definition: DataItems.h:340
T_ Top
Top margin.
Definition: Margin.h:170
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
basic_Margin< int > Margin
Definition: Margin.h:289
Marker WriteChunkStart(GID::Type type)
Writes the start of a chunk. Should have a matching WriteEnd.
Definition: Writer.h:351
virtual std::string ToString() const =0
Converts the contents of this data to string.
T_ & GetObject() const
Definition: DataItems.h:482
void Save(Writer &writer)
Saves this object into the given writer. The writer should be open prior to this call.
Definition: Base.cpp:57
Definition: DataItems.h:324
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:63
T_ & Get() const
Returns the item contained within this object.
Definition: DataItems.h:391
constexpr Type Data_Text
Definition: GID.h:169
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:79
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
basic_Point< int > Point
Definition: Point.h:598
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:171
static std::map< GID::Type, LoaderFn > DataLoaders
Data loaders that all data containing classes would use to load their children.
Definition: DataItems.h:58
FloatData()
Definition: DataItems.h:106
PointfData(Geometry::Pointf v)
Definition: DataItems.h:187
void Set(Base *v)
Changes the object that this data holds. Once set, the data owns the object.
Definition: DataItems.h:362
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:205
Definition: DataItems.h:63
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:140
SizeData(Geometry::Size v)
Definition: DataItems.h:214
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:310
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:276
This class is the base for all Gorgon Resources.
Definition: Base.h:20
void Set(T_ val)
Definition: DataItems.h:71
PointfData()
Definition: DataItems.h:185
Definition: DataItems.h:78
Definition: DataItems.h:210
PointData()
Definition: DataItems.h:158
void Unset()
Removes the object that this data holds.
Definition: DataItems.h:370
basic_Point< Float > Pointf
Definition: Point.h:601
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:22
basic_Bounds< int > Bounds
Definition: Bounds.h:722
Definition: DataItems.h:295
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:290
T_ Bottom
Bottom margin.
Definition: Margin.h:176
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
ObjectData()
Definition: DataItems.h:326
constexpr Type Data_Int
Definition: GID.h:170
Definition: Rectangle.h:11
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:129
void WriteEnd(Marker &marker)
This function performs writes necessary to end a chunk that is represented by the marker.
Definition: Writer.h:373
TextData(const std::string &name, const std::string &v)
Definition: DataItems.h:136
T_ Y
Y coordinate of the top left corner of this rectangle.
Definition: Rectangle.h:357
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:36
int value
Definition: DataItems.h:74
constexpr Type Data_Bounds
Definition: GID.h:179
T_ Right
Right-most boundary.
Definition: Bounds.h:405
T_ Right
Right margin.
Definition: Margin.h:173
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:147
Definition: DataItems.h:156
T_ Height
Height of the rectangle.
Definition: Rectangle.h:363
virtual ~DataItem()
Definition: DataItems.h:22
ObjectData(Base *v)
Definition: DataItems.h:334
T_ Bottom
Bottom-most boundary.
Definition: Bounds.h:408
MarginData(Geometry::Margin v)
Definition: DataItems.h:299
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:247
T_ Y
Y coordinate.
Definition: Point.h:371
void WriteInt32(long value)
Writes a 32-bit integer to the stream.
Definition: Writer.h:149
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:347
T_ Width
Width of this size object.
Definition: Size.h:258
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:125
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:93
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:198
BoundsData(const std::string &name, Geometry::Bounds v)
Definition: DataItems.h:272
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:95
MarginData()
Definition: DataItems.h:297
Type to store GID information.
Definition: GID.h:23
RectangleData()
Definition: DataItems.h:239
This class defines Margin of an object or an area.
Definition: Margin.h:22
TextData()
Definition: DataItems.h:132
constexpr Type Data_Size
Definition: GID.h:178
virtual void Save(Writer &writer) const
Saves the data item with header information to gorgon file.
Definition: DataItems.h:31
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:111
Definition: DataItems.h:266
TextData(std::string v)
Definition: DataItems.h:134
Represents a rectangle in a 2D space.
Definition: Rectangle.h:19
PointData(const std::string &name, Geometry::Point v)
Definition: DataItems.h:162
RectangleData(Geometry::Rectangle v)
Definition: DataItems.h:241
virtual GID::Type GetGID() const override
Returns the Gorgon ID of this data object.
Definition: DataItems.h:305
virtual std::string ToString() const override
Converts the contents of this data to string.
Definition: DataItems.h:400
PointfData(const std::string &name, Geometry::Pointf v)
Definition: DataItems.h:189
constexpr Type Data_Float
Definition: GID.h:171
static DataItem * Load(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Definition: DataItems.cpp:165
virtual void SaveValue(Writer &writer) const =0
Saves only the value of the data item to gorgon file.
IntegerData()
Definition: DataItems.h:80
const std::string & GetName() const
Returns the name of this object.
Definition: Base.h:61
T_ Get() const
Returns the contents of this data item to the requested type; use GetObject in order to get resource ...
Definition: DataItems.h:40
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:252
constexpr Type Data_Object
Definition: GID.h:181
virtual void SaveValue(Writer &writer) const override
Saves only the value of the data item to gorgon file.
Definition: DataItems.h:281
T_ Top
Top-most boundary.
Definition: Bounds.h:402
void WriteFloat(float value)
Writes a 32 bit IEEE floating point number to the file.
Definition: Writer.h:203
ObjectData(const std::string &name, Base &v)
Definition: DataItems.h:330