mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:20: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
76
scwx-qt/source/scwx/qt/settings/settings_variable_base.hpp
Normal file
76
scwx-qt/source/scwx/qt/settings/settings_variable_base.hpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <boost/json/object.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Settings Variable base class
|
||||
*/
|
||||
class SettingsVariableBase
|
||||
{
|
||||
protected:
|
||||
explicit SettingsVariableBase(const std::string& name);
|
||||
~SettingsVariableBase();
|
||||
|
||||
public:
|
||||
SettingsVariableBase(const SettingsVariableBase&) = delete;
|
||||
SettingsVariableBase& operator=(const SettingsVariableBase&) = delete;
|
||||
|
||||
SettingsVariableBase(SettingsVariableBase&&) noexcept;
|
||||
SettingsVariableBase& operator=(SettingsVariableBase&&) noexcept;
|
||||
|
||||
std::string name() const;
|
||||
|
||||
/**
|
||||
* Sets the current value of the settings variable to default.
|
||||
*/
|
||||
virtual void SetValueToDefault() = 0;
|
||||
|
||||
/**
|
||||
* Sets the current value of the settings variable to the staged value.
|
||||
*/
|
||||
virtual void Commit() = 0;
|
||||
|
||||
/**
|
||||
* Reads the value from the JSON object. If the read value is out of range,
|
||||
* the value is set to the minimum or maximum. If the read value fails
|
||||
* validation, the value is set to default.
|
||||
*
|
||||
* @param json JSON object to read
|
||||
*
|
||||
* @return true if the read value is valid, false if the value was modified.
|
||||
*/
|
||||
virtual bool ReadValue(const boost::json::object& json) = 0;
|
||||
|
||||
/**
|
||||
* Writes the current value to the JSON object.
|
||||
*
|
||||
* @param json JSON object to write
|
||||
*/
|
||||
virtual void WriteValue(boost::json::object& json) const = 0;
|
||||
|
||||
protected:
|
||||
friend bool operator==(const SettingsVariableBase& lhs,
|
||||
const SettingsVariableBase& rhs);
|
||||
virtual bool Equals(const SettingsVariableBase& o) const;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
};
|
||||
|
||||
bool operator==(const SettingsVariableBase& lhs,
|
||||
const SettingsVariableBase& rhs);
|
||||
|
||||
} // namespace settings
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue