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