92template<
typename ValueType>
96 PARAM(
const std::string& aJsonPath, ValueType* aPtr,
const ValueType& aDefault,
97 bool aReadOnly =
false ) :
106 PARAM(
const std::string& aJsonPath, ValueType* aPtr,
const ValueType& aDefault,
107 const ValueType& aMin,
const ValueType& aMax,
bool aReadOnly =
false ) :
121 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
123 ValueType val = *optval;
133 else if( aResetIfMissing )
156 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
157 return *optval == *
m_ptr;
178 PARAM_PATH(
const std::string& aJsonPath, wxString* aPtr,
const wxString& aDefault,
179 bool aReadOnly =
false ) :
180 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
200 if( std::optional<wxString> optval = aSettings.
Get<wxString>(
m_path ) )
209 wxString ret = aString;
210 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
216 wxString ret = aString;
218 if( !ret.Contains( wxT(
"://" ) ) )
219 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
228template<
typename EnumType>
232 PARAM_ENUM(
const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
233 EnumType aMin, EnumType aMax,
bool aReadOnly =
false ) :
247 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
249 if( *val >=
static_cast<int>(
m_min ) && *val <=
static_cast<int>(
m_max ) )
250 *
m_ptr =
static_cast<EnumType
>( *val );
251 else if( aResetIfMissing )
255 else if( aResetIfMissing )
263 aSettings->
Set<
int>(
m_path,
static_cast<int>( *m_ptr ) );
278 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
279 return *val ==
static_cast<int>( *m_ptr );
295template<
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 ) :
314 if( std::is_same<ValueType, nlohmann::json>::value )
316 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
323 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
353 if( std::is_same<ValueType, nlohmann::json>::value )
355 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
360 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
392template<
typename ValueType>
396 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
397 double aScale = 1.0,
bool aReadOnly =
false ) :
408 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
409 ValueType aMin, ValueType aMax,
double aScale = 1.0,
bool aReadOnly =
false ) :
427 if( std::optional<double> optval = aSettings.
Get<
double>(
m_path ) )
429 else if( !aResetIfMissing )
460 if( std::optional<double> optval = aSettings.
Get<
double>(
m_path ) )
476template<
typename Type>
480 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
481 std::initializer_list<Type> aDefault,
bool aResetIfEmpty =
false ) :
488 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
489 std::vector<Type> aDefault,
bool aResetIfEmpty =
false ) :
501 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
503 std::vector<Type> val;
507 for(
const auto& el : js->items() )
508 val.push_back( el.value().get<Type>() );
516 else if( aResetIfMissing )
524 nlohmann::json js = nlohmann::json::array();
526 for(
const auto& el : *
m_ptr )
529 aSettings->
Set<nlohmann::json>(
m_path, js );
539 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
543 std::vector<Type> val;
545 for(
const auto& el : js->items() )
549 val.emplace_back( el.value().get<Type>() );
557 return val == *
m_ptr;
588template<
typename Type>
592 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
593 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
599 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
600 std::set<Type> aDefault,
bool aReadOnly =
false ) :
611 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
617 for(
const auto& el : js->items() )
618 val.insert( el.value().get<Type>() );
623 else if( aResetIfMissing )
629 nlohmann::json js = nlohmann::json::array();
631 for(
const auto& el : *
m_ptr )
634 aSettings->
Set<nlohmann::json>(
m_path, js );
645 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
651 for(
const auto& el : js->items() )
652 val.insert( el.value().get<Type>() );
654 return val == *
m_ptr;
680 std::initializer_list<wxString> aDefault ) :
685 std::vector<wxString> aDefault ) :
696 for(
size_t i = 0; i <
m_ptr->size(); i++ )
702 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
707 wxString ret = aString;
708 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
714 wxString ret = aString;
716 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
734template<
typename Value>
738 PARAM_MAP(
const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
739 std::initializer_list<std::pair<const std::string, Value>> aDefault,
740 bool aReadOnly =
false ) :
753 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
755 if( js->is_object() )
759 for(
const auto& el : js->items() )
760 ( *m_ptr )[el.key()] = el.value().get<Value>();
763 else if( aResetIfMissing )
769 nlohmann::json js( {} );
771 for(
const auto& el : *
m_ptr )
772 js[el.first] = el.second;
774 aSettings->
Set<nlohmann::json>(
m_path, js );
784 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
786 if( js->is_object() )
788 if(
m_ptr->size() != js->size() )
791 std::map<std::string, Value> val;
793 for(
const auto& el : js->items() )
794 val[el.key()] = el.value().get<Value>();
796 return val == *
m_ptr;
804 std::map<std::string, Value>*
m_ptr;
827 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
828 bool aReadOnly =
false,
bool aArrayBehavior =
false ) :
836 void Load(
const JSON_SETTINGS& aSettings,
bool aResetIfMissing =
true )
const override;
845 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
848 std::map<wxString, wxString>*
m_ptr;
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
Read a model file and creates a generic display structure.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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.
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::vector< Type > aDefault, bool aResetIfEmpty=false)
std::vector< Type > * m_ptr
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aResetIfEmpty=false)
std::vector< Type > m_default
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
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault)
wxString toFileFormat(const wxString &aString) const
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault)
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(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.
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
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.
PARAM(const std::string &aJsonPath, ValueType *aPtr, const ValueType &aDefault, 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.
void SetDefault() override
PARAM(const std::string &aJsonPath, ValueType *aPtr, const ValueType &aDefault, const ValueType &aMin, const ValueType &aMax, bool aReadOnly=false)
ValueType GetDefault() const
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.