mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: dictionary: allow variable as dictionary keyword
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -30,6 +30,8 @@ License
|
|||||||
#include "inputModeEntry.H"
|
#include "inputModeEntry.H"
|
||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
#include "IOstreams.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
|
bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
|
||||||
@ -114,6 +116,9 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
|
|||||||
&& keyword[0] == '$'
|
&& keyword[0] == '$'
|
||||||
) // ... Substitution entry
|
) // ... Substitution entry
|
||||||
{
|
{
|
||||||
|
token nextToken(is);
|
||||||
|
is.putBack(nextToken);
|
||||||
|
|
||||||
if (keyword.size() > 2 && keyword[1] == token::BEGIN_BLOCK)
|
if (keyword.size() > 2 && keyword[1] == token::BEGIN_BLOCK)
|
||||||
{
|
{
|
||||||
// Recursive substitution mode. Replace between {} with
|
// Recursive substitution mode. Replace between {} with
|
||||||
@ -125,7 +130,48 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
|
|||||||
stringOps::inplaceExpand(s, parentDict, true, false);
|
stringOps::inplaceExpand(s, parentDict, true, false);
|
||||||
keyword.std::string::replace(1, keyword.size()-1, s);
|
keyword.std::string::replace(1, keyword.size()-1, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nextToken == token::BEGIN_BLOCK)
|
||||||
|
{
|
||||||
|
word varName = keyword(1, keyword.size()-1);
|
||||||
|
|
||||||
|
// lookup the variable name in the given dictionary
|
||||||
|
const entry* ePtr = parentDict.lookupScopedEntryPtr
|
||||||
|
(
|
||||||
|
varName,
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ePtr)
|
||||||
|
{
|
||||||
|
// Read as primitiveEntry
|
||||||
|
const word newKeyword(ePtr->stream());
|
||||||
|
|
||||||
|
return parentDict.add
|
||||||
|
(
|
||||||
|
new dictionaryEntry(newKeyword, parentDict, is),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalIOErrorIn
|
||||||
|
(
|
||||||
|
"entry::New(const dictionary& parentDict, Istream&)",
|
||||||
|
is
|
||||||
|
)
|
||||||
|
<< "Attempt to use undefined variable " << varName
|
||||||
|
<< " as keyword"
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
parentDict.substituteScopedKeyword(keyword);
|
parentDict.substituteScopedKeyword(keyword);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if
|
else if
|
||||||
|
|||||||
Reference in New Issue
Block a user