mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 13:00:05 +00:00 
			
		
		
		
	Removing unused JSON functionality
This commit is contained in:
		
							parent
							
								
									6b90c5471d
								
							
						
					
					
						commit
						0c1706ce6f
					
				
					 3 changed files with 4 additions and 246 deletions
				
			
		|  | @ -7,6 +7,8 @@ | ||||||
| #include <shared_mutex> | #include <shared_mutex> | ||||||
| #include <unordered_map> | #include <unordered_map> | ||||||
| 
 | 
 | ||||||
|  | #include <boost/json.hpp> | ||||||
|  | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
| namespace qt | namespace qt | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <fstream> | #include <fstream> | ||||||
| 
 | 
 | ||||||
|  | #include <boost/json.hpp> | ||||||
| #include <fmt/ranges.h> | #include <fmt/ranges.h> | ||||||
| #include <QFile> | #include <QFile> | ||||||
| #include <QTextStream> | #include <QTextStream> | ||||||
|  | @ -34,229 +35,6 @@ static void PrettyPrintJson(std::ostream&             os, | ||||||
| static boost::json::value ReadJsonFile(QFile& file); | static boost::json::value ReadJsonFile(QFile& file); | ||||||
| static boost::json::value ReadJsonStream(std::istream& is); | 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<bool>(*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<int64_t>     minValue, |  | ||||||
|                    std::optional<int64_t>     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<int64_t>(*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<int64_t>&       values, |  | ||||||
|                         const std::vector<int64_t>& defaultValues, |  | ||||||
|                         std::optional<int64_t>      minValue, |  | ||||||
|                         std::optional<int64_t>      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<std::vector<int64_t>>(*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<std::string>(*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 ReadJsonFile(const std::string& path) | ||||||
| { | { | ||||||
|    boost::json::value json; |    boost::json::value json; | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <optional> | #include <optional> | ||||||
| 
 | 
 | ||||||
| #include <boost/json.hpp> | #include <boost/json/value.hpp> | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -13,28 +13,6 @@ namespace util | ||||||
| namespace json | 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<int64_t>     minValue, |  | ||||||
|                    std::optional<int64_t>     maxValue); |  | ||||||
| bool FromJsonInt64Array(const boost::json::object&  json, |  | ||||||
|                         const std::string&          key, |  | ||||||
|                         std::vector<int64_t>&       values, |  | ||||||
|                         const std::vector<int64_t>& defaultValues, |  | ||||||
|                         std::optional<int64_t>      minValue, |  | ||||||
|                         std::optional<int64_t>      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); | boost::json::value ReadJsonFile(const std::string& path); | ||||||
| void               WriteJsonFile(const std::string&        path, | void               WriteJsonFile(const std::string&        path, | ||||||
|                                  const boost::json::value& json, |                                  const boost::json::value& json, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat