Util: Add more ways of accessing and creating Json::Value objects
This commit is contained in:
+18
-1
@@ -7,6 +7,7 @@
|
||||
#ifndef JSON_ARRAY_H
|
||||
#define JSON_ARRAY_H
|
||||
|
||||
#include <initializer_list>
|
||||
#include <utility> // move
|
||||
#include <vector>
|
||||
|
||||
@@ -19,6 +20,10 @@ public:
|
||||
Array() {}
|
||||
virtual ~Array() {}
|
||||
|
||||
Array(const std::initializer_list<Value>& values)
|
||||
: m_values(values)
|
||||
{}
|
||||
|
||||
Array(const Array& other)
|
||||
: m_values(other.m_values)
|
||||
{
|
||||
@@ -29,6 +34,19 @@ public:
|
||||
m_values.emplace_back(std::move(value));
|
||||
}
|
||||
|
||||
Value& at(size_t index)
|
||||
{
|
||||
if (index + 1 > m_values.size()) {
|
||||
m_values.resize(index + 1);
|
||||
}
|
||||
|
||||
return m_values.at(index);
|
||||
}
|
||||
Value& operator[](size_t index) { return at(index); }
|
||||
const Value& at(size_t index) const { return m_values.at(index); }
|
||||
const Value& operator[](size_t index) const { return m_values.at(index); }
|
||||
|
||||
size_t size() const { return m_values.size(); }
|
||||
const std::vector<Value>& values() const { return m_values; }
|
||||
|
||||
private:
|
||||
@@ -37,5 +55,4 @@ private:
|
||||
|
||||
} // namespace Json
|
||||
|
||||
|
||||
#endif // JSON_ARRAY_H
|
||||
|
||||
Reference in New Issue
Block a user