diff --git a/src/util/json/array.cpp b/src/util/json/array.cpp new file mode 100644 index 0000000..50e46a2 --- /dev/null +++ b/src/util/json/array.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2022 Riyyi + * + * SPDX-License-Identifier: MIT + */ + +#include "util/json/array.h" +#include "util/json/value.h" + +namespace Json { + +void Array::emplace_back(Value value) +{ + m_values.emplace_back(std::move(value)); +} + +Value& Array::at(size_t index) +{ + if (index + 1 > m_values.size()) { + m_values.resize(index + 1); + } + + return m_values.at(index); +} + +} // namespace Json diff --git a/src/util/json/array.h b/src/util/json/array.h index a22e807..b59c84a 100644 --- a/src/util/json/array.h +++ b/src/util/json/array.h @@ -12,10 +12,11 @@ #include #include "util/json/parser.h" -#include "util/json/value.h" namespace Json { +class Value; + class Array { public: Array() {} @@ -30,19 +31,9 @@ public: { } - void emplace_back(Value value) - { - m_values.emplace_back(std::move(value)); - } - - Value& at(size_t index) - { - if (index + 1 > m_values.size()) { - m_values.resize(index + 1); - } + void emplace_back(Value value); - return m_values.at(index); - } + Value& at(size_t 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); } diff --git a/src/util/json/object.cpp b/src/util/json/object.cpp new file mode 100644 index 0000000..8612897 --- /dev/null +++ b/src/util/json/object.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2022 Riyyi + * + * SPDX-License-Identifier: MIT + */ + +#include "util/json/object.h" +#include "util/json/value.h" + +namespace Json { + +void Object::emplace(const std::string& name, Value value) +{ + m_members.emplace(name, std::move(value)); +} + +Value& Object::at(const std::string& name) +{ + if (m_members.find(name) == m_members.end()) { + emplace(name, {}); + } + + return m_members.at(name); +} + +} // namespace Json diff --git a/src/util/json/object.h b/src/util/json/object.h index d8bf27f..71538ba 100644 --- a/src/util/json/object.h +++ b/src/util/json/object.h @@ -12,10 +12,11 @@ #include // move #include "util/json/parser.h" -#include "util/json/value.h" namespace Json { +class Value; + class Object { public: Object() {} @@ -26,19 +27,9 @@ public: { } - void emplace(const std::string& name, Value value) - { - m_members.emplace(name, std::move(value)); - } - - Value& at(const std::string& name) - { - if (m_members.find(name) == m_members.end()) { - emplace(name, {}); - } + void emplace(const std::string& name, Value value); - return m_members.at(name); - } + Value& at(const std::string& name); Value& operator[](const std::string& name) { return at(name); } const Value& at(const std::string& name) const { return m_members.at(name); } const Value& operator[](const std::string& name) const { return m_members.at(name); }