AK: Use [[nodiscard]] in JsonObject and JsonArray

This commit is contained in:
Max Wipfli 2021-06-28 14:17:14 +02:00 committed by Andreas Kling
parent 9c8a2a5f69
commit ed2bf0a753
Notes: sideshowbarker 2024-07-18 11:21:12 +09:00
2 changed files with 23 additions and 23 deletions

View File

@ -48,11 +48,11 @@ public:
return *this;
}
size_t size() const { return m_values.size(); }
bool is_empty() const { return m_values.is_empty(); }
[[nodiscard]] size_t size() const { return m_values.size(); }
[[nodiscard]] bool is_empty() const { return m_values.is_empty(); }
JsonValue const& at(size_t index) const { return m_values.at(index); }
JsonValue const& operator[](size_t index) const { return at(index); }
[[nodiscard]] JsonValue const& at(size_t index) const { return m_values.at(index); }
[[nodiscard]] JsonValue const& operator[](size_t index) const { return at(index); }
void clear() { m_values.clear(); }
void append(JsonValue value) { m_values.append(move(value)); }
@ -64,7 +64,7 @@ public:
template<typename Builder>
void serialize(Builder&) const;
String to_string() const { return serialized<StringBuilder>(); }
[[nodiscard]] String to_string() const { return serialized<StringBuilder>(); }
template<typename Callback>
void for_each(Callback callback) const
@ -73,7 +73,7 @@ public:
callback(value);
}
Vector<JsonValue> const& values() const { return m_values; }
[[nodiscard]] Vector<JsonValue> const& values() const { return m_values; }
void ensure_capacity(size_t capacity) { m_values.ensure_capacity(capacity); }

View File

@ -44,10 +44,10 @@ public:
return *this;
}
size_t size() const { return m_members.size(); }
bool is_empty() const { return m_members.is_empty(); }
[[nodiscard]] size_t size() const { return m_members.size(); }
[[nodiscard]] bool is_empty() const { return m_members.is_empty(); }
JsonValue const& get(String const& key) const
[[nodiscard]] JsonValue const& get(String const& key) const
{
auto* value = get_ptr(key);
static JsonValue* s_null_value { nullptr };
@ -59,7 +59,7 @@ public:
return *value;
}
JsonValue const* get_ptr(String const& key) const
[[nodiscard]] JsonValue const* get_ptr(String const& key) const
{
auto it = m_members.find(key);
if (it == m_members.end())
@ -67,63 +67,63 @@ public:
return &(*it).value;
}
bool has(String const& key) const
[[nodiscard]] [[nodiscard]] bool has(String const& key) const
{
return m_members.contains(key);
}
bool has_null(String const& key) const
[[nodiscard]] bool has_null(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_null();
}
bool has_bool(String const& key) const
[[nodiscard]] bool has_bool(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_bool();
}
bool has_string(String const& key) const
[[nodiscard]] bool has_string(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_string();
}
bool has_i32(String const& key) const
[[nodiscard]] bool has_i32(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_i32();
}
bool has_u32(String const& key) const
[[nodiscard]] bool has_u32(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_u32();
}
bool has_i64(String const& key) const
[[nodiscard]] bool has_i64(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_i64();
}
bool has_u64(String const& key) const
[[nodiscard]] bool has_u64(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_u64();
}
bool has_number(String const& key) const
[[nodiscard]] bool has_number(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_number();
}
bool has_array(String const& key) const
[[nodiscard]] bool has_array(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_array();
}
bool has_object(String const& key) const
[[nodiscard]] bool has_object(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_object();
}
#ifndef KERNEL
bool has_double(String const& key) const
[[nodiscard]] [[nodiscard]] bool has_double(String const& key) const
{
auto* value = get_ptr(key);
return value && value->is_double();
@ -153,7 +153,7 @@ public:
template<typename Builder>
void serialize(Builder&) const;
String to_string() const { return serialized<StringBuilder>(); }
[[nodiscard]] String to_string() const { return serialized<StringBuilder>(); }
private:
OrderedHashMap<String, JsonValue> m_members;