39 m_path(
std::
move( aJsonPath ) ),
40 m_readOnly( aReadOnly ),
41 m_clearUnknownKeys( false )
91template<
typename ValueType>
95 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
96 bool aReadOnly =
false ) :
105 PARAM(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault, ValueType aMin,
106 ValueType aMax,
bool aReadOnly =
false ) :
120 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
122 ValueType val = *optval;
132 else if( aResetIfMissing )
155 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
156 return *optval == *
m_ptr;
177 PARAM_PATH(
const std::string& aJsonPath, wxString* aPtr,
const wxString& aDefault,
178 bool aReadOnly =
false ) :
179 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
187 PARAM::Load( aSettings, aResetIfMissing );
189 *m_ptr = fromFileFormat( *m_ptr );
194 aSettings->
Set<wxString>( m_path, toFileFormat( *m_ptr ) );
199 if( std::optional<wxString> optval = aSettings.
Get<wxString>( m_path ) )
200 return fromFileFormat( *optval ) == *m_ptr;
208 wxString ret = aString;
209 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
215 wxString ret = aString;
217 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
226template<
typename EnumType>
230 PARAM_ENUM(
const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
231 EnumType aMin, EnumType aMax,
bool aReadOnly =
false ) :
245 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
247 if( *val >=
static_cast<int>(
m_min ) && *val <=
static_cast<int>(
m_max ) )
248 *
m_ptr =
static_cast<EnumType
>( *val );
249 else if( aResetIfMissing )
253 else if( aResetIfMissing )
261 aSettings->
Set<
int>(
m_path,
static_cast<int>( *m_ptr ) );
276 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
277 return *val ==
static_cast<int>( *m_ptr );
293template<
typename ValueType>
297 PARAM_LAMBDA(
const std::string& aJsonPath, std::function<ValueType()> aGetter,
298 std::function<
void( ValueType )> aSetter, ValueType aDefault,
299 bool aReadOnly =
false ) :
312 if( std::is_same<ValueType, nlohmann::json>::value )
314 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
321 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
351 if( std::is_same<ValueType, nlohmann::json>::value )
353 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
358 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
390template<
typename ValueType>
394 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
395 double aScale = 1.0,
bool aReadOnly =
false ) :
398 m_default( aDefault ),
401 m_use_minmax( false ),
403 m_invScale( 1.0 / aScale )
406 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
407 ValueType aMin, ValueType aMax,
double aScale = 1.0,
bool aReadOnly =
false ) :
410 m_default( aDefault ),
413 m_use_minmax( true ),
415 m_invScale( 1.0 / aScale )
423 double dval = m_default / m_invScale;
425 if( std::optional<double> optval = aSettings.
Get<
double>( m_path ) )
427 else if( !aResetIfMissing )
430 ValueType val = KiROUND<double, ValueType>( dval * m_invScale );
434 if( val > m_max || val < m_min )
443 aSettings->
Set<
double>( m_path, *m_ptr / m_invScale );
458 if( std::optional<double> optval = aSettings.
Get<
double>( m_path ) )
459 return *optval == ( *m_ptr / m_invScale );
474template<
typename Type>
478 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
479 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
485 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
486 std::vector<Type> aDefault,
bool aReadOnly =
false ) :
497 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
499 std::vector<Type> val;
503 for(
const auto& el : js->items() )
504 val.push_back( el.value().get<Type>() );
509 else if( aResetIfMissing )
515 nlohmann::json js = nlohmann::json::array();
517 for(
const auto& el : *
m_ptr )
520 aSettings->
Set<nlohmann::json>(
m_path, js );
530 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
534 std::vector<Type> val;
536 for(
const auto& el : js->items() )
540 val.emplace_back( el.value().get<Type>() );
548 return val == *
m_ptr;
578template<
typename Type>
582 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
583 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
586 m_default( aDefault )
589 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
590 std::set<Type> aDefault,
bool aReadOnly =
false ) :
593 m_default( aDefault )
601 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
607 for(
const auto& el : js->items() )
608 val.insert( el.value().get<Type>() );
613 else if( aResetIfMissing )
619 nlohmann::json js = nlohmann::json::array();
621 for(
const auto& el : *m_ptr )
624 aSettings->
Set<nlohmann::json>( m_path, js );
635 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
641 for(
const auto& el : js->items() )
642 val.insert( el.value().get<Type>() );
644 return val == *m_ptr;
670 std::initializer_list<wxString> aDefault,
bool aReadOnly =
false ) :
671 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
675 std::vector<wxString> aDefault,
bool aReadOnly =
false ) :
676 PARAM_LIST( aJsonPath, aPtr, aDefault, aReadOnly )
686 for(
size_t i = 0; i < m_ptr->size(); i++ )
687 ( *m_ptr )[i] = fromFileFormat( ( *m_ptr )[i] );
692 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
697 wxString ret = aString;
698 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
704 wxString ret = aString;
706 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
724template<
typename Value>
728 PARAM_MAP(
const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
729 std::initializer_list<std::pair<const std::string, Value>> aDefault,
730 bool aReadOnly =
false ) :
733 m_default( aDefault )
741 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
743 if( js->is_object() )
747 for(
const auto& el : js->items() )
748 ( *m_ptr )[el.key()] = el.value().get<Value>();
751 else if( aResetIfMissing )
757 nlohmann::json js( {} );
759 for(
const auto& el : *m_ptr )
760 js[el.first] = el.second;
762 aSettings->
Set<nlohmann::json>( m_path, js );
772 if( std::optional<nlohmann::json> js = aSettings.
GetJson( m_path ) )
774 if( js->is_object() )
776 if( m_ptr->size() != js->size() )
779 std::map<std::string, Value> val;
781 for(
const auto& el : js->items() )
782 val[el.key()] = el.value().get<Value>();
784 return val == *m_ptr;
792 std::map<std::string, Value>*
m_ptr;
815 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
816 bool aReadOnly =
false,
bool aArrayBehavior =
false ) :
819 m_default( aDefault )
821 m_clearUnknownKeys = aArrayBehavior;
824 void Load(
const JSON_SETTINGS& aSettings,
bool aResetIfMissing =
true )
const override;
833 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
836 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
void SetClearUnknownKeys(bool aSet=true)
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.