diff --git a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C index d87633f4db..144bec118a 100644 --- a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C +++ b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C @@ -276,75 +276,10 @@ void substitute(dictionary& dict, string substitutions) } word funcName; - int argLevel = 0; + wordReList args; List> namedArgs; - bool namedArg = false; - word argName; - word::size_type start = 0; - word::size_type i = 0; - - for - ( - word::const_iterator iter = substitutions.begin(); - iter != substitutions.end(); - ++iter - ) - { - char c = *iter; - - if (c == '(') - { - if (argLevel == 0) - { - funcName = substitutions(start, i - start); - start = i+1; - } - ++argLevel; - } - else if (c == ',' || c == ')') - { - if (argLevel == 1) - { - if (namedArg) - { - namedArgs.append - ( - Tuple2 - ( - argName, - substitutions(start, i - start) - ) - ); - namedArg = false; - } - else - { - FatalIOErrorInFunction(dict) - << "Unnamed substitution" << exit(FatalIOError); - } - start = i+1; - } - - if (c == ')') - { - if (argLevel == 1) - { - break; - } - --argLevel; - } - } - else if (c == '=') - { - argName = substitutions(start, i - start); - string::stripInvalid(argName); - start = i+1; - namedArg = true; - } - - ++i; - } + dictArgList(substitutions, funcName, args, namedArgs); forAll(namedArgs, i) { diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 25903098f7..a8694c7fa2 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -1556,6 +1556,89 @@ Foam::dictionary Foam::operator| // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // +void Foam::dictArgList +( + const string& funcArgs, + word& funcName, + wordReList& args, + List>& namedArgs +) +{ + funcName = funcArgs; + + int argLevel = 0; + bool namedArg = false; + word argName; + + word::size_type start = 0; + word::size_type i = 0; + + for + ( + word::const_iterator iter = funcArgs.begin(); + iter != funcArgs.end(); + ++iter + ) + { + char c = *iter; + + if (c == '(') + { + if (argLevel == 0) + { + funcName = funcArgs(start, i - start); + start = i+1; + } + ++argLevel; + } + else if (c == ',' || c == ')') + { + if (argLevel == 1) + { + if (namedArg) + { + namedArgs.append + ( + Tuple2 + ( + argName, + funcArgs(start, i - start) + ) + ); + namedArg = false; + } + else + { + args.append(wordRe(funcArgs(start, i - start))); + } + start = i+1; + } + + if (c == ')') + { + if (argLevel == 1) + { + break; + } + --argLevel; + } + } + else if (c == '=') + { + argName = funcArgs(start, i - start); + string::stripInvalid(argName); + start = i+1; + namedArg = true; + } + + ++i; + } + + // Strip whitespace from the function name + string::stripInvalid(funcName); +} + + Foam::Pair Foam::dictAndKeyword(const word& scopedName) { string::size_type i = scopedName.find_last_of diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index b968f0cfb5..18e93b7b5e 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -53,12 +53,11 @@ SourceFiles #include "entry.H" #include "IDLList.H" #include "DLList.H" -#include "fileName.H" -#include "ITstream.H" #include "HashTable.H" -#include "wordList.H" -#include "className.H" +#include "ITstream.H" +#include "wordReList.H" #include "Pair.H" +#include "className.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -634,6 +633,15 @@ dictionary operator|(const dictionary& dict1, const dictionary& dict2); // Global Functions +//- Parse dictionary substitution argument list +void dictArgList +( + const string& funcArgs, + word& funcName, + wordReList& args, + List>& namedArgs +); + //- Extracts dict name and keyword Pair dictAndKeyword(const word& scopedName); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 1403a588ac..bd15bd87c3 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -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& requiredFields, const word& region ) { - word funcName(funcCall); - - int argLevel = 0; + word funcName; wordReList args; - List> 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 - ( - 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(argName); - start = i+1; - namedArg = true; - } - - ++i; - } - - // Strip whitespace from the function name - string::stripInvalid(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(funcCall); + const word funcArgsKeyword = string::validate(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; } diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index 2386da1b66..bed96380c8 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -222,7 +222,7 @@ public: ); //- Read the specified functionObject configuration dictionary - // parsing the optional arguments included in the string 'funcCall', + // parsing the optional arguments included in the string 'funcArgs', // inserting 'field' or 'fields' entries as required and merging the // resulting functionObject dictionary into 'functionsDict'. // Any fields required to execute the functionObject are added to @@ -242,7 +242,7 @@ public: // fields (p U); static bool readFunctionObject ( - const string& funcCall, + const string& funcArgs, dictionary& functionsDict, const string& context, HashSet& requiredFields,