23#include <nlohmann/json.hpp>
31template <
typename ValueType>
37 if( std::is_same<ValueType, nlohmann::json>::value )
39 if( std::optional<nlohmann::json> optval = aSettings->
GetJson( m_path ) )
42 m_setter( m_default );
46 if( std::optional<ValueType> optval = aSettings->
Get<ValueType>( m_path ) )
49 m_setter( m_default );
54template <
typename ValueType>
57 if( std::is_same<ValueType, nlohmann::json>::value )
59 if( std::optional<nlohmann::json> optval = aSettings->
GetJson( m_path ) )
60 return *optval == m_getter();
64 if( std::optional<ValueType> optval = aSettings->
Get<ValueType>( m_path ) )
65 return *optval == m_getter();
79template <
typename ValueType>
85 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
87 std::vector<ValueType> val;
91 for(
const auto& el : js->items() )
92 val.push_back( el.value().get<ValueType>() );
97 else if( aResetIfMissing )
102template <
typename ValueType>
105 nlohmann::json js = nlohmann::json::array();
107 for(
const auto& el : *m_ptr )
110 aSettings->
Set<nlohmann::json>( m_path, js );
114template <
typename ValueType>
117 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
121 std::vector<ValueType> val;
123 for(
const auto& el : js->items() )
127 val.emplace_back( el.value().get<ValueType>() );
135 return val == *m_ptr;
153template <
typename ValueType>
159 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
161 std::set<ValueType> val;
165 for(
const auto& el : js->items() )
166 val.insert( el.value().get<ValueType>() );
171 else if( aResetIfMissing )
176template <
typename ValueType>
179 nlohmann::json js = nlohmann::json::array();
181 for(
const auto& el : *m_ptr )
184 aSettings->
Set<nlohmann::json>( m_path, js );
188template <
typename ValueType>
191 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
195 std::set<ValueType> val;
197 for(
const auto& el : js->items() )
198 val.insert( el.value().get<ValueType>() );
200 return val == *m_ptr;
213 nlohmann::json js = nlohmann::json::array();
215 for(
const auto& el : *
m_ptr )
218 aSettings->
Set<nlohmann::json>(
m_path, js );
224 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
228 std::vector<wxString> val;
230 for(
const auto& el : js->items() )
233 return val == *
m_ptr;
241template <
typename Value>
247 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
249 if( js->is_object() )
253 for(
const auto& el : js->items() )
254 ( *m_ptr )[el.key()] = el.value().get<Value>();
257 else if( aResetIfMissing )
262template <
typename Value>
265 nlohmann::json js( {} );
267 for(
const auto& el : *m_ptr )
268 js[el.first] = el.second;
270 aSettings->
Set<nlohmann::json>( m_path, js );
274template <
typename Value>
277 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
279 if( js->is_object() )
281 if( m_ptr->size() != js->size() )
284 std::map<std::string, Value> val;
286 for(
const auto& el : js->items() )
287 val[el.key()] = el.value().get<Value>();
289 return val == *m_ptr;
307 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
309 if( js->is_object() )
313 for(
const auto& el : js->items() )
315 ( *m_ptr )[wxString( el.key().c_str(), wxConvUTF8 )] = el.value().get<wxString>();
319 else if( aResetIfMissing )
326 nlohmann::json js( {} );
328 for(
const auto& el : *
m_ptr )
330 std::string key( el.first.ToUTF8() );
334 aSettings->
Set<nlohmann::json>(
m_path, js );
340 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
342 if( js->is_object() )
344 if(
m_ptr->size() != js->size() )
347 std::map<wxString, wxString> val;
349 for(
const auto& el : js->items() )
351 wxString key( el.key().c_str(), wxConvUTF8 );
352 val[key] = el.value().get<wxString>();
355 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