mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
#14683 Share OPM parser for keyword lookups
This commit is contained in:
1 parent
275b120688
commit
2462170647
4 files changed
+19
-31
No files matched your search
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "Commands/CompletionExportCommands/RicWellPathExportCompletionDataFeatureImpl.h"
|
||||
|
||||
#include "RiaOpmKeywordTools.h"
|
||||
#include "RiaResultNames.h"
|
||||
|
||||
#include "RifEclipseInputFileTools.h"
|
||||
@@ -64,18 +65,6 @@
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
namespace
|
||||
{
|
||||
// A single shared parser instance is used for all keyword schema lookups. Constructing an
|
||||
// Opm::Parser populates the complete keyword database and costs milliseconds, which is far too
|
||||
// expensive to repeat for every keyword being serialised.
|
||||
const Opm::Parser& sharedParser()
|
||||
{
|
||||
static const Opm::Parser parser;
|
||||
return parser;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace RimKeywordFactory
|
||||
{
|
||||
|
||||
@@ -944,7 +933,7 @@ QString deckKeywordToAlignedString( const Opm::DeckKeyword& keyword )
|
||||
std::vector<std::string> canonicalItemOrder;
|
||||
try
|
||||
{
|
||||
const Opm::ParserKeyword& parserKeyword = sharedParser().getKeyword( keyword.name() );
|
||||
const Opm::ParserKeyword& parserKeyword = RiaOpmKeywordTools::defaultParser().getKeyword( keyword.name() );
|
||||
if ( std::distance( parserKeyword.begin(), parserKeyword.end() ) == 1 )
|
||||
{
|
||||
const Opm::ParserRecord& parserRecord = parserKeyword.getRecord( 0 );
|
||||
@@ -1089,7 +1078,7 @@ QString deckKeywordToAlignedString( const Opm::DeckKeyword& keyword )
|
||||
bool slashTerminated = true;
|
||||
try
|
||||
{
|
||||
slashTerminated = !sharedParser().getKeyword( keyword.name() ).hasFixedSize();
|
||||
slashTerminated = !RiaOpmKeywordTools::defaultParser().getKeyword( keyword.name() ).hasFixedSize();
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
|
||||
@@ -26,14 +26,16 @@
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
|
||||
namespace
|
||||
{
|
||||
const Opm::Parser& sharedParser()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const Opm::Parser& RiaOpmKeywordTools::defaultParser()
|
||||
{
|
||||
// Constructing an Opm::Parser builds the complete keyword database. Keep one shared instance
|
||||
// for all keyword schema lookups.
|
||||
static const Opm::Parser parser( true );
|
||||
return parser;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@@ -41,7 +43,7 @@ const Opm::Parser& sharedParser()
|
||||
std::optional<RiaOpmKeywordInfo> RiaOpmKeywordTools::keywordInfo( const QString& keywordName )
|
||||
{
|
||||
const QString keyword = keywordName.toUpper();
|
||||
const auto& parser = sharedParser();
|
||||
const auto& parser = defaultParser();
|
||||
const auto deckName = keyword.toStdString();
|
||||
|
||||
if ( !parser.isRecognizedKeyword( deckName ) ) return std::nullopt;
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
class Parser;
|
||||
}
|
||||
|
||||
struct RiaOpmKeywordInfo
|
||||
{
|
||||
QString name;
|
||||
@@ -32,5 +37,6 @@ struct RiaOpmKeywordInfo
|
||||
|
||||
namespace RiaOpmKeywordTools
|
||||
{
|
||||
const Opm::Parser& defaultParser();
|
||||
std::optional<RiaOpmKeywordInfo> keywordInfo( const QString& keywordName );
|
||||
} // namespace RiaOpmKeywordTools
|
||||
Reference in new issue
Block a user