23#include <nlohmann/json.hpp>
30template <
typename ValueType>
36 if( std::is_same<ValueType, nlohmann::json>::value )
38 if( std::optional<nlohmann::json> optval = aSettings->
GetJson( m_path ) )
41 m_setter( m_default );
45 if( std::optional<ValueType> optval = aSettings->
Get<ValueType>( m_path ) )
48 m_setter( m_default );
53template <
typename ValueType>
56 if( std::is_same<ValueType, nlohmann::json>::value )
58 if( std::optional<nlohmann::json> optval = aSettings->
GetJson( m_path ) )
59 return *optval == m_getter();
63 if( std::optional<ValueType> optval = aSettings->
Get<ValueType>( m_path ) )
64 return *optval == m_getter();
78template <
typename ValueType>
84 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
86 std::vector<ValueType> val;
90 for(
const auto& el : js->items() )
91 val.push_back( el.value().get<ValueType>() );
96 else if( aResetIfMissing )
101template <
typename ValueType>
104 nlohmann::json js = nlohmann::json::array();
106 for(
const auto& el : *m_ptr )
109 aSettings->
Set<nlohmann::json>( m_path, js );
113template <
typename ValueType>
116 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
120 std::vector<ValueType> val;
122 for(
const auto& el : js->items() )
123 val.emplace_back( el.value().get<ValueType>() );
125 return val == *m_ptr;
142template <
typename ValueType>
148 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
150 std::set<ValueType> val;
154 for(
const auto& el : js->items() )
155 val.insert( el.value().get<ValueType>() );
160 else if( aResetIfMissing )
165template <
typename ValueType>
168 nlohmann::json js = nlohmann::json::array();
170 for(
const auto& el : *m_ptr )
173 aSettings->
Set<nlohmann::json>( m_path, js );
177template <
typename ValueType>
180 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
184 std::set<ValueType> val;
186 for(
const auto& el : js->items() )
187 val.insert( el.value().get<ValueType>() );
189 return val == *m_ptr;
202 nlohmann::json js = nlohmann::json::array();
204 for(
const auto& el : *
m_ptr )
207 aSettings->
Set<nlohmann::json>(
m_path, js );
213 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
217 std::vector<wxString> val;
219 for(
const auto& el : js->items() )
222 return val == *
m_ptr;
230template <
typename Value>
236 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
238 if( js->is_object() )
242 for(
const auto& el : js->items() )
243 ( *m_ptr )[el.key()] = el.value().get<Value>();
246 else if( aResetIfMissing )
251template <
typename Value>
254 nlohmann::json js( {} );
256 for(
const auto& el : *m_ptr )
257 js[el.first] = el.second;
259 aSettings->
Set<nlohmann::json>( m_path, js );
263template <
typename Value>
266 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
268 if( js->is_object() )
270 if( m_ptr->size() != js->size() )
273 std::map<std::string, Value> val;
275 for(
const auto& el : js->items() )
276 val[el.key()] = el.value().get<Value>();
278 return val == *m_ptr;
296 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
298 if( js->is_object() )
302 for(
const auto& el : js->items() )
304 ( *m_ptr )[wxString( el.key().c_str(), wxConvUTF8 )] = el.value().get<wxString>();
308 else if( aResetIfMissing )
315 nlohmann::json js( {} );
317 for(
const auto& el : *
m_ptr )
319 std::string key( el.first.ToUTF8() );
323 aSettings->
Set<nlohmann::json>(
m_path, js );
329 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
331 if( js->is_object() )
333 if(
m_ptr->size() != js->size() )
336 std::map<wxString, wxString> val;
338 for(
const auto& el : js->items() )
340 wxString key( el.key().c_str(), wxConvUTF8 );
341 val[key] = el.value().get<wxString>();
344 return val == *
m_ptr;
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
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....
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...
bool m_readOnly
! True if the parameter pointer should never be overwritten
std::string m_path
the string used to store the param in json files
Like a normal param, but with custom getter and setter functions.
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.
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.
std::vector< 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.
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 Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
wxString toFileFormat(const wxString &aString) const
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.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
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 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
std::map< wxString, wxString > m_default