17#include <nlohmann/json.hpp>
21using json = nlohmann::json;
52 static auto
test() ->
void;
65 auto
read(const std::
string& keyPath, T& value) const ->
bool
67 assert(
isValid &&
"Stream is not valid. Ensure the file was opened successfully.");
72 size_t start = 0, end;
74 while ((end = keyPath.find(
'.', start)) != std::string::npos)
76 auto key = keyPath.substr(start, end - start);
77 current = ¤t->at(key);
81 auto lastKey = keyPath.substr(start);
82 value = current->at(lastKey).get<T>();
84 catch (
const json::exception& exception)
86 hlg::Error(
"Stream: JSON key error: {}", exception.what());
110 auto saveAs(
const std::string& newFilePath) -> void;
113 template <
typename T>
nlohmann::json json
Definition Json.cpp:19
std::string filePath
Definition Json.h:124
auto operator[](T *key)
Definition Json.h:114
auto data() -> json &
Definition Json.cpp:72
auto open(const std::string &filePath) -> bool
Definition Json.cpp:37
bool isValid
Definition Json.h:122
auto jsonDump(int pretty) -> void
Definition Json.cpp:116
Json(std::string filePath)
Constructor that opens and parses a JSON file.
Definition Json.cpp:22
json j
Definition Json.h:123
auto read(const std::string &keyPath, T &value) const -> bool
Definition Json.h:65
Json(const Json &)=default
static auto savingTest() -> void
Definition Json.cpp:186
auto save() -> void
Definition Json.cpp:121
auto saveAs(const std::string &newFilePath) -> void
Definition Json.cpp:157
auto clear() -> void
Definition Json.cpp:179
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