14 #include "GDCore/String.h"
16 class SerializerElement;
50 static bool IsPrimitive(
const Type type);
55 Variable() : value(0), type(
Type::Number), hasMixedValues(false) {};
59 Variable& operator=(
const Variable& rhs);
69 void CastTo(
const Type newType);
92 hasMixedValues =
false;
98 double GetValue()
const;
106 if (std::isnan(value)) value = 0.0;
108 hasMixedValues =
false;
114 bool GetBool()
const;
121 type = Type::Boolean;
122 hasMixedValues =
false;
130 return hasMixedValues;
137 void MarkAsMixedValues();
141 void operator=(
double val) { SetValue(val); };
142 void operator+=(
double val) { SetValue(val + GetValue()); }
143 void operator-=(
double val) { SetValue(GetValue() - val); }
144 void operator*=(
double val) { SetValue(val * GetValue()); }
145 void operator/=(
double val) { SetValue(GetValue() / val); }
147 bool operator<=(
double val)
const {
return GetValue() <= val; };
148 bool operator>=(
double val)
const {
return GetValue() >= val; };
149 bool operator<(
double val)
const {
return GetValue() < val; };
150 bool operator>(
double val)
const {
return GetValue() > val; };
151 bool operator==(
double val)
const {
return GetValue() == val; };
152 bool operator!=(
double val)
const {
return GetValue() != val; };
155 void operator=(
int val) { SetValue(val); };
156 void operator+=(
int val) { SetValue(val + GetValue()); }
157 void operator-=(
int val) { SetValue(GetValue() - val); }
158 void operator*=(
int val) { SetValue(val * GetValue()); }
159 void operator/=(
int val) { SetValue(GetValue() / val); }
161 bool operator<=(
int val)
const {
return GetValue() <= val; };
162 bool operator>=(
int val)
const {
return GetValue() >= val; };
163 bool operator<(
int val)
const {
return GetValue() < val; };
164 bool operator>(
int val)
const {
return GetValue() > val; };
165 bool operator==(
int val)
const {
return GetValue() == val; };
166 bool operator!=(
int val)
const {
return GetValue() != val; };
170 void operator=(
const gd::String& val) { SetString(val); };
171 void operator+=(
const gd::String& val) { SetString(GetString() + val); }
173 bool operator==(
const gd::String& val)
const {
return GetString() == val; };
174 bool operator!=(
const gd::String& val)
const {
return GetString() != val; };
177 void operator=(
const char* val) { SetString(val); };
178 void operator+=(
const char* val) { SetString(GetString() + val); }
180 bool operator==(
const char* val)
const {
return GetString() == val; };
181 bool operator!=(
const char* val)
const {
return GetString() != val; };
185 void operator=(
const bool val) { SetBool(val); };
187 bool operator==(
const bool val)
const {
return GetBool() == val; };
188 bool operator!=(
const bool val)
const {
return GetBool() != val; };
205 childrenArray.clear();
212 return type == Type::Structure ? children.size()
213 : type == Type::Array ? childrenArray.size()
263 std::vector<gd::String> GetAllChildrenNames()
const;
276 bool Contains(
const gd::Variable& variableToSearch,
bool recursive)
const;
281 void RemoveRecursively(
const gd::Variable& variableToRemove);
295 Variable& GetAtIndex(
const size_t index);
303 const Variable& GetAtIndex(
const size_t index)
const;
315 void RemoveAtIndex(
const size_t index);
320 void MoveChildInArray(
const size_t oldIndex,
const size_t newIndex);
325 bool InsertAtIndex(
const gd::Variable& variable,
const size_t index);
336 return childrenArray;
399 mutable double value;
400 mutable bool boolVal =
false;
401 mutable bool hasMixedValues;
402 mutable std::map<gd::String, std::shared_ptr<Variable>>
404 mutable std::vector<std::shared_ptr<Variable>>
414 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:33
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:89
Type
Definition: Variable.h:32
@ MixedTypes
Definition: Variable.h:35
size_t GetChildrenCount() const
Get the count of children that the variable has.
Definition: Variable.h:211
const std::map< gd::String, std::shared_ptr< Variable > > & GetAllChildren() const
Get the map containing all the children.
Definition: Variable.h:268
void SetValue(double val)
Change the content of the variable, considered as a number.
Definition: Variable.h:103
Variable()
Default constructor creating a variable with 0 as value.
Definition: Variable.h:55
bool IsFolded() const
True if the children should be folded in the variables editor.
Definition: Variable.h:347
bool HasMixedValues() const
Return true when objects of a group have different values for a variable.
Definition: Variable.h:129
Type GetType() const
Get the type of the variable.
Definition: Variable.h:64
void SetBool(bool val)
Change the content of the variable, considered as a boolean.
Definition: Variable.h:119
const gd::String & GetPersistentUuid() const
Get the persistent UUID used to recognize the same variable between serialization.
Definition: Variable.h:382
void CastTo(const gd::String &type)
Converts the variable to a new type.
Definition: Variable.h:74
void ClearChildren()
Remove all the children.
Definition: Variable.h:203
const std::vector< std::shared_ptr< Variable > > & GetAllChildrenArray() const
Get the vector containing all the children.
Definition: Variable.h:335
void SetFolded(bool fold=true)
Set if the children must be folded.
Definition: Variable.h:342
Definition: CommonTools.h:24
Type
Type of JSON value.
Definition: rapidjson.h:603