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();
150 void ClearMixedValues();
154 void operator=(
double val) { SetValue(val); };
155 void operator+=(
double val) { SetValue(val + GetValue()); }
156 void operator-=(
double val) { SetValue(GetValue() - val); }
157 void operator*=(
double val) { SetValue(val * GetValue()); }
158 void operator/=(
double val) { SetValue(GetValue() / val); }
160 bool operator<=(
double val)
const {
return GetValue() <= val; };
161 bool operator>=(
double val)
const {
return GetValue() >= val; };
162 bool operator<(
double val)
const {
return GetValue() < val; };
163 bool operator>(
double val)
const {
return GetValue() > val; };
164 bool operator==(
double val)
const {
return GetValue() == val; };
165 bool operator!=(
double val)
const {
return GetValue() != val; };
168 void operator=(
int val) { SetValue(val); };
169 void operator+=(
int val) { SetValue(val + GetValue()); }
170 void operator-=(
int val) { SetValue(GetValue() - val); }
171 void operator*=(
int val) { SetValue(val * GetValue()); }
172 void operator/=(
int val) { SetValue(GetValue() / val); }
174 bool operator<=(
int val)
const {
return GetValue() <= val; };
175 bool operator>=(
int val)
const {
return GetValue() >= val; };
176 bool operator<(
int val)
const {
return GetValue() < val; };
177 bool operator>(
int val)
const {
return GetValue() > val; };
178 bool operator==(
int val)
const {
return GetValue() == val; };
179 bool operator!=(
int val)
const {
return GetValue() != val; };
183 void operator=(
const gd::String& val) { SetString(val); };
184 void operator+=(
const gd::String& val) { SetString(GetString() + val); }
186 bool operator==(
const gd::String& val)
const {
return GetString() == val; };
187 bool operator!=(
const gd::String& val)
const {
return GetString() != val; };
190 void operator=(
const char* val) { SetString(val); };
191 void operator+=(
const char* val) { SetString(GetString() + val); }
193 bool operator==(
const char* val)
const {
return GetString() == val; };
194 bool operator!=(
const char* val)
const {
return GetString() != val; };
198 void operator=(
const bool val) { SetBool(val); };
200 bool operator==(
const bool val)
const {
return GetBool() == val; };
201 bool operator!=(
const bool val)
const {
return GetBool() != val; };
218 childrenArray.clear();
225 return type == Type::Structure ? children.size()
226 : type == Type::Array ? childrenArray.size()
276 std::vector<gd::String> GetAllChildrenNames()
const;
289 bool Contains(
const gd::Variable& variableToSearch,
bool recursive)
const;
294 void RemoveRecursively(
const gd::Variable& variableToRemove);
308 Variable& GetAtIndex(
const size_t index);
316 const Variable& GetAtIndex(
const size_t index)
const;
328 void RemoveAtIndex(
const size_t index);
333 void MoveChildInArray(
const size_t oldIndex,
const size_t newIndex);
338 bool InsertAtIndex(
const gd::Variable& variable,
const size_t index);
349 return childrenArray;
420 mutable double value;
421 mutable bool boolVal =
false;
422 mutable bool hasMixedValues;
423 mutable std::map<gd::String, std::shared_ptr<Variable>>
425 mutable std::vector<std::shared_ptr<Variable>>
435 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:224
const std::map< gd::String, std::shared_ptr< Variable > > & GetAllChildren() const
Get the map containing all the children.
Definition: Variable.h:281
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:360
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:403
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:216
const std::vector< std::shared_ptr< Variable > > & GetAllChildrenArray() const
Get the vector containing all the children.
Definition: Variable.h:348
void SetFolded(bool fold=true)
Set if the children must be folded.
Definition: Variable.h:355
Definition: CommonTools.h:24
Type
Type of JSON value.
Definition: rapidjson.h:603