82template<
typename ValueType>
86 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
87 bool aReadOnly =
false ) :
96 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault, ValueType aMin,
97 ValueType aMax,
bool aReadOnly =
false ) :
111 if( std::optional<ValueType> optval = aSettings->
Get<ValueType>(
m_path ) )
113 ValueType val = *optval;
123 else if( aResetIfMissing )
144 if( std::optional<ValueType> optval = aSettings->
Get<ValueType>(
m_path ) )
145 return *optval == *
m_ptr;
166 PARAM_PATH(
const std::string& aJsonPath, wxString* aPtr,
const wxString& aDefault,
167 bool aReadOnly =
false ) :
168 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
176 PARAM::Load( aSettings, aResetIfMissing );
188 if( std::optional<wxString> optval = aSettings->
Get<wxString>(
m_path ) )
197 wxString ret = aString;
198 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
204 wxString ret = aString;
206 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
215template<
typename EnumType>
219 PARAM_ENUM(
const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
220 EnumType aMin, EnumType aMax,
bool aReadOnly =
false ) :
234 if( std::optional<int> val = aSettings->
Get<
int>(
m_path ) )
236 if( *val >=
static_cast<int>(
m_min ) && *val <=
static_cast<int>(
m_max ) )
237 *
m_ptr =
static_cast<EnumType
>( *val );
238 else if( aResetIfMissing )
242 else if( aResetIfMissing )
248 aSettings->
Set<
int>(
m_path,
static_cast<int>( *m_ptr ) );
263 if( std::optional<int> val = aSettings->
Get<
int>(
m_path ) )
264 return *val ==
static_cast<int>( *m_ptr );
280template<
typename ValueType>
284 PARAM_LAMBDA(
const std::string& aJsonPath, std::function<ValueType()> aGetter,
285 std::function<
void( ValueType )> aSetter, ValueType aDefault,
286 bool aReadOnly =
false ) :
293 void Load(
JSON_SETTINGS* aSettings,
bool aResetIfMissing =
true )
const override;
333template<
typename ValueType>
337 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
338 double aScale = 1.0,
bool aReadOnly =
false ) :
348 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
349 ValueType aMin, ValueType aMax,
double aScale = 1.0,
bool aReadOnly =
false ) :
366 if( std::optional<double> optval = aSettings->
Get<
double>(
m_path ) )
368 else if( !aResetIfMissing )
371 ValueType val = KiROUND<ValueType>( dval /
m_scale );
399 if( std::optional<double> optval = aSettings->
Get<
double>(
m_path ) )
414template<
typename Type>
418 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
419 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
425 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
426 std::vector<Type> aDefault,
bool aReadOnly =
false ) :
432 void Load(
JSON_SETTINGS* aSettings,
bool aResetIfMissing =
true )
const override;
449template<
typename Type>
453 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
454 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
460 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
461 std::set<Type> aDefault,
bool aReadOnly =
false ) :
467 void Load(
JSON_SETTINGS* aSettings,
bool aResetIfMissing =
true )
const override;
492 std::initializer_list<wxString> aDefault,
bool aReadOnly =
false ) :
493 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
497 std::vector<wxString> aDefault,
bool aReadOnly =
false ) :
498 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
508 for(
size_t i = 0; i <
m_ptr->size(); i++ )
519 wxString ret = aString;
520 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
526 wxString ret = aString;
528 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
546template<
typename Value>
550 PARAM_MAP(
const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
551 std::initializer_list<std::pair<const std::string, Value>> aDefault,
552 bool aReadOnly =
false ) :
558 void Load(
JSON_SETTINGS* aSettings,
bool aResetIfMissing =
true )
const override;
570 std::map<std::string, Value>*
m_ptr;
583 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
584 bool aReadOnly =
false ) :
590 void Load(
JSON_SETTINGS* aSettings,
bool aResetIfMissing =
true )
const override;
602 std::map<wxString, wxString>*
m_ptr;
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
bool m_readOnly
! True if the parameter pointer should never be overwritten
const std::string & GetJsonPath() const
virtual void SetDefault()=0
virtual void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const =0
Loads the value of this parameter from JSON to the underlying storage.
virtual void Store(JSON_SETTINGS *aSettings) const =0
Stores the value of this parameter to the given JSON_SETTINGS object.
virtual ~PARAM_BASE()=default
std::string m_path
the string used to store the param in json files
virtual bool MatchesFile(JSON_SETTINGS *aSettings) const =0
Checks whether the parameter in memory matches the one in a given JSON file.
Stores an enum as an integer.
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
void SetDefault() override
EnumType GetDefault() const
PARAM_ENUM(const std::string &aJsonPath, EnumType *aPtr, EnumType aDefault, EnumType aMin, EnumType aMax, bool aReadOnly=false)
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Like a normal param, but with custom getter and setter functions.
std::function< void(ValueType)> m_setter
std::function< ValueType()> m_getter
void SetDefault() override
ValueType GetDefault() const
PARAM_LAMBDA(const std::string &aJsonPath, std::function< ValueType()> aGetter, std::function< void(ValueType)> aSetter, ValueType aDefault, bool aReadOnly=false)
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
std::vector< Type > * m_ptr
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
std::vector< Type > m_default
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::vector< Type > aDefault, bool aReadOnly=false)
void SetDefault() override
Represents a map of <std::string, Value>.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
virtual void SetDefault() override
PARAM_MAP(const std::string &aJsonPath, std::map< std::string, Value > *aPtr, std::initializer_list< std::pair< const std::string, Value > > aDefault, bool aReadOnly=false)
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
std::map< std::string, Value > m_default
std::map< std::string, Value > * m_ptr
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Represents a list of strings holding directory paths.
wxString toFileFormat(const wxString &aString) const
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
wxString fromFileFormat(const wxString &aString) const
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault, bool aReadOnly=false)
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault, bool aReadOnly=false)
Stores a path as a string with directory separators normalized to unix-style.
PARAM_PATH(const std::string &aJsonPath, wxString *aPtr, const wxString &aDefault, bool aReadOnly=false)
wxString fromFileFormat(const wxString &aString) const
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
wxString toFileFormat(const wxString &aString) const
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
Represents a parameter that has a scaling factor between the value in the file and the value used int...
ValueType GetDefault() const
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, double aScale=1.0, bool aReadOnly=false)
virtual void SetDefault() override
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::set< Type > aDefault, bool aReadOnly=false)
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
void SetDefault() override
std::set< Type > m_default
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
A helper for <wxString, wxString> maps.
virtual void SetDefault() override
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
std::map< wxString, wxString > * m_ptr
PARAM_WXSTRING_MAP(const std::string &aJsonPath, std::map< wxString, wxString > *aPtr, std::initializer_list< std::pair< const wxString, wxString > > aDefault, bool aReadOnly=false)
std::map< wxString, wxString > m_default
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void SetDefault() override
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, bool aReadOnly=false)
ValueType GetDefault() const
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, bool aReadOnly=false)
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.