GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members

Defines a variable which can be used by an object, a layout or a project. More...

#include <Variable.h>

Public Types

enum  Type {
  String , Number , Boolean , Structure ,
  Array
}
 

Public Member Functions

 Variable ()
 Default constructor creating a variable with 0 as value.
 
 Variable (const Variable &)
 
Variableoperator= (const Variable &rhs)
 
Type GetType () const
 Get the type of the variable.
 
void CastTo (const Type newType)
 Converts the variable to a new type.
 
void CastTo (const gd::String &type)
 Converts the variable to a new type.
 
Primitives

Methods and operators used when the variable is considered as a primitive.

const gd::StringGetString () const
 Return the content of the variable, considered as a string.
 
void SetString (const gd::String &newStr)
 Change the content of the variable, considered as a string.
 
double GetValue () const
 Return the content of the variable, considered as a number.
 
void SetValue (double val)
 Change the content of the variable, considered as a number.
 
bool GetBool () const
 Return the content of the variable, considered as a boolean.
 
void SetBool (bool val)
 Change the content of the variable, considered as a boolean.
 
void operator= (double val)
 
void operator+= (double val)
 
void operator-= (double val)
 
void operator*= (double val)
 
void operator/= (double val)
 
bool operator<= (double val) const
 
bool operator>= (double val) const
 
bool operator< (double val) const
 
bool operator> (double val) const
 
bool operator== (double val) const
 
bool operator!= (double val) const
 
void operator= (int val)
 
void operator+= (int val)
 
void operator-= (int val)
 
void operator*= (int val)
 
void operator/= (int val)
 
bool operator<= (int val) const
 
bool operator>= (int val) const
 
bool operator< (int val) const
 
bool operator> (int val) const
 
bool operator== (int val) const
 
bool operator!= (int val) const
 
void operator= (const gd::String &val)
 
void operator+= (const gd::String &val)
 
bool operator== (const gd::String &val) const
 
bool operator!= (const gd::String &val) const
 
void operator= (const char *val)
 
void operator+= (const char *val)
 
bool operator== (const char *val) const
 
bool operator!= (const char *val) const
 
void operator= (const bool val)
 
bool operator== (const bool val) const
 
bool operator!= (const bool val) const
 
Collection types

Methods used for collection types

void ClearChildren ()
 Remove all the children.
 
size_t GetChildrenCount () const
 Get the count of children that the variable has.
 
Structure

Methods used when the variable is considered as a structure.

bool HasChild (const gd::String &name) const
 Return true if the variable is a structure and has the specified child.
 
VariableGetChild (const gd::String &name)
 Return the child with the specified name. More...
 
const VariableGetChild (const gd::String &name) const
 Return the child with the specified name. More...
 
void RemoveChild (const gd::String &name)
 Remove the child with the specified name. More...
 
bool RenameChild (const gd::String &oldName, const gd::String &newName)
 Rename the specified child. More...
 
std::vector< gd::StringGetAllChildrenNames () const
 Get the names of all children.
 
const std::map< gd::String, std::shared_ptr< Variable > > & GetAllChildren () const
 Get the map containing all the children.
 
bool Contains (const gd::Variable &variableToSearch, bool recursive) const
 Search if a variable is part of the children, optionally recursively.
 
void RemoveRecursively (const gd::Variable &variableToRemove)
 Remove the specified variable if it can be found in the children.
 
Array

Methods used when the variable is considered as an array.

VariableGetAtIndex (const size_t index)
 Return the element with the specified index. More...
 
const VariableGetAtIndex (const size_t index) const
 Return the element with the specified index. More...
 
VariablePushNew ()
 Appends a new variable at the end of the list and returns it.
 
void RemoveAtIndex (const size_t index)
 Remove the element with the specified index. More...
 
void MoveChildInArray (const size_t oldIndex, const size_t newIndex)
 Move child in array.
 
bool InsertAtIndex (const gd::Variable &variable, const size_t index)
 Insert child in array.
 
bool InsertChild (const gd::String &name, const gd::Variable &variable)
 Insert a child in a structure.
 
const std::vector< std::shared_ptr< Variable > > & GetAllChildrenArray () const
 Get the vector containing all the children.
 
void SetFolded (bool fold=true)
 Set if the children must be folded.
 
bool IsFolded () const
 True if the children should be folded in the variables editor.
 
Serialization

Methods used when to load or save a variable to XML.

void SerializeTo (SerializerElement &element) const
 Serialize variable.
 
void UnserializeFrom (const SerializerElement &element)
 Unserialize the variable.
 
VariableResetPersistentUuid ()
 Reset the persistent UUID used to recognize the same variable between serialization.
 
VariableClearPersistentUuid ()
 Remove the persistent UUID - when the variable no longer needs to be recognized between serializations.
 
const gd::StringGetPersistentUuid () const
 Get the persistent UUID used to recognize the same variable between serialization.
 

Static Public Member Functions

static bool IsPrimitive (const Type type)
 Returns true if the passed type is primitive.
 

Static Public Attributes

static gd::Variable badVariable
 

Detailed Description

Defines a variable which can be used by an object, a layout or a project.

See also
gd::VariablesContainer

Member Function Documentation

◆ GetAtIndex() [1/2]

Variable & gd::Variable::GetAtIndex ( const size_t  index)

Return the element with the specified index.

If the variable does not have the specified index, the array will be filled up to that index with empty variables.

◆ GetAtIndex() [2/2]

const Variable & gd::Variable::GetAtIndex ( const size_t  index) const

Return the element with the specified index.

If the variable has not the specified child, an empty variable is returned.

◆ GetChild() [1/2]

Variable & gd::Variable::GetChild ( const gd::String name)

Return the child with the specified name.

If the variable has not the specified child, an empty variable with the specified name is added as child.

If the variable is not a structure or has not the specified child, an empty variable is returned.

◆ GetChild() [2/2]

const Variable & gd::Variable::GetChild ( const gd::String name) const

Return the child with the specified name.

If the variable has not the specified child, an empty variable with the specified name is added as child.

If the variable is not a structure or has not the specified child, an empty variable is returned.

◆ RemoveAtIndex()

void gd::Variable::RemoveAtIndex ( const size_t  index)

Remove the element with the specified index.

And shifts all the next elements back by one.

◆ RemoveChild()

void gd::Variable::RemoveChild ( const gd::String name)

Remove the child with the specified name.

If the variable is not a structure or has not the specified child, nothing is done.

◆ RenameChild()

bool gd::Variable::RenameChild ( const gd::String oldName,
const gd::String newName 
)

Rename the specified child.

If the variable is not a structure or has not the specified child, nothing is done.

Returns
true if the child was renamed, false otherwise.

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