mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:10:06 +00:00 
			
		
		
		
	Settings variable abstract base, additional validation, and reading/writing JSON
This commit is contained in:
		
							parent
							
								
									1ad67de71b
								
							
						
					
					
						commit
						46c4dd3780
					
				
					 7 changed files with 408 additions and 17 deletions
				
			
		|  | @ -11,6 +11,7 @@ namespace settings | |||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::settings::settings_container"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| template<class Container> | ||||
| class SettingsContainer<Container>::Impl | ||||
|  | @ -61,16 +62,29 @@ bool SettingsContainer<Container>::SetValueOrDefault(const Container& c) | |||
|          } | ||||
|          else if (p->elementMinimum_.has_value() && value < p->elementMinimum_) | ||||
|          { | ||||
|             logger_->warn("{0} less than minimum ({1} < {2}), setting to: {2}", | ||||
|                           this->name(), | ||||
|                           value, | ||||
|                           *p->elementMinimum_); | ||||
|             validated = false; | ||||
|             return *p->elementMinimum_; | ||||
|          } | ||||
|          else if (p->elementMaximum_.has_value() && value > p->elementMaximum_) | ||||
|          { | ||||
|             logger_->warn( | ||||
|                "{0} greater than maximum ({1} > {2}), setting to: {2}", | ||||
|                this->name(), | ||||
|                value, | ||||
|                *p->elementMaximum_); | ||||
|             validated = false; | ||||
|             return *p->elementMaximum_; | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             logger_->warn("{} validation failed ({}), setting to default: {}", | ||||
|                           this->name(), | ||||
|                           value, | ||||
|                           p->elementDefault_); | ||||
|             validated = false; | ||||
|             return p->elementDefault_; | ||||
|          } | ||||
|  | @ -143,6 +157,21 @@ bool SettingsContainer<Container>::ValidateElement(const T& value) const | |||
|       (p->elementValidator_ == nullptr || p->elementValidator_(value))); | ||||
| } | ||||
| 
 | ||||
| template<class Container> | ||||
| bool SettingsContainer<Container>::Equals(const SettingsVariableBase& o) const | ||||
| { | ||||
|    // This is only ever called with SettingsContainer<Container>, so static_cast
 | ||||
|    // is safe
 | ||||
|    const SettingsContainer<Container>& v = | ||||
|       static_cast<const SettingsContainer<Container>&>(o); | ||||
| 
 | ||||
|    // Don't compare validator
 | ||||
|    return SettingsVariable<Container>::Equals(o) && | ||||
|           p->elementDefault_ == v.p->elementDefault_ && | ||||
|           p->elementMinimum_ == v.p->elementMinimum_ && | ||||
|           p->elementMaximum_ == v.p->elementMaximum_; | ||||
| } | ||||
| 
 | ||||
| } // namespace settings
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat