Util: Add size() getter to Json::Value
This commit is contained in:
+21
-1
@@ -87,7 +87,7 @@ Value::Value(const std::initializer_list<Value>& values)
|
|||||||
{
|
{
|
||||||
bool isObject = std::all_of(values.begin(), values.end(), [](const Value& value) {
|
bool isObject = std::all_of(values.begin(), values.end(), [](const Value& value) {
|
||||||
return value.type() == Type::Array
|
return value.type() == Type::Array
|
||||||
&& value.m_value.asArray->size() == 2
|
&& value.size() == 2
|
||||||
&& value[0].m_type == Type::String;
|
&& value[0].m_type == Type::String;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -186,6 +186,26 @@ const Value& Value::operator[](const std::string& key) const
|
|||||||
|
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
|
|
||||||
|
size_t Value::size() const
|
||||||
|
{
|
||||||
|
switch (m_type) {
|
||||||
|
case Type::Null:
|
||||||
|
return 0;
|
||||||
|
case Type::Bool:
|
||||||
|
case Type::Number:
|
||||||
|
case Type::String:
|
||||||
|
return 1;
|
||||||
|
case Type::Array:
|
||||||
|
return m_value.asArray->size();
|
||||||
|
case Type::Object:
|
||||||
|
return m_value.asObject->size();
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------
|
||||||
|
|
||||||
void Value::create()
|
void Value::create()
|
||||||
{
|
{
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public:
|
|||||||
// --------------------------------------
|
// --------------------------------------
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
size_t size() const;
|
||||||
|
|
||||||
bool asBool() const { return m_value.asBool; }
|
bool asBool() const { return m_value.asBool; }
|
||||||
double asDouble() const { return m_value.asDouble; }
|
double asDouble() const { return m_value.asDouble; }
|
||||||
|
|||||||
Reference in New Issue
Block a user