summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Buhagiar <jooster669@gmail.com>2021-05-26 23:23:31 +1000
committerLinus Groh <mail@linusgroh.de>2021-05-28 16:37:25 +0100
commit786275feb86ea1d2c1849e6422bceaf54233b70b (patch)
tree5855152575da53358a2a7292f63d30f0aab90e3c
parent9adcfd57261a4627501e8502a446160e0b499e7d (diff)
downloadserenity-786275feb86ea1d2c1849e6422bceaf54233b70b.zip
LibGUI: Add u64 type to LibGUI::Variant
`uint` has also been more appropriately renamed to u32.
-rw-r--r--Userland/Libraries/LibGUI/AutocompleteProvider.cpp2
-rw-r--r--Userland/Libraries/LibGUI/Variant.cpp52
-rw-r--r--Userland/Libraries/LibGUI/Variant.h40
3 files changed, 63 insertions, 31 deletions
diff --git a/Userland/Libraries/LibGUI/AutocompleteProvider.cpp b/Userland/Libraries/LibGUI/AutocompleteProvider.cpp
index bc6d8162f1..d1798c31c2 100644
--- a/Userland/Libraries/LibGUI/AutocompleteProvider.cpp
+++ b/Userland/Libraries/LibGUI/AutocompleteProvider.cpp
@@ -177,7 +177,7 @@ void AutocompleteBox::apply_suggestion()
VERIFY(suggestion.length() >= partial_length);
auto completion_view = suggestion.substring_view(partial_length, suggestion.length() - partial_length);
- auto completion_kind = (GUI::AutocompleteProvider::CompletionKind)suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Kind).as_uint();
+ auto completion_kind = (GUI::AutocompleteProvider::CompletionKind)suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Kind).as_u32();
String completion;
if (completion_view.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::SystemInclude)
diff --git a/Userland/Libraries/LibGUI/Variant.cpp b/Userland/Libraries/LibGUI/Variant.cpp
index cd322fa84e..d70e8bf114 100644
--- a/Userland/Libraries/LibGUI/Variant.cpp
+++ b/Userland/Libraries/LibGUI/Variant.cpp
@@ -22,8 +22,10 @@ const char* to_string(Variant::Type type)
return "Int32";
case Variant::Type::Int64:
return "Int64";
- case Variant::Type::UnsignedInt:
- return "UnsignedInt";
+ case Variant::Type::UnsignedInt32:
+ return "UnsignedInt32";
+ case Variant::Type::UnsignedInt64:
+ return "UnsignedInt64";
case Variant::Type::Float:
return "Float";
case Variant::Type::String:
@@ -95,10 +97,16 @@ Variant::Variant(i64 value)
m_value.as_i64 = value;
}
-Variant::Variant(unsigned value)
- : m_type(Type::UnsignedInt)
+Variant::Variant(u32 value)
+ : m_type(Type::UnsignedInt32)
{
- m_value.as_uint = value;
+ m_value.as_u32 = value;
+}
+
+Variant::Variant(u64 value)
+ : m_type(Type::UnsignedInt64)
+{
+ m_value.as_u64 = value;
}
Variant::Variant(float value)
@@ -149,8 +157,8 @@ Variant::Variant(const JsonValue& value)
}
if (value.is_u32()) {
- m_type = Type::UnsignedInt;
- m_value.as_uint = value.as_u32();
+ m_type = Type::UnsignedInt32;
+ m_value.as_u32 = value.as_u32();
return;
}
@@ -161,9 +169,8 @@ Variant::Variant(const JsonValue& value)
}
if (value.is_u64()) {
- // FIXME: Variant should have a 64-bit internal type.
- m_type = Type::UnsignedInt;
- m_value.as_uint = value.to_u32();
+ m_type = Type::UnsignedInt64;
+ m_value.as_u64 = value.to_u64();
return;
}
@@ -273,8 +280,11 @@ void Variant::copy_from(const Variant& other)
case Type::Int64:
m_value.as_i64 = other.m_value.as_i64;
break;
- case Type::UnsignedInt:
- m_value.as_uint = other.m_value.as_uint;
+ case Type::UnsignedInt32:
+ m_value.as_u32 = other.m_value.as_u32;
+ break;
+ case Type::UnsignedInt64:
+ m_value.as_u64 = other.m_value.as_u64;
break;
case Type::Float:
m_value.as_float = other.m_value.as_float;
@@ -326,8 +336,10 @@ bool Variant::operator==(const Variant& other) const
return as_i32() == other.as_i32();
case Type::Int64:
return as_i64() == other.as_i64();
- case Type::UnsignedInt:
- return as_uint() == other.as_uint();
+ case Type::UnsignedInt32:
+ return as_u32() == other.as_u32();
+ case Type::UnsignedInt64:
+ return as_u64() == other.as_u64();
case Type::Float:
return as_float() == other.as_float();
case Type::String:
@@ -365,8 +377,10 @@ bool Variant::operator<(const Variant& other) const
return as_i32() < other.as_i32();
case Type::Int64:
return as_i64() < other.as_i64();
- case Type::UnsignedInt:
- return as_uint() < other.as_uint();
+ case Type::UnsignedInt32:
+ return as_u32() < other.as_u32();
+ case Type::UnsignedInt64:
+ return as_u64() < other.as_u64();
case Type::Float:
return as_float() < other.as_float();
case Type::String:
@@ -401,8 +415,10 @@ String Variant::to_string() const
return String::number(as_i32());
case Type::Int64:
return String::number(as_i64());
- case Type::UnsignedInt:
- return String::number(as_uint());
+ case Type::UnsignedInt32:
+ return String::number(as_u32());
+ case Type::UnsignedInt64:
+ return String::number(as_u64());
case Type::Float:
return String::formatted("{:.2}", as_float());
case Type::String:
diff --git a/Userland/Libraries/LibGUI/Variant.h b/Userland/Libraries/LibGUI/Variant.h
index 3b1eefa848..a9b0267e9f 100644
--- a/Userland/Libraries/LibGUI/Variant.h
+++ b/Userland/Libraries/LibGUI/Variant.h
@@ -20,7 +20,8 @@ public:
Variant(float);
Variant(i32);
Variant(i64);
- Variant(unsigned);
+ Variant(u32);
+ Variant(u64);
Variant(const char*);
Variant(const StringView&);
Variant(const String&);
@@ -49,7 +50,8 @@ public:
Bool,
Int32,
Int64,
- UnsignedInt,
+ UnsignedInt32,
+ UnsignedInt64,
Float,
String,
Bitmap,
@@ -66,7 +68,8 @@ public:
bool is_bool() const { return m_type == Type::Bool; }
bool is_i32() const { return m_type == Type::Int32; }
bool is_i64() const { return m_type == Type::Int64; }
- bool is_uint() const { return m_type == Type::UnsignedInt; }
+ bool is_u32() const { return m_type == Type::UnsignedInt32; }
+ bool is_u64() const { return m_type == Type::UnsignedInt64; }
bool is_float() const { return m_type == Type::Float; }
bool is_string() const { return m_type == Type::String; }
bool is_bitmap() const { return m_type == Type::Bitmap; }
@@ -95,8 +98,10 @@ public:
return m_value.as_i32 != 0;
if (type() == Type::Int64)
return m_value.as_i64 != 0;
- if (type() == Type::UnsignedInt)
- return m_value.as_uint != 0;
+ if (type() == Type::UnsignedInt32)
+ return m_value.as_u32 != 0;
+ if (type() == Type::UnsignedInt64)
+ return m_value.as_u64 != 0;
if (type() == Type::Rect)
return !as_rect().is_null();
if (type() == Type::Size)
@@ -118,10 +123,16 @@ public:
return m_value.as_i64;
}
- unsigned as_uint() const
+ u32 as_u32() const
{
- VERIFY(type() == Type::UnsignedInt);
- return m_value.as_uint;
+ VERIFY(type() == Type::UnsignedInt32);
+ return m_value.as_u32;
+ }
+
+ u64 as_u64() const
+ {
+ VERIFY(type() == Type::UnsignedInt64);
+ return m_value.as_u64;
}
template<typename T>
@@ -135,9 +146,13 @@ public:
return as_bool() ? 1 : 0;
if (is_float())
return (int)as_float();
- if (is_uint()) {
- VERIFY(as_uint() <= INT32_MAX);
- return (int)as_uint();
+ if (is_u32()) {
+ VERIFY(as_u32() <= INT32_MAX);
+ return static_cast<i32>(as_u32());
+ }
+ if (is_u64()) {
+ VERIFY(as_u64() <= INT64_MAX);
+ return static_cast<i64>(as_u64());
}
if (is_string())
return as_string().to_int().value_or(0);
@@ -256,7 +271,8 @@ private:
bool as_bool;
i32 as_i32;
i64 as_i64;
- unsigned as_uint;
+ u32 as_u32;
+ u64 as_u64;
float as_float;
Gfx::RGBA32 as_color;
Gfx::TextAlignment as_text_alignment;