NESTED_SETTINGS: allow to create/load without a parent settings object. Used for test/mocking

This commit is contained in:
Tomasz Wlostowski 2020-04-13 16:48:43 +02:00
parent 5143f87678
commit ee70c6dd5b
1 changed files with 16 additions and 11 deletions

View File

@ -30,8 +30,10 @@ NESTED_SETTINGS::NESTED_SETTINGS( const std::string& aName, int aVersion, JSON_S
JSON_SETTINGS( aName, SETTINGS_LOC::NESTED, aVersion, std::move( aDefault ) ),
m_parent( aParent ), m_path( aPath )
{
wxASSERT( m_parent );
m_parent->AddNestedSettings( this );
if( m_parent )
{
m_parent->AddNestedSettings( this );
}
// In case we were created after the parent's ctor
LoadFromFile();
@ -48,17 +50,20 @@ void NESTED_SETTINGS::LoadFromFile( const std::string& aDirectory )
{
clear();
try
if( m_parent )
{
update( ( *m_parent )[PointerFromString( m_path ) ] );
try
{
update( ( *m_parent )[PointerFromString( m_path )] );
wxLogTrace( traceSettings, "Loaded NESTED_SETTINGS %s with schema %d",
GetFilename(), m_schemaVersion );
}
catch( ... )
{
wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not load from %s at %s",
m_filename, m_parent->GetFilename(), m_path );
wxLogTrace( traceSettings, "Loaded NESTED_SETTINGS %s with schema %d", GetFilename(),
m_schemaVersion );
}
catch( ... )
{
wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not load from %s at %s",
m_filename, m_parent->GetFilename(), m_path );
}
}
Load();