From 2915c1c1ec235bf7147b1d539f7a0ac80e608619 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 18 Jul 2022 15:10:11 +0200 Subject: [PATCH] Util: Reorder Array/Object functions, add empty() --- src/util/json/array.h | 14 +++++++++++--- src/util/json/object.h | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/util/json/array.h b/src/util/json/array.h index 57a768c..138c214 100644 --- a/src/util/json/array.h +++ b/src/util/json/array.h @@ -30,18 +30,26 @@ public: { } - void clear() { m_elements.clear(); } - void emplace_back(Value element); + // Capacity + + bool empty() const { return m_elements.empty(); } + size_t size() const { return m_elements.size(); } void reserve(size_t size) { m_elements.reserve(size); } + // Element access + Value& operator[](size_t index); Value& at(size_t index) { return m_elements.at(index); } const Value& at(size_t index) const { return m_elements.at(index); } - size_t size() const { return m_elements.size(); } const std::vector& elements() const { return m_elements; } + // Modifiers + + void clear() { m_elements.clear(); } + void emplace_back(Value element); + private: std::vector m_elements; }; diff --git a/src/util/json/object.h b/src/util/json/object.h index 2dfb0d0..5fbcd74 100644 --- a/src/util/json/object.h +++ b/src/util/json/object.h @@ -27,17 +27,25 @@ public: { } - void clear() { m_members.clear(); } - void emplace(const std::string& name, Value value); + // Capacity + + bool empty() const { return m_members.empty(); } + size_t size() const { return m_members.size(); } + + // Member access Value& operator[](const std::string& name); Value& at(const std::string& name) { return m_members.at(name); } const Value& at(const std::string& name) const { return m_members.at(name); } - size_t size() const { return m_members.size(); } const std::map& members() const { return m_members; } + // Modifiers + + void clear() { m_members.clear(); } + void emplace(const std::string& name, Value value); + private: std::map m_members; };