From c3dc8376beea437f95b882d0b6bf04bb02b7a676 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 30 Oct 2019 21:11:40 +0100 Subject: [PATCH] Extract two utility methods to make loadAndSyncronizeInputProperties smaller. --- .../RifEclipseInputPropertyLoader.cpp | 48 ++++++++++++------- .../RifEclipseInputPropertyLoader.h | 9 ++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.cpp b/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.cpp index 80e5036098..c6be456374 100644 --- a/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.cpp +++ b/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.cpp @@ -62,15 +62,7 @@ void RifEclipseInputPropertyLoader::loadAndSyncronizeInputProperties( QFileInfo fileNameInfo( filenames[i] ); bool isExistingFile = fileNameInfo.exists(); - std::set fileKeywordSet; - - if ( isExistingFile ) - { - std::vector fileKeywords; - RifEclipseInputFileTools::findKeywordsOnFile( filenames[i], &fileKeywords ); - - for_all( fileKeywords, fkIt ) fileKeywordSet.insert( fileKeywords[fkIt].keyword ); - } + std::set fileKeywordSet = extractKeywordsOnFile( filenames[i], isExistingFile ); // Find the input property objects referring to the file @@ -128,13 +120,8 @@ void RifEclipseInputPropertyLoader::loadAndSyncronizeInputProperties( } } - for_all( inputPropertyCollection->inputProperties, i ) - { - if ( inputPropertyCollection->inputProperties[i]->resolvedState() == RimEclipseInputProperty::UNKNOWN ) - { - inputPropertyCollection->inputProperties[i]->resolvedState = RimEclipseInputProperty::FILE_MISSING; - } - } + // All input properties still unknown at this stage is missing a file + setResolvedState( inputPropertyCollection, RimEclipseInputProperty::UNKNOWN, RimEclipseInputProperty::FILE_MISSING ); } bool RifEclipseInputPropertyLoader::readInputPropertiesFromFiles( RimEclipseInputPropertyCollection* inputPropertyCollection, @@ -173,3 +160,32 @@ bool RifEclipseInputPropertyLoader::readInputPropertiesFromFiles( RimEclipseInpu // TODO: seems a bit optimistic? return true; } + +std::set RifEclipseInputPropertyLoader::extractKeywordsOnFile( const QString& filename, bool isExistingFile ) +{ + std::set fileKeywordSet; + if ( isExistingFile ) + { + std::vector fileKeywords; + RifEclipseInputFileTools::findKeywordsOnFile( filename, &fileKeywords ); + + for ( const RifKeywordAndFilePos& fileKeyword : fileKeywords ) + { + fileKeywordSet.insert( fileKeyword.keyword ); + } + } + return fileKeywordSet; +} + +void RifEclipseInputPropertyLoader::setResolvedState( RimEclipseInputPropertyCollection* inputPropertyCollection, + RimEclipseInputProperty::ResolveState currentState, + RimEclipseInputProperty::ResolveState newState ) +{ + for ( RimEclipseInputProperty* inputProperty : inputPropertyCollection->inputProperties ) + { + if ( inputProperty->resolvedState() == currentState ) + { + inputProperty->resolvedState = newState; + } + } +} diff --git a/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.h b/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.h index 63ac89db1b..2d504430e4 100644 --- a/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.h +++ b/ApplicationCode/FileInterface/RifEclipseInputPropertyLoader.h @@ -18,6 +18,9 @@ #pragma once +#include "RimEclipseInputProperty.h" + +#include #include #include @@ -45,4 +48,10 @@ private: // Hide constructor to prevent instantiation RifEclipseInputPropertyLoader(); ~RifEclipseInputPropertyLoader(); + + static std::set extractKeywordsOnFile( const QString& filename, bool isExistingFile ); + + static void setResolvedState( RimEclipseInputPropertyCollection* inputPropertyCollection, + RimEclipseInputProperty::ResolveState currentState, + RimEclipseInputProperty::ResolveState newState ); };