GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Public Member Functions | List of all members
gd::InitialInstancesContainer Class Reference

Defines a container of gd::InitialInstances. More...

#include <InitialInstancesContainer.h>

Public Member Functions

InitialInstancesContainerClone () const
 Return a pointer to a copy of the container. A such method is needed as the IDE may want to store copies of some containers and so need a way to do polymorphic copies. More...
 
void Create (const InitialInstancesContainer &source)
 
Instances management

Members functions related to managing the instances

std::size_t GetInstancesCount () const
 Return the number of instances.
 
void IterateOverInstances (InitialInstanceFunctor &func)
 Apply func to each instance of the container. More...
 
void IterateOverInstancesWithZOrdering (InitialInstanceFunctor &func, const gd::String &layer)
 
InitialInstanceInsertInitialInstance (const InitialInstance &instance)
 Insert the specified instance into the list and return a a reference to the newly added instance.
 
InitialInstanceInsertNewInitialInstance ()
 Insert a new blank instance at the end of the list and return a a reference to the newly added instance.
 
void RemoveInstance (const gd::InitialInstance &instance)
 Remove the specified instance.
 
void RemoveAllInstancesOnLayer (const gd::String &layerName)
 Remove all instances from layer layerName.
 
void MoveInstancesToLayer (const gd::String &fromLayer, const gd::String &toLayer)
 Move the instances on layer fromLayer to layer toLayer.
 
void RemoveInitialInstancesOfObject (const gd::String &objectName)
 Remove instances of object named objectName.
 
void RenameInstancesOfObject (const gd::String &oldName, const gd::String &newName)
 Change instances with object's name oldName to newName.
 
std::size_t GetLayerInstancesCount (const gd::String &layerName) const
 Return the number of instances on the layer named layerName.
 
bool SomeInstancesAreOnLayer (const gd::String &layerName) const
 Return true if there is at least one instance on the layer named layerName.
 
bool HasInstancesOfObject (const gd::String &objectName) const
 Return true if there is at least one instance of the given object.
 
void Clear ()
 Remove all instances.
 
Saving and loading

Members functions related to saving and loading the object.

virtual void SerializeTo (SerializerElement &element) const
 Serialize instances container.
 
virtual void UnserializeFrom (const SerializerElement &element)
 Unserialize the instances container.
 

Detailed Description

Defines a container of gd::InitialInstances.

The container is notably able to ensure that pointers to the elements of the container are not invalidated when a change occurs (through InsertNewInitialInstance or RemoveInstance for example).
Thus, the implementations uses a std::list for holding the instances. In this way, the container is not required to provide a direct access to element based on an index. Instead, the method IterateOverInstances is used to perform operations.

See also
gd::InitialInstanceFunctor

Member Function Documentation

◆ Clone()

InitialInstancesContainer* gd::InitialInstancesContainer::Clone ( ) const
inline

Return a pointer to a copy of the container. A such method is needed as the IDE may want to store copies of some containers and so need a way to do polymorphic copies.

Typical implementation example:

return new MyContainer(*this);

◆ Create()

void gd::InitialInstancesContainer::Create ( const InitialInstancesContainer source)

Must construct the class from the source A such method is needed as the IDE may want to store copies of some containers and so need a way to do polymorphic copies.

Typical implementation example:

try
{
const MyContainer & castedSource = dynamic_cast<const
MyContainer&>(source); operator=(castedSource);
}
catch(...) { std::cout << "WARNING: Tried to create a MyContainer object
from an object which is not a MyContainer"; }

◆ IterateOverInstances()

void gd::InitialInstancesContainer::IterateOverInstances ( gd::InitialInstanceFunctor func)

Apply func to each instance of the container.

See also
InitialInstanceFunctor

◆ IterateOverInstancesWithZOrdering()

void gd::InitialInstancesContainer::IterateOverInstancesWithZOrdering ( gd::InitialInstanceFunctor func,
const gd::String layer 
)

Get the instances on the specified layer, sort them regarding their Z order and then apply func on them.

Parameters
funcThe functor to be applied.
layerThe layer
See also
InitialInstanceFunctor

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