GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
gd::SerializableWithNameList< T > Class Template Reference

A class template that store a list of elements that can be accessed by their names and serialized. More...

#include <SerializableWithNameList.h>

Public Member Functions

 SerializableWithNameList (const SerializableWithNameList< T > &)
 
SerializableWithNameList< T > & operator= (const SerializableWithNameList< T > &rhs)
 
T & Insert (const T &element, size_t position=(size_t) -1)
 Insert the specified element to the list. More...
 
void Insert (const SerializableWithNameList< T > &otherEvents, size_t begin, size_t end, size_t position=(size_t) -1)
 Copy elements from another list.
 
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. More...
 
size_t GetCount () const
 Return the number of elements.
 
T & Get (const gd::String &name)
 Return a reference to the element with the specified name.
 
const T & Get (const gd::String &name) const
 Return a reference to the element with the specified name.
 
T & Get (size_t index)
 Return a reference to the element at position index in the elements list.
 
const T & Get (size_t index) const
 Return a reference to the element at position index in the elements list.
 
void Remove (const gd::String &name)
 Remove the element with the specified name, destroying it.
 
void Remove (size_t index)
 Remove the element at the specified index in the list, destroying it.
 
bool IsEmpty () const
 Return true if there isn't any element in the list.
 
void Clear ()
 Clear the list of elements, destroying all of them.
 
void Move (std::size_t oldIndex, std::size_t newIndex)
 Move element at position oldIndex to position newIndex. More...
 
bool Has (const gd::String &name) const
 Return true if an element with the specified name exists.
 
std::size_t GetPosition (const T &element) const
 Get the position of an element in the list.
 
std::vector-like API

These functions ensure that the class can be used just like a std::vector for iterations.

size_t size () const
 Alias for GetCount() More...
 
bool empty () const
 Alias for IsEmpty() More...
 
T & operator[] (size_t index)
 Alias for Get() More...
 
const T & operator[] (size_t index) const
 Alias for Get() More...
 
T & at (size_t index)
 Alias for Get() More...
 
const T & at (size_t index) const
 Alias for Get() More...
 
Internal std::vector raw access
const std::vector< std::unique_ptr< T > > & GetInternalVector () const
 Provide a raw access to the vector containing the elements.
 
std::vector< std::unique_ptr< T > > & GetInternalVector ()
 Provide a raw access to the vector containing the elements.
 
Serialization
void SerializeElementsTo (const gd::String &elementName, SerializerElement &element) const
 
void UnserializeElementsFrom (const gd::String &elementName, gd::Project &project, const SerializerElement &element)
 
void UnserializeElementsFrom (const gd::String &elementName, const SerializerElement &element)
 
void ProgressivelyUnserializeElementsFrom (const gd::String &elementName, gd::Project &project, const SerializerElement &element)
 

Protected Member Functions

void Init (const SerializableWithNameList< T > &other)
 

Protected Attributes

std::vector< std::unique_ptr< T > > elements
 

Detailed Description

template<typename T>
class gd::SerializableWithNameList< T >

A class template that store a list of elements that can be accessed by their names and serialized.

The type T is supposed to have a method GetName, returning the gd::String representing the name of the object, and SerializeTo/UnserializeFrom.

Note
Invariant: each element in the list has a unique name.
Invalidation: Elements can be re-ordered without invalidating them. Insertion/removal does not invalidate other elements. Remove/Clear delete elements from memory.

Member Function Documentation

◆ at() [1/2]

template<typename T >
T& gd::SerializableWithNameList< T >::at ( size_t  index)
inline

◆ at() [2/2]

template<typename T >
const T& gd::SerializableWithNameList< T >::at ( size_t  index) const
inline

◆ empty()

template<typename T >
bool gd::SerializableWithNameList< T >::empty ( ) const
inline

◆ Init()

template<typename T >
void gd::SerializableWithNameList< T >::Init ( const SerializableWithNameList< T > &  other)
protected

Initialize from another list of elements, copying elements. Used by copy-ctor and assign-op. Don't forget to update me if members were changed!

◆ Insert()

template<typename T >
T & gd::SerializableWithNameList< T >::Insert ( const T &  element,
size_t  position = (size_t)-1 
)

Insert the specified element to the list.

Note
The element passed by parameter is copied.
Parameters
elementThe element that must be copied and inserted into the list
positionInsertion position. If the position is invalid, the object is inserted at the end of the objects list.
Returns
A reference to the element in the list

◆ InsertNew()

template<typename T >
T & gd::SerializableWithNameList< 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.

Parameters
nameThe name of the new element
positionInsertion position. If the position is invalid, the object is inserted at the end of the objects list.
Returns
A reference to the element in the list

◆ Move()

template<typename T >
void gd::SerializableWithNameList< T >::Move ( std::size_t  oldIndex,
std::size_t  newIndex 
)

Move element at position oldIndex to position newIndex.

Elements pointers/references won't be invalidated.

◆ operator[]() [1/2]

template<typename T >
T& gd::SerializableWithNameList< T >::operator[] ( size_t  index)
inline

◆ operator[]() [2/2]

template<typename T >
const T& gd::SerializableWithNameList< T >::operator[] ( size_t  index) const
inline

◆ size()

template<typename T >
size_t gd::SerializableWithNameList< T >::size ( ) const
inline

The documentation for this class was generated from the following files: