7 #ifndef GDCORE_SerializableWithNameList
8 #define GDCORE_SerializableWithNameList
11 #include "GDCore/String.h"
14 class SerializerElement;
50 T&
Insert(
const T& element,
size_t position = (
size_t)-1);
58 size_t position = (
size_t)-1);
75 size_t GetCount()
const {
return elements.size(); };
91 T&
Get(
size_t index) {
return *elements[index]; };
97 const T&
Get(
size_t index)
const {
return *elements[index]; };
108 void Remove(
size_t index);
113 bool IsEmpty()
const {
return elements.empty(); };
118 void Clear() {
return elements.clear(); };
125 void Move(std::size_t oldIndex, std::size_t newIndex);
170 T&
at(
size_t index) {
return Get(index); };
176 const T&
at(
size_t index)
const {
return Get(index); };
198 void SerializeElementsTo(
const gd::String& elementName,
201 void UnserializeElementsFrom(
const gd::String& elementName,
205 void UnserializeElementsFrom(
const gd::String& elementName,
208 void ProgressivelyUnserializeElementsFrom(
const gd::String& elementName,
214 std::vector<std::unique_ptr<T>> elements;
225 #include "SerializableWithNameList.inl"
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
A class template that store a list of elements that can be accessed by their names and serialized.
Definition: SerializableWithNameList.h:33
T & Get(size_t index)
Return a reference to the element at position index in the elements list.
Definition: SerializableWithNameList.h:91
T & at(size_t index)
Alias for Get()
Definition: SerializableWithNameList.h:170
std::vector< std::unique_ptr< T > > & GetInternalVector()
Provide a raw access to the vector containing the elements.
Definition: SerializableWithNameList.h:192
void Remove(const gd::String &name)
Remove the element with the specified name, destroying it.
Definition: SerializableWithNameList.inl:62
size_t size() const
Alias for GetCount()
Definition: SerializableWithNameList.h:146
const std::vector< std::unique_ptr< T > > & GetInternalVector() const
Provide a raw access to the vector containing the elements.
Definition: SerializableWithNameList.h:185
void Clear()
Clear the list of elements, destroying all of them.
Definition: SerializableWithNameList.h:118
bool IsEmpty() const
Return true if there isn't any element in the list.
Definition: SerializableWithNameList.h:113
bool Has(const gd::String &name) const
Return true if an element with the specified name exists.
Definition: SerializableWithNameList.inl:95
T & Insert(const T &element, size_t position=(size_t) -1)
Insert the specified element to the list.
Definition: SerializableWithNameList.inl:37
const T & at(size_t index) const
Alias for Get()
Definition: SerializableWithNameList.h:176
bool empty() const
Alias for IsEmpty()
Definition: SerializableWithNameList.h:152
std::size_t GetPosition(const T &element) const
Get the position of an element in the list.
Definition: SerializableWithNameList.inl:114
size_t GetCount() const
Return the number of elements.
Definition: SerializableWithNameList.h:75
void Init(const SerializableWithNameList< T > &other)
Definition: SerializableWithNameList.inl:190
const T & Get(size_t index) const
Return a reference to the element at position index in the elements list.
Definition: SerializableWithNameList.h:97
const T & operator[](size_t index) const
Alias for Get()
Definition: SerializableWithNameList.h:164
T & InsertNew(const gd::String &name, size_t position=(size_t) -1)
Insert a new element (constructed from its default constructor) with the given name.
Definition: SerializableWithNameList.inl:46
void Move(std::size_t oldIndex, std::size_t newIndex)
Move element at position oldIndex to position newIndex.
Definition: SerializableWithNameList.inl:104
T & operator[](size_t index)
Alias for Get()
Definition: SerializableWithNameList.h:158
T & Get(const gd::String &name)
Return a reference to the element with the specified name.
Definition: SerializableWithNameList.inl:75
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24