7 #ifndef GDCORE_VARIABLE_H
8 #define GDCORE_VARIABLE_H
14 #include "GDCore/String.h"
16 class SerializerElement;
46 static bool IsPrimitive(
const Type type);
55 Variable& operator=(
const Variable& rhs);
65 void CastTo(
const Type newType);
93 double GetValue()
const;
101 if (std::isnan(value)) value = 0.0;
108 bool GetBool()
const;
115 type = Type::Boolean;
120 void operator=(
double val) { SetValue(val); };
121 void operator+=(
double val) { SetValue(val + GetValue()); }
122 void operator-=(
double val) { SetValue(GetValue() - val); }
123 void operator*=(
double val) { SetValue(val * GetValue()); }
124 void operator/=(
double val) { SetValue(GetValue() / val); }
126 bool operator<=(
double val)
const {
return GetValue() <= val; };
127 bool operator>=(
double val)
const {
return GetValue() >= val; };
128 bool operator<(
double val)
const {
return GetValue() < val; };
129 bool operator>(
double val)
const {
return GetValue() > val; };
130 bool operator==(
double val)
const {
return GetValue() == val; };
131 bool operator!=(
double val)
const {
return GetValue() != val; };
134 void operator=(
int val) { SetValue(val); };
135 void operator+=(
int val) { SetValue(val + GetValue()); }
136 void operator-=(
int val) { SetValue(GetValue() - val); }
137 void operator*=(
int val) { SetValue(val * GetValue()); }
138 void operator/=(
int val) { SetValue(GetValue() / val); }
140 bool operator<=(
int val)
const {
return GetValue() <= val; };
141 bool operator>=(
int val)
const {
return GetValue() >= val; };
142 bool operator<(
int val)
const {
return GetValue() < val; };
143 bool operator>(
int val)
const {
return GetValue() > val; };
144 bool operator==(
int val)
const {
return GetValue() == val; };
145 bool operator!=(
int val)
const {
return GetValue() != val; };
149 void operator=(
const gd::String& val) { SetString(val); };
150 void operator+=(
const gd::String& val) { SetString(GetString() + val); }
152 bool operator==(
const gd::String& val)
const {
return GetString() == val; };
153 bool operator!=(
const gd::String& val)
const {
return GetString() != val; };
156 void operator=(
const char* val) { SetString(val); };
157 void operator+=(
const char* val) { SetString(GetString() + val); }
159 bool operator==(
const char* val)
const {
return GetString() == val; };
160 bool operator!=(
const char* val)
const {
return GetString() != val; };
164 void operator=(
const bool val) { SetBool(val); };
166 bool operator==(
const bool val)
const {
return GetBool() == val; };
167 bool operator!=(
const bool val)
const {
return GetBool() != val; };
181 childrenArray.clear();
188 return type == Type::Structure ? children.size()
189 : type == Type::Array ? childrenArray.size()
239 std::vector<gd::String> GetAllChildrenNames()
const;
252 bool Contains(
const gd::Variable& variableToSearch,
bool recursive)
const;
257 void RemoveRecursively(
const gd::Variable& variableToRemove);
271 Variable& GetAtIndex(
const size_t index);
279 const Variable& GetAtIndex(
const size_t index)
const;
291 void RemoveAtIndex(
const size_t index);
296 void MoveChildInArray(
const size_t oldIndex,
const size_t newIndex);
301 bool InsertAtIndex(
const gd::Variable& variable,
const size_t index);
312 return childrenArray;
375 mutable double value;
376 mutable bool boolVal;
377 mutable std::map<gd::String, std::shared_ptr<Variable>>
379 mutable std::vector<std::shared_ptr<Variable>>
389 void CopyChildren(
const Variable& other);
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:31
Defines a variable which can be used by an object, a layout or a project.
Definition: Variable.h:29
void SetString(const gd::String &newStr)
Change the content of the variable, considered as a string.
Definition: Variable.h:85
Variable & ClearPersistentUuid()
Remove the persistent UUID - when the variable no longer needs to be recognized between serialization...
Definition: Variable.h:352
size_t GetChildrenCount() const
Get the count of children that the variable has.
Definition: Variable.h:187
const std::map< gd::String, std::shared_ptr< Variable > > & GetAllChildren() const
Get the map containing all the children.
Definition: Variable.h:244
void SetValue(double val)
Change the content of the variable, considered as a number.
Definition: Variable.h:98
Variable()
Default constructor creating a variable with 0 as value.
Definition: Variable.h:51
bool IsFolded() const
True if the children should be folded in the variables editor.
Definition: Variable.h:323
Type GetType() const
Get the type of the variable.
Definition: Variable.h:60
void SetBool(bool val)
Change the content of the variable, considered as a boolean.
Definition: Variable.h:113
const gd::String & GetPersistentUuid() const
Get the persistent UUID used to recognize the same variable between serialization.
Definition: Variable.h:358
void CastTo(const gd::String &type)
Converts the variable to a new type.
Definition: Variable.h:70
void ClearChildren()
Remove all the children.
Definition: Variable.h:179
const std::vector< std::shared_ptr< Variable > > & GetAllChildrenArray() const
Get the vector containing all the children.
Definition: Variable.h:311
void SetFolded(bool fold=true)
Set if the children must be folded.
Definition: Variable.h:318
Definition: CommonTools.h:24
Type
Type of JSON value.
Definition: rapidjson.h:603