 |
Gorgon Game Engine
|
Go to the documentation of this file.
10 namespace Gorgon {
namespace Resource {
16 template <
class T_,
class R_,
int IND_>
17 void append(
const T_ &values,
const std::string &prefix,
const R_ &reflectionobj) {
18 Append(prefix+reflectionobj.Names[IND_], values.*(R_::template Member<IND_>::MemberPointer()) );
22 template <
class T_,
class R_,
int ...S_>
23 void append(
const T_ &values,
const std::string &prefix,
const R_ &reflectionobj,
TMP::Sequence<S_...>) {
24 char dummy[] ={0, (append<T_, R_, S_>(values, prefix, reflectionobj),
'\0')...};
27 template <
class T_,
class O_,
class R_,
int IND_>
28 typename std::enable_if<!std::is_base_of<Base, typename std::remove_pointer<O_>::type>::value,
void>::type
29 namedtransform(T_ &values,
const std::string &prefix,
const R_ &reflectionobj)
const {
30 values.*(R_::template Member<IND_>::MemberPointer())=
GetItem(prefix+reflectionobj.Names[IND_]).template Get<O_>();
33 template <
class T_,
class R_,
int ...S_>
34 void namedtransform(T_ &values,
const std::string &prefix,
const R_ &reflectionobj,
TMP::Sequence<S_...>)
const {
38 template <
class T_,
class O_,
class R_,
int IND_>
39 typename std::enable_if<std::is_base_of<Base, typename std::remove_pointer<O_>::type>::value,
void>::type
40 namedtransform(T_ &values,
const std::string &prefix,
const R_ &reflectionobj) {
41 values.*(R_::template Member<IND_>::MemberPointer())=&
GetItem(prefix+reflectionobj.Names[IND_]).template GetObject<typename std::remove_pointer<O_>::type>();
45 template <
class T_,
class O_,
class R_,
int IND_>
46 typename std::enable_if<!std::is_base_of<Base, typename std::remove_pointer<O_>::type>::value,
void>::type
47 namedtransform(T_ &values,
const std::string &prefix,
const R_ &reflectionobj) {
48 values.*(R_::template Member<IND_>::MemberPointer())=
GetItem(prefix+reflectionobj.Names[IND_]).template Get<O_>();
51 template <
class T_,
class R_,
int ...S_>
52 void namedtransform(T_ &values,
const std::string &prefix,
const R_ &reflectionobj,
TMP::Sequence<S_...>) {
69 template<
class T_,
class R_ =
typename T_::ReflectionType>
71 Append(values, reflectionobj);
78 template<
class T_,
class R_ =
typename T_::ReflectionType>
80 Append(values, prefix, reflectionobj);
91 template<
class T_,
class R_ =
typename T_::ReflectionType>
92 typename std::enable_if<R_::IsGorgonReflection, void>::type
94 static_assert(R_::IsGorgonReflection,
"The template argument R_ for this constructor should be reflection type of the struct.");
96 Append(values,
"", reflectionobj);
103 template<
class T_,
class R_ =
typename T_::ReflectionType>
104 typename std::enable_if<R_::IsGorgonReflection, void>::type
106 static_assert(R_::IsGorgonReflection,
"The template argument R_ for this constructor should be reflection type of the struct.");
113 typename std::enable_if<!std::is_base_of<Base, T_>::value && !T_::ReflectionType::IsGorgonReflection,
void>::type
115 Insert(value, items.GetCount());
120 typename std::enable_if<std::is_base_of<Base, T_>::value,
void>::type
122 Insert(value, items.GetCount());
127 typename std::enable_if<!std::is_base_of<Base, T_>::value,
void>::type
134 typename std::enable_if<std::is_base_of<Base, T_>::value,
void>::type
145 void Insert(
const std::string &
name,
int value,
int before) {
155 void Insert(
const std::string &
name,
float value,
int before) {
160 void Insert(
const std::string &value,
int before) {
165 void Insert(
const std::string &
name,
const std::string &value,
int before) {
170 void Insert(
const char *value,
int before) {
175 void Insert(
const std::string &
name,
const char *value,
int before) {
260 template<
class T_,
class R_ =
typename T_::ReflectionType>
262 return NamedTransform_KeepObjects<T_, R_>(
"", reflectionobj);
267 template<
class T_,
class R_ =
typename T_::ReflectionType>
277 template<
class T_,
class R_ =
typename T_::ReflectionType>
279 return NamedTransform<T_, R_>(
"", reflectionobj);
284 template<
class T_,
class R_ =
typename T_::ReflectionType>
295 static_assert(std::is_same<T_, int>::value,
"Unknown data type.");
301 static_assert(std::is_same<T_, int>::value,
"Unknown data type.");
307 auto &item=
dynamic_cast<ObjectData&
>(items[index]);
309 return item.
Get<T_>();
320 return items.begin();
330 return items.begin();
345 for(
auto &item : items) {
346 if(item.Name==
name)
return item;
349 throw std::runtime_error(
"Cannot find the item requested: "+
name);
356 for(
auto &item : items) {
357 if(item.Name==
name)
return ind;
366 return items.GetCount();
379 throw std::runtime_error(
"Cannot find the item with the name: "+
name);
387 auto &item = items[index];
399 throw std::runtime_error(
"Cannot find the item with the name: "+
name);
412 items.Insert(item, before);
416 static Data *
LoadResource(std::weak_ptr<File> file, std::shared_ptr<Reader> reader,
unsigned long totalsize);
425 virtual void save(
Writer &writer)
const;
433 inline int Data::Get<int>(
int index)
const {
434 auto &item=
dynamic_cast<IntegerData&
>(items[index]);
440 inline float Data::Get<float>(
int index)
const {
441 auto &item=
dynamic_cast<FloatData&
>(items[index]);
447 inline std::string Data::Get<std::string>(
int index)
const {
448 auto &item=
dynamic_cast<TextData&
>(items[index]);
455 auto &item=
dynamic_cast<PointData&
>(items[index]);
462 auto &item=
dynamic_cast<PointfData&
>(items[index]);
469 auto &item=
dynamic_cast<SizeData&
>(items[index]);
483 auto &item=
dynamic_cast<BoundsData&
>(items[index]);
490 auto &item=
dynamic_cast<MarginData&
>(items[index]);
bool isreference
Is a reference, data is a ptr to the original type.
Definition: Data.h:191
T_ NamedTransform_KeepObjects(const R_ &reflectionobj=T_::Reflection()) const
Transforms the members of this resource data to the given struct.
Definition: Data.h:261
void Insert(Geometry::Size value, int before)
Inserts a data item to the given position.
Definition: Data.h:200
Definition: DataItems.h:183
This class represents boundaries of 2D objects.
Definition: Bounds.h:27
Data(const T_ &values, const std::string &prefix, const R_ &reflectionobj=T_::Reflection())
This constructor accepts a reflected struct and turns it into a resource data.
Definition: Data.h:79
void Insert(Geometry::Margin value, int before)
Inserts a data item to the given position.
Definition: Data.h:230
static bool Exists()
Returns the current VM for this thread.
Definition: VirtualMachine.h:118
Data DeReference()
Definition: Data.cpp:180
Any data
Stored data.
Definition: Data.h:185
virtual std::string ToString(const Data &) const =0
Converts a data of this type to string.
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
std::string name
Name of this resource object, may not be loaded.
Definition: Base.h:155
constexpr Type Data
Data resource.
Definition: GID.h:164
std::enable_if<!std::is_base_of< Base, T_ >::value &&!T_::ReflectionType::IsGorgonReflection, void >::type Append(T_ value)
Appends the given data to the end of this data resource.
Definition: Data.h:114
void Insert(Geometry::Point value, int before)
Inserts a data item to the given position.
Definition: Data.h:180
RTTS & ConstPtrType
Definition: TMP.h:375
virtual GID::Type GetGID() const override
This function shall return Gorgon ID of this resource.
Definition: Data.h:83
std::enable_if< std::is_base_of< Base, T_ >::value, void >::type Append(T_ &value)
Appends the given resource object to the end of this data resource.
Definition: Data.h:121
virtual ~Data()
Definition: Data.cpp:128
T_ NamedTransform(const R_ &reflectionobj=T_::Reflection())
Transforms the members of this resource data to the given struct.
Definition: Data.h:278
void Insert(int value, int before)
Inserts a data item to the given position.
Definition: Data.h:140
void Register(const Data &data)
Registers a new object of reference counting, this will set reference count to one.
Definition: Runtime.h:24
void Insert(const std::string &name, Base *value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:244
void Delete(const Data &obj) const
Deletes the object.
Definition: Reflection.h:1379
void Insert(Geometry::Rectangle value, int before)
Inserts a data item to the given position.
Definition: Data.h:210
Data()
Constructs an invalid data.
Definition: Data.h:31
Definition: DataItems.h:104
~Data()
Destructor.
Definition: Data.h:420
TMP::RTTH & TypeInterface
Type interface used for this type.
Definition: Reflection.h:1414
This class can hold any other information providing type erasure.
Definition: Any.h:32
ReferenceCounter References
This system allows objects of automatic lifetime.
Definition: VirtualMachine.h:222
Iterator end()
Can be used to iterate over data objects.
Definition: Data.h:334
Data describes a piece of data.
Definition: Data.h:22
std::string ToString() const
Definition: Data.cpp:90
Definition: DataItems.h:237
void Insert(DataItem &item, int before)
Inserts the given data item to this data resource before the specified index. Ownership of the item i...
Definition: Data.h:411
T_ UnsafeGet() const
Unsafe version of Get.
Definition: Any.h:305
Definition: DataItems.h:17
void Insert(const std::string &name, Geometry::Size value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:205
static Data * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long totalsize)
Loads a data resource.
Definition: Data.cpp:18
void SetRaw(void *data)
Unsafe! This function sets the raw data contained within any, without modifying its type data.
Definition: Any.h:194
void Insert(const std::string &name, Geometry::Pointf value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:195
void Insert(const std::string &name, int value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:145
A sequence element, can be used to represent a sequence of integer numbers.
Definition: TMP.h:15
bool Compare(const Data &l, const Data &r) const
This function compares two instances of this type. Both left and right should of this type.
Definition: Reflection.cpp:95
void Insert(const std::string &name, Geometry::Margin value, int before)
Definition: Data.h:234
void * Disown()
Unsafe! Disowns the data contained in this any.
Definition: Any.h:234
void Insert(const std::string &name, Geometry::Point value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:185
static VirtualMachine & Get()
Returns the current VM for this thread.
Definition: VirtualMachine.h:109
bool IsReferenceType() const
Returns whether this type is a reference type.
Definition: Reflection.h:1327
void Insert(const std::string &name, float value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:155
Definition: DataItems.h:130
Generates a sequence from 0 to the given value.
Definition: TMP.h:18
DataItem & Release(int index)
Releases the data item with the given index. The data item will not be destroyed.
Definition: Data.h:386
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
void Insert(Base *value, int before)
Inserts a data item to the given position.
Definition: Data.h:239
std::enable_if<!std::is_base_of< Base, T_ >::value, void >::type Append(const std::string &name, T_ value)
Appends the given data to the end of this data resource with the specified name.
Definition: Data.h:128
void Add(DataItem &item)
Adds the given data item to this data resource. Ownership of the item is transferred to this Data.
Definition: Data.h:406
T_ NamedTransform_KeepObjects(const std::string &prefix, const R_ &reflectionobj=T_::Reflection()) const
Transforms the members of this resource data to the given struct.
Definition: Data.h:268
void SetType(const TMP::RTTS &type)
Unsafe! This function modifies type information of the data content.
Definition: Any.h:246
void MakeConstant()
Makes this data a constant.
Definition: Data.cpp:199
This class stores information about types.
Definition: Reflection.h:1165
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
int FindIndex(const std::string &name) const
Returns the index of the data item with the given name.
Definition: Data.h:354
RTTS & NormalType
Definition: TMP.h:375
ConstIterator begin() const
Can be used to iterate over data objects.
Definition: Data.h:319
Data GetReference()
Definition: Data.cpp:148
void Insert(const std::string &name, const std::string &value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:165
void Insert(Base &value, int before)
Inserts a data item to the given position.
Definition: Data.h:249
Definition: DataItems.h:324
T_ & Get() const
Returns the item contained within this object.
Definition: DataItems.h:391
bool IsReference() const
Returns if this data contains a reference.
Definition: Data.cpp:212
#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
static std::map< GID::Type, LoaderFn > DataLoaders
Data loaders that all data containing classes would use to load their children.
Definition: DataItems.h:58
TMP::RTTI & TypeInfo() const
Returns TypeInfo used by current data.
Definition: Any.h:87
bool operator==(const Data &r) const
Definition: Data.cpp:218
DataItem & GetItem(int index) const
Returns the data item with the given index.
Definition: Data.h:339
This class is the base for all Gorgon Resources.
Definition: Base.h:20
void Insert(const std::string &name, const char *value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:175
DataItem & GetItem(const std::string &name) const
Returns the data item with the given name.
Definition: Data.h:344
Definition: DataItems.h:78
Definition: DataItems.h:210
std::enable_if< R_::IsGorgonReflection, void >::type Append(const T_ &values, const R_ &reflectionobj=T_::Reflection())
This function accepts a reflected struct and appends it to the resource data.
Definition: Data.h:93
ConstIterator end() const
Can be used to iterate over data objects.
Definition: Data.h:324
Containers::Collection< DataItem >::Iterator Iterator
Iterator for the data resource.
Definition: Data.h:58
Const iterator allows iteration of const collections.
Definition: Collection.h:137
Iterator_< T_, Collection > Iterator
Regular iterator.
Definition: Collection.h:134
Definition: DataItems.h:295
T_ NamedTransform(const std::string &prefix, const R_ &reflectionobj=T_::Reflection())
Transforms the members of this resource data to the given struct.
Definition: Data.h:285
void Insert(const char *value, int before)
Inserts a data item to the given position.
Definition: Data.h:170
This class represents a 2D point.
Definition: Point.h:32
Any GetDefaultValue() const
Returns the value of the type.
Definition: Reflection.h:1322
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
void Insert(Geometry::Pointf value, int before)
Inserts a data item to the given position.
Definition: Data.h:190
void Delete() const
Attempts to delete the data contained in this data.
Definition: Data.cpp:136
bool IsNull() const
Definition: Data.cpp:118
void Set(const T_ &data)
Set the content of the Any to the given value.
Definition: Any.h:151
Data & operator=(Data)
Assignment operator.
Definition: Data.cpp:96
std::enable_if< std::is_base_of< Base, T_ >::value, void >::type Append(const std::string &name, T_ &value)
Appends the given resource object to the end of this data resource with the specified name.
Definition: Data.h:135
Data(const T_ &values, const R_ &reflectionobj=T_::Reflection())
This constructor accepts a reflected struct and turns it into a resource data.
Definition: Data.h:70
void Insert(const std::string &name, Geometry::Bounds value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:225
Data()
Creates an empty Data.
Definition: Data.h:64
std::string Name() const
Returns human readable name of the type.
Definition: TMP.h:184
Data * parent
Definition: Data.h:196
void Insert(const std::string &name, Geometry::Rectangle value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:215
RTTS & ConstType
Definition: TMP.h:375
void Insert(Geometry::Bounds value, int before)
Inserts a data item to the given position.
Definition: Data.h:220
Definition: DataItems.h:156
Iterator begin()
Can be used to iterate over data objects.
Definition: Data.h:329
DataItem & Release(const std::string &name)
Releases the data item with the given name. The data item will not be destroyed.
Definition: Data.h:395
Type
Definition: Shader.h:14
void * Pointer() const
Returns the pointer without type information.
Definition: Any.h:332
T_ Get(int index) const
Returns the data with the given index; use GetObject in order to get resource objects.
Definition: Data.h:294
Library Reflection
Definition: Builtin.cpp:17
const Type * type
Type of the data.
Definition: Data.h:188
Exceptions This file contains string related exceptions.
Type to store GID information.
Definition: GID.h:23
This class defines Margin of an object or an area.
Definition: Margin.h:22
void Remove(int index)
Removes the item at the given index. The data item will be destroyed.
Definition: Data.h:370
RTTS & PtrType
Definition: TMP.h:375
void Decrease(const Data &data)
Decreases the reference count of the given object.
Definition: Runtime.h:68
T_ & GetObject(const std::string &name) const
Returns the resource object with the given name.
Definition: Data.h:314
void Insert(float value, int before)
Inserts a data item to the given position.
Definition: Data.h:150
void Remove(const std::string &name)
Removes the item with the given name. The data item will be destroyed.
Definition: Data.h:375
int GetCount() const
Returns the number data items in this data resource.
Definition: Data.h:365
Definition: DataItems.h:266
Represents a rectangle in a 2D space.
Definition: Rectangle.h:19
bool IsSet() const
Checks whether the Any is set.
Definition: Any.h:398
std::string GetTypeName() const
Definition: Any.h:272
T_ & GetObject(int index) const
Returns the resource object at the given index.
Definition: Data.h:306
T_ Get(const std::string &name) const
Returns the data with the given name; use GetObject in order to get resource objects.
Definition: Data.h:300
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
void Increase(const Data &data)
Increases the reference count of the given object. If it is not registered, this request is ignored.
Definition: Runtime.h:47
void Insert(const std::string &name, Base &value, int before)
Inserts a data item to the given position with the specified name.
Definition: Data.h:254
bool isconstant
This data is a constant and should not be changed.
Definition: Data.h:194
void NotImplemented(const std::string &what="This feature")
Definition: Assert.h:187
std::enable_if< R_::IsGorgonReflection, void >::type Append(const T_ &values, const std::string &prefix, const R_ &reflectionobj=T_::Reflection())
This function accepts a reflected struct and appends it to the resource data.
Definition: Data.h:105
void Insert(const std::string &value, int before)
Inserts a data item to the given position.
Definition: Data.h:160
std::string GetName() const
Returns the name of this member.
Definition: Reflection.h:325