diff --git a/GMLIB/GMLIB.dll b/GMLIB/GMLIB.dll index 2f94785..a6a7bf7 100644 Binary files a/GMLIB/GMLIB.dll and b/GMLIB/GMLIB.dll differ diff --git a/GMLIB/manifest.json b/GMLIB/manifest.json index 625a8cd..1340fc7 100644 --- a/GMLIB/manifest.json +++ b/GMLIB/manifest.json @@ -4,5 +4,5 @@ "type": "native", "author": "GroupMountain", "description": "Group Mountain Library", - "version": "0.5.2" + "version": "0.5.3" } \ No newline at end of file diff --git a/include/GMLIB/Files/JsonConfig.h b/include/GMLIB/Files/JsonConfig.h index 317e0fd..ef58efa 100644 --- a/include/GMLIB/Files/JsonConfig.h +++ b/include/GMLIB/Files/JsonConfig.h @@ -1,5 +1,6 @@ #pragma once #include "GMLIB/GMLIB.h" +#include "nlohmann/json.hpp" class GMLIB_JsonConfig { public: @@ -7,9 +8,9 @@ class GMLIB_JsonConfig { nlohmann::ordered_json mValue; public: - GMLIB_JsonConfig(std::string filePath, std::string defaultJson); - GMLIB_JsonConfig(std::string filePath, nlohmann::ordered_json defaultJson); - GMLIB_JsonConfig() = delete; + GMLIB_API GMLIB_JsonConfig(std::string filePath, std::string defaultJson); + GMLIB_API GMLIB_JsonConfig(std::string filePath, nlohmann::ordered_json defaultJson); + GMLIB_API GMLIB_JsonConfig() = delete; public: virtual ~GMLIB_JsonConfig(); @@ -18,13 +19,59 @@ class GMLIB_JsonConfig { GMLIB_API bool initConfig(); template - GMLIB_API std::optional getValue(std::vector key); + inline std::optional getValue(std::vector path) { + try { + if (path.empty()) { + return {}; + } + auto value = mValue; + for (auto& key : path) { + if (value.is_object() && value.contains(key)) { + value = value[key]; + } else { + return {}; + } + } + return value.get(); + } catch (...) { + return {}; + } + } template - GMLIB_API T getValue(std::vector key, T defaultValue); + inline T getValue(std::vector path, T defaultValue) { + try { + std::optional result = getValue(path); + if (result.has_value()) { + return result.value(); + } + this->setValue(path, defaultValue); + return defaultValue; + } catch (...) { + this->setValue(path, defaultValue); + return defaultValue; + } + } template - GMLIB_API bool setValue(std::vector key, T value); + inline bool setValue(std::vector path, T data) { + try { + if (path.empty()) { + return false; + } + nlohmann::ordered_json* jsonObj = &mValue; + for (auto& key : path) { + if (jsonObj->is_null()) { + *jsonObj = nlohmann::ordered_json::object(); + } + jsonObj = &(*jsonObj)[key]; + } + *jsonObj = data; + return this->writeFile(); + } catch (...) { + return false; + } + } GMLIB_API bool deleteKey(std::vector key); diff --git a/include/GMLIB/Files/JsonLanguage.h b/include/GMLIB/Files/JsonLanguage.h index c3b160e..3e2ec8c 100644 --- a/include/GMLIB/Files/JsonLanguage.h +++ b/include/GMLIB/Files/JsonLanguage.h @@ -6,9 +6,9 @@ class GMLIB_JsonLanguage : public GMLIB_JsonConfig { public: public: - GMLIB_JsonLanguage(std::string filePath, std::string defaultJson); - GMLIB_JsonLanguage(std::string filePath, nlohmann::ordered_json defaultJson); - GMLIB_JsonLanguage() = delete; + GMLIB_API GMLIB_JsonLanguage(std::string filePath, std::string defaultJson); + GMLIB_API GMLIB_JsonLanguage(std::string filePath, nlohmann::ordered_json defaultJson); + GMLIB_API GMLIB_JsonLanguage() = delete; public: GMLIB_API std::string getValue(std::string key); diff --git a/manifest.json b/manifest.json index 625a8cd..1340fc7 100644 --- a/manifest.json +++ b/manifest.json @@ -4,5 +4,5 @@ "type": "native", "author": "GroupMountain", "description": "Group Mountain Library", - "version": "0.5.2" + "version": "0.5.3" } \ No newline at end of file diff --git a/src/Files/JsonConfig.cc b/src/Files/JsonConfig.cc index cc5ac1d..46aca18 100644 --- a/src/Files/JsonConfig.cc +++ b/src/Files/JsonConfig.cc @@ -46,60 +46,6 @@ bool GMLIB_JsonConfig::writeFile() { nlohmann::ordered_json GMLIB_JsonConfig::getSelf() { return mValue; } -template -std::optional GMLIB_JsonConfig::getValue(std::vector path) { - try { - if (path.empty()) { - return {}; - } - auto value = mValue; - for (auto& key : path) { - if (value.is_object() && value.contains(key)) { - value = value[key]; - } else { - return {}; - } - } - return value.get(); - } catch (...) { - return {}; - } -} - -template -T GMLIB_JsonConfig::getValue(std::vector path, T defaultValue) { - try { - std::optional result = getValue(path); - if (result.has_value) { - return result.value(); - } - this->setValue(path, defaultValue); - return defaultValue; - } catch (...) { - return false; - } -} - -template -bool GMLIB_JsonConfig::setValue(std::vector path, T data) { - try { - if (path.empty()) { - return false; - } - nlohmann::ordered_json* jsonObj = &mValue; - for (auto& key : path) { - if (jsonObj->is_null()) { - *jsonObj = nlohmann::ordered_json::object(); - } - jsonObj = &(*jsonObj)[key]; - } - *jsonObj = data; - return this->writeFile(); - } catch (...) { - return false; - } -} - bool GMLIB_JsonConfig::deleteKey(std::vector path) { try { if (path.empty()) { diff --git a/src/Version.h b/src/Version.h index fb99663..9bfa528 100644 --- a/src/Version.h +++ b/src/Version.h @@ -4,7 +4,7 @@ #define LIB_VERSION_MAJOR 0 #define LIB_VERSION_MINOR 5 -#define LIB_VERSION_REVISION 2 +#define LIB_VERSION_REVISION 3 #define LIB_VERSION_PRERELEASE "" #define LIB_VERSION_BUILD_META "" diff --git a/tooth.json b/tooth.json index 09fee2f..cb65ca0 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/GroupMountain/GMLIB", - "version": "0.5.2", + "version": "0.5.3", "info": { "name": "GMLIB", "description": "Group Mountain Library",