1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:44:58 +00:00

AK: Make JsonValue and JsonObjectSerializer speak int/long/long long

While width-oriented integer types are nicer from the programmer's
perspective, we have to accept that C++ thinks in int/long/long long.
This commit is contained in:
Andreas Kling 2020-05-22 13:57:23 +02:00
parent ba390f9b34
commit a1db1e6664
3 changed files with 46 additions and 12 deletions

View file

@ -129,27 +129,47 @@ bool JsonValue::equals(const JsonValue& other) const
return false;
}
JsonValue::JsonValue(i32 value)
JsonValue::JsonValue(int value)
: m_type(Type::Int32)
{
m_value.as_i32 = value;
}
JsonValue::JsonValue(u32 value)
JsonValue::JsonValue(unsigned value)
: m_type(Type::UnsignedInt32)
{
m_value.as_u32 = value;
}
JsonValue::JsonValue(i64 value)
JsonValue::JsonValue(long value)
: m_type(sizeof(long) == 8 ? Type::Int64 : Type::Int32)
{
if constexpr (sizeof(long) == 8)
m_value.as_i64 = value;
else
m_value.as_i32 = value;
}
JsonValue::JsonValue(unsigned long value)
: m_type(sizeof(long) == 8 ? Type::UnsignedInt64 : Type::UnsignedInt32)
{
if constexpr (sizeof(long) == 8)
m_value.as_u64 = value;
else
m_value.as_u32 = value;
}
JsonValue::JsonValue(long long value)
: m_type(Type::Int64)
{
static_assert(sizeof(long long unsigned) == 8);
m_value.as_i64 = value;
}
JsonValue::JsonValue(u64 value)
JsonValue::JsonValue(long long unsigned value)
: m_type(Type::UnsignedInt64)
{
static_assert(sizeof(long long unsigned) == 8);
m_value.as_u64 = value;
}