30 const std::string& aPath,
bool aLoadFromFile ) :
41 m_parent->ReleaseNestedSettings(
this );
49 bool migrationFailed =
false;
55 if(
m_parent->m_internals->contains( ptr ) )
67 wxLogTrace(
traceSettings, wxT(
"NESTED_SETTINGS %s: Could not load from "
84 wxLogTrace(
traceSettings, wxT(
"%s: nested settings version could not be read!" ),
91 wxLogTrace(
traceSettings, wxT(
"%s: attempting migration from version %d to %d" ),
94 bool migrated =
false;
109 migrationFailed =
true;
115 wxT(
"%s: warning: nested settings version %d is newer than latest (%d)" ),
118 else if( filever >= 0 )
120 wxLogTrace(
traceSettings, wxT(
"%s: schema version %d is current" ),
129 settings->LoadFromFile();
157 bool modified = !jsonObjectInParent
158 || !nlohmann::json::diff( *
m_internals, jsonObjectInParent.value() ).empty();
167 if( !param->ClearUnknownKeys() )
170 std::string
path = param->GetJsonPath();
180 if( original.contains( ptr ) )
181 original[ptr] = nlohmann::json::object();
187 if( modified || aForce )
191 wxLogTrace(
traceSettings, wxS(
"Stored NESTED_SETTINGS %s with schema %d" ),
200 wxLogTrace(
traceSettings, wxS(
"NESTED_SETTINGS %s: Could not store to %s at %s" ),
217 m_parent->AddNestedSettings(
this );
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
nlohmann::json m_original
wxString m_filename
The filename (not including path) of this settings file (inicode)
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
bool m_modified
True if the JSON data store has been written to since the last file write.
bool m_writeImplicitly
Whether migration and default fill may write the file by themselves.
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
wxString GetFullFilename() const
bool Migrate()
Migrates the schema of this settings from the version in the file to the latest version.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
friend class NESTED_SETTINGS
int m_schemaVersion
Version of this settings schema.
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
wxString GetFilename() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
void SetParent(JSON_SETTINGS *aParent, bool aLoadFromFile=true)
std::string m_path
The path (in pointer format) of where to store this document in the parent.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
virtual ~NESTED_SETTINGS()
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS.
NESTED_SETTINGS(const std::string &aName, int aSchemaVersion, JSON_SETTINGS *aParent, const std::string &aPath, bool aLoadFromFile=true)
bool LoadFromFile(const wxString &aDirectory="") override
Loads the JSON document from the parent and then calls Load()
@ NESTED
Not stored in a file, but inside another JSON_SETTINGS.
std::vector< FAB_LAYER_COLOR > dummy