17#include <nlohmann/json.hpp>
21using json = nlohmann::json;
49 static auto test() -> void;
62 auto read(
const std::string& keyPath, T& value)
const ->
bool
64 assert(
isValid &&
"Stream is not valid. Ensure the file was opened successfully.");
69 size_t start = 0, end;
71 while ((end = keyPath.find(
'.', start)) != std::string::npos)
73 auto key = keyPath.substr(start, end - start);
74 current = ¤t->at(key);
78 auto lastKey = keyPath.substr(start);
79 value = current->at(lastKey).get<T>();
81 catch (
const json::exception& exception)
83 hlg::Error(
"Stream: JSON key error: {}", exception.what());
107 auto saveAs(
const std::string& newFilePath) -> void;
110 template <
typename T>
nlohmann::json json
Definition Json.cpp:19
std::string filePath
Definition Json.h:121
auto operator[](T *key)
Definition Json.h:111
auto data() -> json &
Definition Json.cpp:67
bool isValid
Definition Json.h:119
auto jsonDump(int pretty) -> void
Definition Json.cpp:106
Json(std::string filePath)
Constructor that opens and parses a JSON file.
Definition Json.cpp:22
json j
Definition Json.h:120
auto read(const std::string &keyPath, T &value) const -> bool
Definition Json.h:62
auto open(std::string filePath) -> bool
Definition Json.cpp:32
Json(const Json &)=default
static auto savingTest() -> void
Definition Json.cpp:176
auto save() -> void
Definition Json.cpp:111
auto saveAs(const std::string &newFilePath) -> void
Definition Json.cpp:147
auto clear() -> void
Definition Json.cpp:169
auto Error(spdlog::format_string_t< Args... > message, Args &&... args) -> void
Definition Logging.h:110
the type of elements in a basic_json container
Definition GameObject.h:32