GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Public Member Functions | Protected Attributes | List of all members

Used as a base class for classes that will own objects (see gd::Object). More...

#include <ObjectsContainer.h>

Inherited by gd::Layout, and gd::Project.

Public Member Functions

 ObjectsContainer ()
 Default constructor creating a container without any objects.
 
Objects management

Members functions related to objects management.

bool HasObjectNamed (const gd::String &name) const
 Return true if object called name exists.
 
ObjectGetObject (const gd::String &name)
 Return a reference to the object called name.
 
const gd::ObjectGetObject (const gd::String &name) const
 Return a reference to the object called name.
 
ObjectGetObject (std::size_t index)
 Return a reference to the object at position index in the objects list.
 
const gd::ObjectGetObject (std::size_t index) const
 Return a reference to the object at position index in the objects list.
 
std::size_t GetObjectPosition (const gd::String &name) const
 Return the position of the object called name in the objects list. More...
 
std::size_t GetObjectsCount () const
 Return the number of object.
 
gd::ObjectInsertNewObject (gd::Project &project, const gd::String &objectType, const gd::String &name, std::size_t position)
 Add a new empty object of type objectType called name at the specified position in the list.
More...
 
gd::ObjectInsertObject (const gd::Object &object, std::size_t position)
 Add a new object to the list. More...
 
void RemoveObject (const gd::String &name)
 Delete an object. More...
 
void MoveObject (std::size_t oldIndex, std::size_t newIndex)
 
void SwapObjects (std::size_t firstObjectIndex, std::size_t secondObjectIndex)
 Swap the position of the specified objects.
 
void MoveObjectToAnotherContainer (const gd::String &name, gd::ObjectsContainer &newContainer, std::size_t newPosition)
 
std::vector< std::unique_ptr
< gd::Object > > & 
GetObjects ()
 
const std::vector
< std::unique_ptr< gd::Object > > & 
GetObjects () const
 
Saving and loading

Members functions related to saving and loading the objects of the class.

void SerializeObjectsTo (SerializerElement &element) const
 Serialize instances container.
 
void UnserializeObjectsFrom (gd::Project &project, const SerializerElement &element)
 Unserialize the instances container.
 
Objects groups management

Members functions related to global objects groups management.

ObjectGroupsContainerGetObjectGroups ()
 Return a reference to the project's objects groups.
 
const ObjectGroupsContainerGetObjectGroups () const
 Return a const reference to the project's objects groups.
 

Protected Attributes

std::vector< std::unique_ptr
< gd::Object > > 
initialObjects
 Objects contained.
 
gd::ObjectGroupsContainer objectGroups
 

Detailed Description

Used as a base class for classes that will own objects (see gd::Object).

For example, gd::Project inherits from this class as it have global objects.
gd::Layout also inherits from this class as each layout has specific objects.

See also
gd::Project
gd::Layout
gd::Object

Member Function Documentation

std::size_t gd::ObjectsContainer::GetObjectPosition ( const gd::String name) const

Return the position of the object called name in the objects list.

Warning
This has nothing to do with an object position on a layout. Objects put on layouts are represented thanks to the gd::InitialInstance class.
std::vector<std::unique_ptr<gd::Object> >& gd::ObjectsContainer::GetObjects ( )
inline

Provide a raw access to the vector containing the objects

const std::vector<std::unique_ptr<gd::Object> >& gd::ObjectsContainer::GetObjects ( ) const
inline

Provide a raw access to the vector containing the objects

gd::Object & gd::ObjectsContainer::InsertNewObject ( gd::Project project,
const gd::String objectType,
const gd::String name,
std::size_t  position 
)

Add a new empty object of type objectType called name at the specified position in the list.

Note
The object is created using the project's current platform.
Returns
A reference to the object in the list.
gd::Object & gd::ObjectsContainer::InsertObject ( const gd::Object object,
std::size_t  position 
)

Add a new object to the list.

Note
The object passed by parameter is copied.
Parameters
objectThe object that must be copied and inserted into the project
positionInsertion position. If the position is invalid, the object is inserted at the end of the objects list.
Returns
A reference to the object in the list.
void gd::ObjectsContainer::MoveObject ( std::size_t  oldIndex,
std::size_t  newIndex 
)

Change the position of the specified object.

void gd::ObjectsContainer::MoveObjectToAnotherContainer ( const gd::String name,
gd::ObjectsContainer newContainer,
std::size_t  newPosition 
)

Move the specified object to another container, removing it from the current one and adding it to the new one at the specified position.

Note
This does not invalidate the references to the object (object is not moved in memory, as referenced by smart pointers internally).
void gd::ObjectsContainer::RemoveObject ( const gd::String name)

Delete an object.

Warning
When calling this function, be sure to drop any reference that you might hold to the object - otherwise you'll access deleted memory.
Parameters
nameThe name of the object to be deleted.

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