47 virtual void Load(
JSON_SETTINGS* aSettings,
bool aResetIfMissing =
true )
const = 0;
87 template<
typename ValueType>
91 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
92 bool aReadOnly =
false ) :
101 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault, ValueType aMin,
102 ValueType aMax,
bool aReadOnly =
false ) :
118 ValueType val = *optval;
128 else if( aResetIfMissing )
155 return *optval == *
m_ptr;
176 PARAM_PATH(
const std::string& aJsonPath, wxString* aPtr, wxString aDefault,
177 bool aReadOnly =
false ) :
178 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
207 wxString ret = aString;
208 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
214 wxString ret = aString;
216 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
225 template<
typename EnumType>
229 PARAM_ENUM(
const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
230 EnumType aMin, EnumType aMax,
bool aReadOnly =
false ) :
246 if( *val >= static_cast<int>(
m_min ) && *val <= static_cast<int>(
m_max ) )
247 *
m_ptr = static_cast<EnumType>( *val );
248 else if( aResetIfMissing )
252 else if( aResetIfMissing )
279 return *val == static_cast<int>( *
m_ptr );
295 template<
typename ValueType>
299 PARAM_LAMBDA(
const std::string& aJsonPath, std::function<ValueType()> aGetter,
300 std::function<
void( ValueType )> aSetter, ValueType aDefault,
301 bool aReadOnly =
false ) :
313 if( std::is_same<ValueType, nlohmann::json>::value )
357 if( std::is_same<ValueType, nlohmann::json>::value )
387 template<
typename ValueType>
391 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
392 double aScale = 1.0,
bool aReadOnly =
false ) :
402 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
403 ValueType aMin, ValueType aMax,
double aScale = 1.0,
bool aReadOnly =
false ) :
422 else if( !aResetIfMissing )
425 ValueType val = KiROUND<ValueType>( dval /
m_scale );
473 template<
typename Type>
477 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
478 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
484 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
485 std::vector<Type> aDefault,
bool aReadOnly =
false ) :
498 std::vector<Type> val;
502 for(
const auto& el : js->items() )
503 val.push_back( el.value().get<Type>() );
508 else if( aResetIfMissing )
516 for(
const auto& el : *
m_ptr )
538 std::vector<Type> val;
540 for(
const auto& el : js->items() )
541 val.emplace_back( el.value().get<Type>() );
543 return val == *
m_ptr;
564 std::initializer_list<wxString> aDefault,
bool aReadOnly =
false ) :
565 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
569 std::vector<wxString> aDefault,
bool aReadOnly =
false ) :
570 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
580 for(
size_t i = 0; i <
m_ptr->size(); i++ )
588 for(
const auto& el : *
m_ptr )
600 std::vector<wxString> val;
602 for(
const auto& el : js->items() )
605 return val == *
m_ptr;
615 wxString ret = aString;
616 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
622 wxString ret = aString;
624 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
642 template<
typename Value>
646 PARAM_MAP(
const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
647 std::initializer_list<std::pair<const std::string, Value>> aDefault,
648 bool aReadOnly =
false ) :
661 if( js->is_object() )
665 for(
const auto& el : js->items() )
666 ( *
m_ptr )[ el.key() ] = el.value().get<Value>();
669 else if( aResetIfMissing )
677 for(
const auto& el : *
m_ptr )
678 js[ el.first ] = el.second;
697 if( js->is_object() )
699 if(
m_ptr->size() != js->size() )
702 std::map<std::string, Value> val;
704 for(
const auto& el : js->items() )
705 val[ el.key() ] = el.value().get<Value>();
707 return val == *
m_ptr;
715 std::map<std::string, Value>*
m_ptr;
728 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
729 bool aReadOnly =
false ) :
742 if( js->is_object() )
746 for(
const auto& el : js->items() )
748 ( *m_ptr )[wxString( el.key().c_str(), wxConvUTF8 )] =
749 el.value().get<wxString>();
753 else if( aResetIfMissing )
761 for(
const auto& el : *
m_ptr )
763 std::string key( el.first.ToUTF8() );
764 js[ key ] = el.second;
784 if( js->is_object() )
786 if(
m_ptr->size() != js->size() )
789 std::map<wxString, wxString> val;
791 for(
const auto& el : js->items() )
793 wxString key( el.key().c_str(), wxConvUTF8 );
794 val[key] = el.value().get<wxString>();
797 return val == *
m_ptr;
805 std::map<wxString, wxString>*
m_ptr;
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault, bool aReadOnly=false)
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
virtual void SetDefault() override
virtual void SetDefault() override
Like a normal param, but with custom getter and setter functions.
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
std::map< std::string, Value > m_default
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.
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, double aScale=1.0, bool aReadOnly=false)
virtual bool IsDefault() const =0
Checks whether or not this param has been changed from its default value.
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
EnumType GetDefault() const
std::string m_path
the string used to store the param in json files
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.
void SetDefault() override
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
std::map< wxString, wxString > * m_ptr
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
OPT< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
Stores an enum as an integer.
std::map< wxString, wxString > m_default
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
std::function< ValueType()> m_getter
PARAM_LAMBDA(const std::string &aJsonPath, std::function< ValueType()> aGetter, std::function< void(ValueType)> aSetter, ValueType aDefault, bool aReadOnly=false)
virtual void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const =0
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.
std::function< void(ValueType)> m_setter
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > 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.
OPT< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
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.
Stores a path as a string with directory separators normalized to unix-style.
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, bool aReadOnly=false)
void SetDefault() override
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
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.
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 SetDefault() override
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Represents a parameter that has a scaling factor between the value in the file and the value used int...
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 Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
const std::string & GetJsonPath()
virtual ~PARAM_BASE()=default
virtual void SetDefault() override
wxString toFileFormat(const wxString &aString) const
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
virtual void Store(JSON_SETTINGS *aSettings) const =0
Stores the value of this parameter to the given JSON_SETTINGS object.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
std::vector< Type > * m_ptr
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)
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
virtual void SetDefault()=0
std::map< std::string, Value > * m_ptr
A helper for <wxString, wxString> maps.
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.
bool m_readOnly
! True if the parameter pointer should never be overwritten
ValueType GetDefault() const
virtual bool MatchesFile(JSON_SETTINGS *aSettings) const =0
Checks whether the parameter in memory matches the one in a given JSON file.
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::vector< 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.
wxString fromFileFormat(const wxString &aString) const
PARAM_WXSTRING_MAP(const std::string &aJsonPath, std::map< wxString, wxString > *aPtr, std::initializer_list< std::pair< const wxString, wxString >> aDefault, bool aReadOnly=false)
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
bool IsDefault() const override
Checks whether or not this param has been changed from its default value.
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
ValueType GetDefault() const
Represents a list of strings holding directory paths.
PARAM(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, bool aReadOnly=false)
wxString toFileFormat(const wxString &aString) const
void SetDefault() override
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...
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
ValueType GetDefault() const
PARAM_PATH(const std::string &aJsonPath, wxString *aPtr, wxString aDefault, bool aReadOnly=false)