Browse Source

Util: Rename Array m_values -> m_elements

master
Riyyi 2 years ago
parent
commit
5835c63bda
  1. 10
      src/util/json/array.cpp
  2. 20
      src/util/json/array.h
  3. 4
      src/util/json/fromjson.h
  4. 2
      src/util/json/serializer.cpp

10
src/util/json/array.cpp

@ -9,18 +9,18 @@
namespace Json { namespace Json {
void Array::emplace_back(Value value) void Array::emplace_back(Value element)
{ {
m_values.emplace_back(std::move(value)); m_elements.emplace_back(std::move(element));
} }
Value& Array::operator[](size_t index) Value& Array::operator[](size_t index)
{ {
if (index + 1 > m_values.size()) { if (index + 1 > m_elements.size()) {
m_values.resize(index + 1); m_elements.resize(index + 1);
} }
return m_values[index]; return m_elements[index];
} }
} // namespace Json } // namespace Json

20
src/util/json/array.h

@ -21,28 +21,28 @@ public:
Array() {} Array() {}
virtual ~Array() {} virtual ~Array() {}
Array(const std::vector<Value>& values) Array(const std::vector<Value>& elements)
: m_values(values) : m_elements(elements)
{} {}
Array(const Array& other) Array(const Array& other)
: m_values(other.m_values) : m_elements(other.m_elements)
{ {
} }
void emplace_back(Value value); void emplace_back(Value element);
void reserve(size_t size) { m_values.reserve(size); } void reserve(size_t size) { m_elements.reserve(size); }
Value& operator[](size_t index); Value& operator[](size_t index);
Value& at(size_t index) { return m_values.at(index); } Value& at(size_t index) { return m_elements.at(index); }
const Value& at(size_t index) const { return m_values.at(index); } const Value& at(size_t index) const { return m_elements.at(index); }
size_t size() const { return m_values.size(); } size_t size() const { return m_elements.size(); }
const std::vector<Value>& values() const { return m_values; } const std::vector<Value>& elements() const { return m_elements; }
private: private:
std::vector<Value> m_values; std::vector<Value> m_elements;
}; };
} // namespace Json } // namespace Json

4
src/util/json/fromjson.h

@ -72,8 +72,8 @@ void fromJson(const Json& json, std::vector<T>& array)
assert(json.type() == Json::Type::Array); assert(json.type() == Json::Type::Array);
array.resize(json.size()); array.resize(json.size());
std::transform( std::transform(
json.asArray().values().begin(), json.asArray().elements().begin(),
json.asArray().values().end(), json.asArray().elements().end(),
array.begin(), array.begin(),
[](const Json& json) { [](const Json& json) {
return json.template get<T>(); // (missing-dependent-template-keyword) return json.template get<T>(); // (missing-dependent-template-keyword)

2
src/util/json/serializer.cpp

@ -77,7 +77,7 @@ std::string Serializer::dumpArray(const Value& value, const uint32_t indentLevel
result += '\n'; result += '\n';
} }
auto values = value.asArray().values(); auto values = value.asArray().elements();
for (auto it = values.begin(); it != values.end(); ++it) { for (auto it = values.begin(); it != values.end(); ++it) {
result += std::string(m_indent * (indentLevel + 1), m_indentCharacter); result += std::string(m_indent * (indentLevel + 1), m_indentCharacter);
result += dumpHelper(*it, indentLevel + 1); result += dumpHelper(*it, indentLevel + 1);

Loading…
Cancel
Save