summaryrefslogtreecommitdiff
path: root/core/variant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/variant.cpp')
-rw-r--r--core/variant.cpp295
1 files changed, 201 insertions, 94 deletions
diff --git a/core/variant.cpp b/core/variant.cpp
index 35c306f24b..4a20e569cc 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1406,20 +1406,47 @@ void Variant::reference(const Variant &p_variant) {
void Variant::zero() {
switch (type) {
- case NIL: break;
- case BOOL: this->_data._bool = false; break;
- case INT: this->_data._int = 0; break;
- case FLOAT: this->_data._float = 0; break;
- case VECTOR2: *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2(); break;
- case VECTOR2I: *reinterpret_cast<Vector2i *>(this->_data._mem) = Vector2i(); break;
- case RECT2: *reinterpret_cast<Rect2 *>(this->_data._mem) = Rect2(); break;
- case RECT2I: *reinterpret_cast<Rect2i *>(this->_data._mem) = Rect2i(); break;
- case VECTOR3: *reinterpret_cast<Vector3 *>(this->_data._mem) = Vector3(); break;
- case VECTOR3I: *reinterpret_cast<Vector3i *>(this->_data._mem) = Vector3i(); break;
- case PLANE: *reinterpret_cast<Plane *>(this->_data._mem) = Plane(); break;
- case QUAT: *reinterpret_cast<Quat *>(this->_data._mem) = Quat(); break;
- case COLOR: *reinterpret_cast<Color *>(this->_data._mem) = Color(); break;
- default: this->clear(); break;
+ case NIL:
+ break;
+ case BOOL:
+ this->_data._bool = false;
+ break;
+ case INT:
+ this->_data._int = 0;
+ break;
+ case FLOAT:
+ this->_data._float = 0;
+ break;
+ case VECTOR2:
+ *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2();
+ break;
+ case VECTOR2I:
+ *reinterpret_cast<Vector2i *>(this->_data._mem) = Vector2i();
+ break;
+ case RECT2:
+ *reinterpret_cast<Rect2 *>(this->_data._mem) = Rect2();
+ break;
+ case RECT2I:
+ *reinterpret_cast<Rect2i *>(this->_data._mem) = Rect2i();
+ break;
+ case VECTOR3:
+ *reinterpret_cast<Vector3 *>(this->_data._mem) = Vector3();
+ break;
+ case VECTOR3I:
+ *reinterpret_cast<Vector3i *>(this->_data._mem) = Vector3i();
+ break;
+ case PLANE:
+ *reinterpret_cast<Plane *>(this->_data._mem) = Plane();
+ break;
+ case QUAT:
+ *reinterpret_cast<Quat *>(this->_data._mem) = Quat();
+ break;
+ case COLOR:
+ *reinterpret_cast<Color *>(this->_data._mem) = Color();
+ break;
+ default:
+ this->clear();
+ break;
}
}
@@ -1545,11 +1572,16 @@ Variant::operator signed int() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1560,11 +1592,16 @@ Variant::operator unsigned int() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1576,11 +1613,16 @@ Variant::operator int64_t() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int64();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int64();
default: {
return 0;
@@ -1612,11 +1654,16 @@ Variant::operator uint64_t() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1639,11 +1686,16 @@ Variant::operator signed long() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._real;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1657,11 +1709,16 @@ Variant::operator unsigned long() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._real;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._real;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1676,11 +1733,16 @@ Variant::operator signed short() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1691,11 +1753,16 @@ Variant::operator unsigned short() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1706,11 +1773,16 @@ Variant::operator signed char() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1721,11 +1793,16 @@ Variant::operator unsigned char() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1 : 0;
- case INT: return _data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_int();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1 : 0;
+ case INT:
+ return _data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_int();
default: {
return 0;
@@ -1742,11 +1819,16 @@ Variant::operator float() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1.0 : 0.0;
- case INT: return (float)_data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_double();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1.0 : 0.0;
+ case INT:
+ return (float)_data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_double();
default: {
return 0;
@@ -1757,11 +1839,16 @@ Variant::operator double() const {
switch (type) {
- case NIL: return 0;
- case BOOL: return _data._bool ? 1.0 : 0.0;
- case INT: return (double)_data._int;
- case FLOAT: return _data._float;
- case STRING: return operator String().to_double();
+ case NIL:
+ return 0;
+ case BOOL:
+ return _data._bool ? 1.0 : 0.0;
+ case INT:
+ return (double)_data._int;
+ case FLOAT:
+ return _data._float;
+ case STRING:
+ return operator String().to_double();
default: {
return 0;
@@ -1800,27 +1887,40 @@ Variant::operator String() const {
String Variant::stringify(List<const void *> &stack) const {
switch (type) {
- case NIL: return "Null";
- case BOOL: return _data._bool ? "True" : "False";
- case INT: return itos(_data._int);
- case FLOAT: return rtos(_data._float);
- case STRING: return *reinterpret_cast<const String *>(_data._mem);
- case VECTOR2: return "(" + operator Vector2() + ")";
- case VECTOR2I: return "(" + operator Vector2i() + ")";
- case RECT2: return "(" + operator Rect2() + ")";
- case RECT2I: return "(" + operator Rect2i() + ")";
+ case NIL:
+ return "Null";
+ case BOOL:
+ return _data._bool ? "True" : "False";
+ case INT:
+ return itos(_data._int);
+ case FLOAT:
+ return rtos(_data._float);
+ case STRING:
+ return *reinterpret_cast<const String *>(_data._mem);
+ case VECTOR2:
+ return "(" + operator Vector2() + ")";
+ case VECTOR2I:
+ return "(" + operator Vector2i() + ")";
+ case RECT2:
+ return "(" + operator Rect2() + ")";
+ case RECT2I:
+ return "(" + operator Rect2i() + ")";
case TRANSFORM2D: {
Transform2D mat32 = operator Transform2D();
return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")";
} break;
- case VECTOR3: return "(" + operator Vector3() + ")";
- case VECTOR3I: return "(" + operator Vector3i() + ")";
+ case VECTOR3:
+ return "(" + operator Vector3() + ")";
+ case VECTOR3I:
+ return "(" + operator Vector3i() + ")";
case PLANE:
return operator Plane();
//case QUAT:
- case AABB: return operator ::AABB();
- case QUAT: return "(" + operator Quat() + ")";
+ case AABB:
+ return operator ::AABB();
+ case QUAT:
+ return "(" + operator Quat() + ")";
case BASIS: {
Basis mat3 = operator Basis();
@@ -1846,10 +1946,14 @@ String Variant::stringify(List<const void *> &stack) const {
return mtx + ")";
} break;
- case TRANSFORM: return operator Transform();
- case STRING_NAME: return operator StringName();
- case NODE_PATH: return operator NodePath();
- case COLOR: return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a);
+ case TRANSFORM:
+ return operator Transform();
+ case STRING_NAME:
+ return operator StringName();
+ case NODE_PATH:
+ return operator NodePath();
+ case COLOR:
+ return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a);
case DICTIONARY: {
const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem);
@@ -3676,9 +3780,12 @@ bool Variant::is_shared() const {
switch (type) {
- case OBJECT: return true;
- case ARRAY: return true;
- case DICTIONARY: return true;
+ case OBJECT:
+ return true;
+ case ARRAY:
+ return true;
+ case DICTIONARY:
+ return true;
default: {
}
}