Fixed a few smalled issues with variant. Also added 2 new helper methods to it.

This commit is contained in:
Relintai 2022-01-09 14:30:42 +01:00
parent 10effc3971
commit bede579bf6
2 changed files with 19 additions and 8 deletions

View File

@ -3,7 +3,7 @@
#include "core/math/math.h" #include "core/math/math.h"
#include "core/reference.h" #include "core/reference.h"
Variant::Type Variant::get_type() { Variant::Type Variant::get_type() const {
return _type; return _type;
} }
@ -79,11 +79,6 @@ void Variant::zero() {
} }
void Variant::parse(const String &str) { void Variant::parse(const String &str) {
if (str.is_bool()) {
set_bool(str.to_bool());
return;
}
if (str.is_int()) { if (str.is_int()) {
set_int(str.to_int()); set_int(str.to_int());
return; return;
@ -99,6 +94,11 @@ void Variant::parse(const String &str) {
return; return;
} }
if (str.is_bool()) {
set_bool(str.to_bool());
return;
}
set_string(str); set_string(str);
} }
Variant Variant::parse_string(const String &str) { Variant Variant::parse_string(const String &str) {
@ -144,6 +144,14 @@ bool Variant::is_reference() const {
return false; return false;
} }
bool Variant::is_primitive_type() const {
return _type == TYPE_BOOL || _type == TYPE_INT || _type == TYPE_UINT || _type == TYPE_FLOAT;
}
bool Variant::is_simple_type() const {
return _type == TYPE_BOOL || _type == TYPE_INT || _type == TYPE_UINT || _type == TYPE_FLOAT || _type == TYPE_STRING;
}
bool Variant::to_bool() const { bool Variant::to_bool() const {
return _bool; return _bool;
} }
@ -430,7 +438,7 @@ void Variant::set_pointer(void *value) {
void Variant::set_variant(const Variant &value) { void Variant::set_variant(const Variant &value) {
clear(); clear();
switch (_type) { switch (value._type) {
case TYPE_NULL: case TYPE_NULL:
break; break;
case TYPE_BOOL: case TYPE_BOOL:

View File

@ -19,7 +19,7 @@ public:
TYPE_POINTER, TYPE_POINTER,
}; };
Type get_type(); Type get_type() const;
void clear(); void clear();
void zero(); void zero();
@ -38,6 +38,9 @@ public:
bool is_pointer() const; bool is_pointer() const;
bool is_reference() const; bool is_reference() const;
bool is_primitive_type() const;
bool is_simple_type() const;
bool to_bool() const; bool to_bool() const;
int to_int() const; int to_int() const;
uint64_t to_uint() const; uint64_t to_uint() const;