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:
parent
ba390f9b34
commit
a1db1e6664
Notes:
sideshowbarker
2024-07-19 06:15:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a1db1e66645
3 changed files with 46 additions and 12 deletions
|
@ -85,25 +85,37 @@ public:
|
|||
m_builder.append(value ? "true" : "false");
|
||||
}
|
||||
|
||||
void add(const StringView& key, i32 value)
|
||||
void add(const StringView& key, int value)
|
||||
{
|
||||
begin_item(key);
|
||||
m_builder.appendf("%d", value);
|
||||
}
|
||||
|
||||
void add(const StringView& key, u32 value)
|
||||
void add(const StringView& key, unsigned value)
|
||||
{
|
||||
begin_item(key);
|
||||
m_builder.appendf("%u", value);
|
||||
}
|
||||
|
||||
void add(const StringView& key, i64 value)
|
||||
void add(const StringView& key, long value)
|
||||
{
|
||||
begin_item(key);
|
||||
m_builder.appendf("%ld", value);
|
||||
}
|
||||
|
||||
void add(const StringView& key, long unsigned value)
|
||||
{
|
||||
begin_item(key);
|
||||
m_builder.appendf("%lu", value);
|
||||
}
|
||||
|
||||
void add(const StringView& key, long long value)
|
||||
{
|
||||
begin_item(key);
|
||||
m_builder.appendf("%lld", value);
|
||||
}
|
||||
|
||||
void add(const StringView& key, u64 value)
|
||||
void add(const StringView& key, long long unsigned value)
|
||||
{
|
||||
begin_item(key);
|
||||
m_builder.appendf("%llu", value);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,10 +63,12 @@ public:
|
|||
JsonValue& operator=(const JsonValue&);
|
||||
JsonValue& operator=(JsonValue&&);
|
||||
|
||||
JsonValue(i32);
|
||||
JsonValue(u32);
|
||||
JsonValue(i64);
|
||||
JsonValue(u64);
|
||||
JsonValue(int);
|
||||
JsonValue(unsigned);
|
||||
JsonValue(long);
|
||||
JsonValue(long unsigned);
|
||||
JsonValue(long long);
|
||||
JsonValue(long long unsigned);
|
||||
|
||||
#if !defined(KERNEL)
|
||||
JsonValue(double);
|
||||
|
|
Loading…
Add table
Reference in a new issue