Extract two utility methods to make loadAndSyncronizeInputProperties smaller.

This commit is contained in:
Kristian Bendiksen 2019-10-30 21:11:40 +01:00
parent 22a5a1fe0f
commit c3dc8376be
2 changed files with 41 additions and 16 deletions

View File

@ -62,15 +62,7 @@ void RifEclipseInputPropertyLoader::loadAndSyncronizeInputProperties(
QFileInfo fileNameInfo( filenames[i] );
bool isExistingFile = fileNameInfo.exists();
std::set<QString> fileKeywordSet;
if ( isExistingFile )
{
std::vector<RifKeywordAndFilePos> fileKeywords;
RifEclipseInputFileTools::findKeywordsOnFile( filenames[i], &fileKeywords );
for_all( fileKeywords, fkIt ) fileKeywordSet.insert( fileKeywords[fkIt].keyword );
}
std::set<QString> 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<QString> RifEclipseInputPropertyLoader::extractKeywordsOnFile( const QString& filename, bool isExistingFile )
{
std::set<QString> fileKeywordSet;
if ( isExistingFile )
{
std::vector<RifKeywordAndFilePos> 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;
}
}
}

View File

@ -18,6 +18,9 @@
#pragma once
#include "RimEclipseInputProperty.h"
#include <set>
#include <vector>
#include <QString>
@ -45,4 +48,10 @@ private:
// Hide constructor to prevent instantiation
RifEclipseInputPropertyLoader();
~RifEclipseInputPropertyLoader();
static std::set<QString> extractKeywordsOnFile( const QString& filename, bool isExistingFile );
static void setResolvedState( RimEclipseInputPropertyCollection* inputPropertyCollection,
RimEclipseInputProperty::ResolveState currentState,
RimEclipseInputProperty::ResolveState newState );
};