39 m_path(
std::
move( aJsonPath ) ),
40 m_readOnly( aReadOnly ),
41 m_clearUnknownKeys( false )
89template<
typename ValueType>
93 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
94 bool aReadOnly =
false ) :
103 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault, ValueType aMin,
104 ValueType aMax,
bool aReadOnly =
false ) :
118 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
120 ValueType val = *optval;
130 else if( aResetIfMissing )
153 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
154 return *optval == *
m_ptr;
175 PARAM_PATH(
const std::string& aJsonPath, wxString* aPtr,
const wxString& aDefault,
176 bool aReadOnly =
false ) :
177 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
185 PARAM::Load( aSettings, aResetIfMissing );
187 *m_ptr = fromFileFormat( *m_ptr );
192 aSettings->
Set<wxString>( m_path, toFileFormat( *m_ptr ) );
197 if( std::optional<wxString> optval = aSettings.
Get<wxString>( m_path ) )
198 return fromFileFormat( *optval ) == *m_ptr;
206 wxString ret = aString;
207 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
213 wxString ret = aString;
215 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
224template<
typename EnumType>
228 PARAM_ENUM(
const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
229 EnumType aMin, EnumType aMax,
bool aReadOnly =
false ) :
243 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
245 if( *val >=
static_cast<int>(
m_min ) && *val <=
static_cast<int>(
m_max ) )
246 *
m_ptr =
static_cast<EnumType
>( *val );
247 else if( aResetIfMissing )
251 else if( aResetIfMissing )
259 aSettings->
Set<
int>(
m_path,
static_cast<int>( *m_ptr ) );
274 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
275 return *val ==
static_cast<int>( *m_ptr );
291template<
typename ValueType>
295 PARAM_LAMBDA(
const std::string& aJsonPath, std::function<ValueType()> aGetter,
296 std::function<
void( ValueType )> aSetter, ValueType aDefault,
297 bool aReadOnly =
false ) :
310 if( std::is_same<ValueType, nlohmann::json>::value )
312 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
319 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
349 if( std::is_same<ValueType, nlohmann::json>::value )
351 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
356 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
388template<
typename ValueType>
392 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
393 double aScale = 1.0,
bool aReadOnly =
false ) :
396 m_default( aDefault ),
399 m_use_minmax( false ),
401 m_invScale( 1.0 / aScale )
404 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
405 ValueType aMin, ValueType aMax,
double aScale = 1.0,
bool aReadOnly =
false ) :
408 m_default( aDefault ),
411 m_use_minmax( true ),
413 m_invScale( 1.0 / aScale )
421 double dval = m_default / m_invScale;
423 if( std::optional<double> optval = aSettings.
Get<
double>( m_path ) )
425 else if( !aResetIfMissing )
428 ValueType val = KiROUND<double, ValueType>( dval * m_invScale );
432 if( val > m_max || val < m_min )
441 aSettings->
Set<
double>( m_path, *m_ptr / m_invScale );
456 if( std::optional<double> optval = aSettings.
Get<
double>( m_path ) )
457 return *optval == ( *m_ptr / m_invScale );
472template<
typename Type>
476 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
477 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
483 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
484 std::vector<Type> aDefault,
bool aReadOnly =
false ) :
495 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
497 std::vector<Type> val;
501 for(
const auto& el : js->items() )
502 val.push_back( el.value().get<Type>() );
507 else if( aResetIfMissing )
513 nlohmann::json js = nlohmann::json::array();
515 for(
const auto& el : *
m_ptr )
518 aSettings->
Set<nlohmann::json>(
m_path, js );
528 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
532 std::vector<Type> val;
534 for(
const auto& el : js->items() )
538 val.emplace_back( el.value().get<Type>() );
546 return val == *
m_ptr;
576template<
typename Type>
580 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
581 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
584 m_default( aDefault )
587 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
588 std::set<Type> aDefault,
bool aReadOnly =
false ) :
591 m_default( aDefault )
599 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
605 for(
const auto& el : js->items() )
606 val.insert( el.value().get<Type>() );
611 else if( aResetIfMissing )
617 nlohmann::json js = nlohmann::json::array();
619 for(
const auto& el : *m_ptr )
622 aSettings->
Set<nlohmann::json>( m_path, js );
633 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
639 for(
const auto& el : js->items() )
640 val.insert( el.value().get<Type>() );
642 return val == *m_ptr;
668 std::initializer_list<wxString> aDefault,
bool aReadOnly =
false ) :
669 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
673 std::vector<wxString> aDefault,
bool aReadOnly =
false ) :
674 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
684 for(
size_t i = 0; i < m_ptr->size(); i++ )
685 ( *m_ptr )[i] = fromFileFormat( ( *m_ptr )[i] );
690 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
695 wxString ret = aString;
696 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
702 wxString ret = aString;
704 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
722template<
typename Value>
726 PARAM_MAP(
const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
727 std::initializer_list<std::pair<const std::string, Value>> aDefault,
728 bool aReadOnly =
false ) :
731 m_default( aDefault )
739 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
741 if( js->is_object() )
745 for(
const auto& el : js->items() )
746 ( *m_ptr )[el.key()] = el.value().get<Value>();
749 else if( aResetIfMissing )
755 nlohmann::json js( {} );
757 for(
const auto& el : *m_ptr )
758 js[el.first] = el.second;
760 aSettings->
Set<nlohmann::json>( m_path, js );
770 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
772 if( js->is_object() )
774 if( m_ptr->size() != js->size() )
777 std::map<std::string, Value> val;
779 for(
const auto& el : js->items() )
780 val[el.key()] = el.value().get<Value>();
782 return val == *m_ptr;
790 std::map<std::string, Value>*
m_ptr;
813 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
814 bool aReadOnly =
false,
bool aArrayBehavior =
false ) :
817 m_default( aDefault )
819 m_clearUnknownKeys = aArrayBehavior;
822 void Load(
const JSON_SETTINGS& aSettings,
bool aResetIfMissing =
true )
const override;
831 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
834 std::map<wxString, wxString>*
m_ptr;
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
reads a model file and creates a generic display structure
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...
std::optional< 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....
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
bool m_readOnly
Indicates param pointer should never be overwritten.
const std::string & GetJsonPath() const
virtual void SetDefault()=0
bool m_clearUnknownKeys
Keys should be cleared from source rather than merged.
bool ClearUnknownKeys() const
virtual void Store(JSON_SETTINGS *aSettings) const =0
Stores the value of this parameter to the given JSON_SETTINGS object.
virtual ~PARAM_BASE()=default
virtual bool MatchesFile(const JSON_SETTINGS &aSettings) const =0
Checks whether the parameter in memory matches the one in a given JSON file.
std::string m_path
Address of the param in the json files.
virtual void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const =0
Loads the value of this parameter from JSON to the underlying storage.
Stores an enum as an integer.
void SetDefault() override
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
EnumType GetDefault() const
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
PARAM_ENUM(const std::string &aJsonPath, EnumType *aPtr, EnumType aDefault, EnumType aMin, EnumType aMax, bool aReadOnly=false)
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(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
bool MatchesFile(const 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.
void Load(const 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(const JSON_SETTINGS &aSettings) const override
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::initializer_list< Type > aDefault, bool aReadOnly=false)
std::vector< Type > * m_ptr
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>.
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
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.
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
std::map< std::string, Value > m_default
std::map< std::string, Value > * m_ptr
Represents a list of strings holding directory paths.
wxString toFileFormat(const wxString &aString) const
wxString fromFileFormat(const wxString &aString) const
void Load(const 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::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
bool MatchesFile(const 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.
wxString toFileFormat(const wxString &aString) const
void Load(const 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 Load(const 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(const 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 void SetDefault() override
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
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(const 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.
void SetDefault() override
std::set< Type > m_default
A helper for <wxString, wxString> maps.
virtual void SetDefault() override
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, bool aArrayBehavior=false)
std::map< wxString, wxString > m_default
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
bool MatchesFile(const 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.