dictionary: Standardised and centralised the argument list parser

to simplify maintenance
This commit is contained in:
Henry Weller
2020-09-19 15:52:09 +01:00
parent ad33cc2cc8
commit 560db98b34
5 changed files with 108 additions and 156 deletions

View File

@ -24,15 +24,11 @@ License
\*---------------------------------------------------------------------------*/
#include "functionObjectList.H"
#include "Time.H"
#include "mapPolyMesh.H"
#include "argList.H"
#include "timeControlFunctionObject.H"
#include "dictionaryEntry.H"
#include "stringOps.H"
#include "Tuple2.H"
#include "etcFiles.H"
#include "IOdictionary.H"
#include "wordAndDictionary.H"
@ -221,88 +217,18 @@ void Foam::functionObjectList::checkUnsetEntries
bool Foam::functionObjectList::readFunctionObject
(
const string& funcCall,
const string& funcArgs,
dictionary& functionsDict,
const string& context,
HashSet<word>& requiredFields,
const word& region
)
{
word funcName(funcCall);
int argLevel = 0;
word funcName;
wordReList args;
List<Tuple2<word, string>> namedArgs;
bool namedArg = false;
word argName;
word::size_type start = 0;
word::size_type i = 0;
for
(
word::const_iterator iter = funcCall.begin();
iter != funcCall.end();
++iter
)
{
char c = *iter;
if (c == '(')
{
if (argLevel == 0)
{
funcName = funcCall(start, i - start);
start = i+1;
}
++argLevel;
}
else if (c == ',' || c == ')')
{
if (argLevel == 1)
{
if (namedArg)
{
namedArgs.append
(
Tuple2<word, string>
(
argName,
funcCall(start, i - start)
)
);
namedArg = false;
}
else
{
args.append(wordRe(funcCall(start, i - start)));
}
start = i+1;
}
if (c == ')')
{
if (argLevel == 1)
{
break;
}
--argLevel;
}
}
else if (c == '=')
{
argName = funcCall(start, i - start);
string::stripInvalid<variable>(argName);
start = i+1;
namedArg = true;
}
++i;
}
// Strip whitespace from the function name
string::stripInvalid<word>(funcName);
dictArgList(funcArgs, funcName, args, namedArgs);
// Search for the functionObject dictionary
fileName path = findDict(funcName, region);
@ -398,9 +324,9 @@ bool Foam::functionObjectList::readFunctionObject
funcDict.set("region", region);
}
const word funcCallKeyword = string::validate<word>(funcCall);
const word funcArgsKeyword = string::validate<word>(funcArgs);
dictionary funcArgsDict;
funcArgsDict.add(funcCallKeyword, funcDict);
funcArgsDict.add(funcArgsKeyword, funcDict);
// Re-parse the funcDict to execute the functionEntries
// now that the function argument entries have been added
@ -416,16 +342,16 @@ bool Foam::functionObjectList::readFunctionObject
}
// Check for anything in the configuration that has not been set
checkUnsetEntries(funcCall, funcArgsDict, funcDict0, context);
checkUnsetEntries(funcArgs, funcArgsDict, funcDict0, context);
// Lookup the field, fields and objects entries from the now expanded
// funcDict and insert into the requiredFields
dictionary& expandedFuncDict = funcArgsDict.subDict(funcCallKeyword);
dictionary& expandedFuncDict = funcArgsDict.subDict(funcArgsKeyword);
if (functionObject::debug)
{
InfoInFunction
<< nl << incrIndent << indent
<< funcCall << expandedFuncDict
<< funcArgs << expandedFuncDict
<< decrIndent << endl;
}
if (expandedFuncDict.found("field"))
@ -451,7 +377,7 @@ bool Foam::functionObjectList::readFunctionObject
// Merge this functionObject dictionary into functionsDict
functionsDict.merge(funcArgsDict);
functionsDict.subDict(funcCallKeyword).name() = funcDict.name();
functionsDict.subDict(funcArgsKeyword).name() = funcDict.name();
return true;
}