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();
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>
107 for(
const auto& el : *m_ptr )
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() )
124 val.emplace_back( el.value().get<ValueType>() );
126 return val == *m_ptr;
141template <
typename ValueType>
147 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
149 std::set<ValueType> val;
153 for(
const auto& el : js->items() )
154 val.insert( el.value().get<ValueType>() );
159 else if( aResetIfMissing )
164template <
typename ValueType>
169 for(
const auto& el : *m_ptr )
176template <
typename ValueType>
179 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
183 std::set<ValueType> val;
185 for(
const auto& el : js->items() )
186 val.insert( el.value().get<ValueType>() );
188 return val == *m_ptr;
203 for(
const auto& el : *
m_ptr )
212 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
216 std::vector<wxString> val;
218 for(
const auto& el : js->items() )
221 return val == *
m_ptr;
229template <
typename Value>
235 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
237 if( js->is_object() )
241 for(
const auto& el : js->items() )
242 ( *m_ptr )[el.key()] = el.value().get<Value>();
245 else if( aResetIfMissing )
250template <
typename Value>
255 for(
const auto& el : *m_ptr )
256 js[el.first] = el.second;
262template <
typename Value>
265 if( std::optional<nlohmann::json> js = aSettings->
GetJson( m_path ) )
267 if( js->is_object() )
269 if( m_ptr->size() != js->size() )
272 std::map<std::string, Value> val;
274 for(
const auto& el : js->items() )
275 val[el.key()] = el.value().get<Value>();
277 return val == *m_ptr;
295 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
297 if( js->is_object() )
301 for(
const auto& el : js->items() )
303 ( *m_ptr )[wxString( el.key().c_str(), wxConvUTF8 )] = el.value().get<wxString>();
307 else if( aResetIfMissing )
318 std::string key( el.first.ToUTF8() );
328 if( std::optional<nlohmann::json> js = aSettings->
GetJson(
m_path ) )
330 if( js->is_object() )
332 if(
m_ptr->size() != js->size() )
335 std::map<wxString, wxString> val;
337 for(
const auto& el : js->items() )
339 wxString key( el.key().c_str(), wxConvUTF8 );
340 val[key] = el.value().get<wxString>();
343 return val == *
m_ptr;
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...
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
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