Util: Add exists() to Json::Value

This commit is contained in:
Riyyi
2022-07-08 14:11:03 +02:00
parent a209452a68
commit c5bbd7befd
2 changed files with 14 additions and 0 deletions
+11
View File
@@ -146,6 +146,17 @@ void Value::emplace(const std::string& key, Value value)
m_value.asObject->emplace(key, value); m_value.asObject->emplace(key, value);
} }
bool Value::exists(size_t index) const
{
return index < size();
}
bool Value::exists(const std::string& key) const
{
assert(m_type == Type::Object);
return m_value.asObject->members().find(key) != m_value.asObject->members().end();
}
// ------------------------------------------ // ------------------------------------------
Value& Value::operator[](size_t index) Value& Value::operator[](size_t index)
+3
View File
@@ -55,6 +55,9 @@ public:
void emplace_back(Value value); void emplace_back(Value value);
void emplace(const std::string& key, Value value); void emplace(const std::string& key, Value value);
bool exists(size_t index) const;
bool exists(const std::string& key) const;
// -------------------------------------- // --------------------------------------
// Array index operator // Array index operator