From 0c1706ce6f7076412ace0100b52839115d91faaa Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Fri, 23 Dec 2022 00:14:15 -0600 Subject: [PATCH] Removing unused JSON functionality --- scwx-qt/source/scwx/qt/config/radar_site.cpp | 2 + scwx-qt/source/scwx/qt/util/json.cpp | 224 +------------------ scwx-qt/source/scwx/qt/util/json.hpp | 24 +- 3 files changed, 4 insertions(+), 246 deletions(-) diff --git a/scwx-qt/source/scwx/qt/config/radar_site.cpp b/scwx-qt/source/scwx/qt/config/radar_site.cpp index 5e58ef53..74a44290 100644 --- a/scwx-qt/source/scwx/qt/config/radar_site.cpp +++ b/scwx-qt/source/scwx/qt/config/radar_site.cpp @@ -7,6 +7,8 @@ #include #include +#include + namespace scwx { namespace qt diff --git a/scwx-qt/source/scwx/qt/util/json.cpp b/scwx-qt/source/scwx/qt/util/json.cpp index fcb40cea..7d5346d7 100644 --- a/scwx-qt/source/scwx/qt/util/json.cpp +++ b/scwx-qt/source/scwx/qt/util/json.cpp @@ -3,6 +3,7 @@ #include +#include #include #include #include @@ -34,229 +35,6 @@ static void PrettyPrintJson(std::ostream& os, static boost::json::value ReadJsonFile(QFile& file); static boost::json::value ReadJsonStream(std::istream& is); -bool FromJsonBool(const boost::json::object& json, - const std::string& key, - bool& value, - const bool defaultValue) -{ - const boost::json::value* jv = json.if_contains(key); - bool dirty = true; - - if (jv != nullptr) - { - if (jv->is_bool()) - { - value = boost::json::value_to(*jv); - dirty = false; - } - else - { - logger_->warn("{} is not a bool ({}), setting to default: {}", - key, - jv->kind(), - defaultValue); - value = defaultValue; - } - } - else - { - logger_->debug( - "{} is not present, setting to default: {}", key, defaultValue); - value = defaultValue; - } - - return !dirty; -} - -bool FromJsonInt64(const boost::json::object& json, - const std::string& key, - int64_t& value, - const int64_t defaultValue, - std::optional minValue, - std::optional maxValue) -{ - const boost::json::value* jv = json.if_contains(key); - bool dirty = true; - - if (jv != nullptr) - { - if (jv->is_int64()) - { - value = boost::json::value_to(*jv); - - if (minValue.has_value() && value < *minValue) - { - logger_->warn("{0} less than minimum ({1} < {2}), setting to: {2}", - key, - value, - *minValue); - value = *minValue; - } - else if (maxValue.has_value() && value > *maxValue) - { - logger_->warn( - "{0} greater than maximum ({1} > {2}), setting to: {2}", - key, - value, - *maxValue); - value = *maxValue; - } - else - { - dirty = false; - } - } - else - { - logger_->warn("{} is not an int64 ({}), setting to default: {}", - key, - jv->kind(), - defaultValue); - value = defaultValue; - } - } - else - { - logger_->debug( - "{} is not present, setting to default: {}", key, defaultValue); - value = defaultValue; - } - - return !dirty; -} - -bool FromJsonInt64Array(const boost::json::object& json, - const std::string& key, - std::vector& values, - const std::vector& defaultValues, - std::optional minValue, - std::optional maxValue) -{ - const boost::json::value* jv = json.if_contains(key); - bool dirty = true; - - if (jv != nullptr) - { - if (jv->is_array()) - { - bool validArray = false; - - try - { - values = boost::json::value_to>(*jv); - validArray = true; - } - catch (const std::exception& ex) - { - logger_->warn( - "{} is an invalid array of int64 ({}), setting to default: {}", - key, - ex.what(), - defaultValues); - values = defaultValues; - } - - if (values.empty()) - { - logger_->warn("{} is an empty array, setting to default: {}", - key, - defaultValues); - values = defaultValues; - } - else if (validArray) - { - dirty = false; - - for (auto& value : values) - { - if (minValue.has_value() && value < *minValue) - { - logger_->warn( - "{0} less than minimum ({1} < {2}), setting to: {2}", - key, - value, - *minValue); - value = *minValue; - dirty = true; - } - else if (maxValue.has_value() && value > *maxValue) - { - logger_->warn( - "{0} greater than maximum ({1} > {2}), setting to: {2}", - key, - value, - *maxValue); - value = *maxValue; - dirty = true; - } - } - } - } - else - { - logger_->warn("{} is not an array ({}), setting to default: {}", - key, - jv->kind(), - defaultValues); - values = defaultValues; - } - } - else - { - logger_->debug( - "{} is not present, setting to default: {}", key, defaultValues); - values = defaultValues; - } - - return !dirty; -} - -bool FromJsonString(const boost::json::object& json, - const std::string& key, - std::string& value, - const std::string& defaultValue, - size_t minLength) -{ - const boost::json::value* jv = json.if_contains(key); - bool dirty = true; - - if (jv != nullptr) - { - if (jv->is_string()) - { - value = boost::json::value_to(*jv); - - if (value.length() >= minLength) - { - dirty = false; - } - else - { - logger_->warn( - "{} is shorter than {} characters, setting to default: {}", - key, - minLength, - defaultValue); - value = defaultValue; - } - } - else - { - logger_->warn( - "{} is not a string, setting to default: {}", key, defaultValue); - value = defaultValue; - } - } - else - { - logger_->debug( - "{} is not present, setting to default: {}", key, defaultValue); - value = defaultValue; - } - - return !dirty; -} - boost::json::value ReadJsonFile(const std::string& path) { boost::json::value json; diff --git a/scwx-qt/source/scwx/qt/util/json.hpp b/scwx-qt/source/scwx/qt/util/json.hpp index 3d6a7215..bbf497f4 100644 --- a/scwx-qt/source/scwx/qt/util/json.hpp +++ b/scwx-qt/source/scwx/qt/util/json.hpp @@ -2,7 +2,7 @@ #include -#include +#include namespace scwx { @@ -13,28 +13,6 @@ namespace util namespace json { -bool FromJsonBool(const boost::json::object& json, - const std::string& key, - bool& value, - const bool defaultValue); -bool FromJsonInt64(const boost::json::object& json, - const std::string& key, - int64_t& value, - const int64_t defaultValue, - std::optional minValue, - std::optional maxValue); -bool FromJsonInt64Array(const boost::json::object& json, - const std::string& key, - std::vector& values, - const std::vector& defaultValues, - std::optional minValue, - std::optional maxValue); -bool FromJsonString(const boost::json::object& json, - const std::string& key, - std::string& value, - const std::string& defaultValue, - size_t minLength = 0); - boost::json::value ReadJsonFile(const std::string& path); void WriteJsonFile(const std::string& path, const boost::json::value& json,