21 #include <wx/string.h> 23 #include <nlohmann/json.hpp> 30 template <
typename ValueType>
36 if( std::is_same<ValueType, nlohmann::json>::value )
41 m_setter( m_default );
48 m_setter( m_default );
53 template <
typename ValueType>
56 if( std::is_same<ValueType, nlohmann::json>::value )
59 return *optval == m_getter();
64 return *optval == m_getter();
79 template <
typename ValueType>
87 std::vector<ValueType> val;
91 for(
const auto& el : js->items() )
92 val.push_back( el.value().get<ValueType>() );
97 else if( aResetIfMissing )
102 template <
typename ValueType>
107 for(
const auto& el : *m_ptr )
114 template <
typename ValueType>
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;
145 for(
const auto& el : *
m_ptr )
158 std::vector<wxString> val;
160 for(
const auto& el : js->items() )
163 return val == *
m_ptr;
171 template <
typename Value>
179 if( js->is_object() )
183 for(
const auto& el : js->items() )
184 ( *m_ptr )[el.key()] = el.value().get<Value>();
187 else if( aResetIfMissing )
192 template <
typename Value>
197 for(
const auto& el : *m_ptr )
198 js[el.first] = el.second;
204 template <
typename Value>
209 if( js->is_object() )
211 if( m_ptr->size() != js->size() )
214 std::map<std::string, Value> val;
216 for(
const auto& el : js->items() )
217 val[el.key()] = el.value().get<Value>();
219 return val == *m_ptr;
239 if( js->is_object() )
243 for(
const auto& el : js->items() )
245 ( *m_ptr )[wxString( el.key().c_str(), wxConvUTF8 )] = el.value().get<wxString>();
249 else if( aResetIfMissing )
258 for(
const auto& el : *
m_ptr )
260 std::string key( el.first.ToUTF8() );
272 if( js->is_object() )
274 if(
m_ptr->size() != js->size() )
277 std::map<wxString, wxString> val;
279 for(
const auto& el : js->items() )
281 wxString key( el.key().c_str(), wxConvUTF8 );
282 val[key] = el.value().get<wxString>();
285 return val == *
m_ptr;
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
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...
Like a normal param, but with custom getter and setter functions.
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
std::string m_path
the string used to store the param in json files
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.
std::map< wxString, wxString > * m_ptr
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
OPT< 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::map< wxString, wxString > m_default
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.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
wxString fromFileFormat(const wxString &aString) const
void Load(JSON_SETTINGS *aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
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
std::vector< wxString > * m_ptr
bool MatchesFile(JSON_SETTINGS *aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
OPT< 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
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.