Browse Source

Util: Reorder Array/Object functions, add empty()

master
Riyyi 2 years ago
parent
commit
2915c1c1ec
  1. 14
      src/util/json/array.h
  2. 14
      src/util/json/object.h

14
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<Value>& elements() const { return m_elements; }
// Modifiers
void clear() { m_elements.clear(); }
void emplace_back(Value element);
private:
std::vector<Value> m_elements;
};

14
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<std::string, Value>& members() const { return m_members; }
// Modifiers
void clear() { m_members.clear(); }
void emplace(const std::string& name, Value value);
private:
std::map<std::string, Value> m_members;
};

Loading…
Cancel
Save