foamDictionary: Improved the -set "<substitutions>" option
Multiple substitutions can be made using the convenient -set "<substitutions>"
option which combines the selection of the entries with the substitutions made
on them using the same argument syntax used by #includeFunc, e.g.
foamDictionary system/controlDict -set "startTime=2000, endTime=3000"
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2016-2020 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -56,7 +56,10 @@ Usage
|
||||
Adds the entry (should not exist yet)
|
||||
|
||||
- \par -set \<value\>
|
||||
Adds or replaces the entry or applies a list of substitutions
|
||||
Adds or replaces the entry selected by \c -entry
|
||||
|
||||
- \par -set \<substitutions\>
|
||||
Applies the list of substitutions
|
||||
|
||||
- \par -merge \<value\>
|
||||
Merges the entry
|
||||
@ -134,6 +137,11 @@ Usage
|
||||
dictionary with keyword 'entryDDD' where DDD is the position
|
||||
in the dictionary (after ignoring the FoamFile entry).
|
||||
|
||||
- Substitute multiple entries:
|
||||
\verbatim
|
||||
foamDictionary system/controlDict -set "startTime=2000, endTime=3000"
|
||||
\endverbatim
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
@ -267,19 +275,9 @@ void remove(dictionary& dict, const dictionary& removeDict)
|
||||
|
||||
void substitute(dictionary& dict, string substitutions)
|
||||
{
|
||||
// Add '()' delimiters to the substitutions if not present
|
||||
const string whitespace(" \t");
|
||||
string::size_type last = substitutions.find_last_not_of(whitespace);
|
||||
if (substitutions[last] != ')')
|
||||
{
|
||||
substitutions = '(' + substitutions + ')';
|
||||
}
|
||||
|
||||
word funcName;
|
||||
wordReList args;
|
||||
List<Tuple2<word, string>> namedArgs;
|
||||
|
||||
dictArgList(substitutions, funcName, args, namedArgs);
|
||||
dictArgList(substitutions, args, namedArgs);
|
||||
|
||||
forAll(namedArgs, i)
|
||||
{
|
||||
|
||||
@ -1699,6 +1699,83 @@ void Foam::dictArgList
|
||||
}
|
||||
|
||||
|
||||
void Foam::dictArgList
|
||||
(
|
||||
const string& funcArgs,
|
||||
wordReList& args,
|
||||
List<Tuple2<word, string>>& namedArgs
|
||||
)
|
||||
{
|
||||
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 == '(')
|
||||
{
|
||||
++argLevel;
|
||||
}
|
||||
else if (c == ',' || std::next(iter) == funcArgs.end())
|
||||
{
|
||||
if (std::next(iter) == funcArgs.end())
|
||||
{
|
||||
if (c == ')')
|
||||
{
|
||||
--argLevel;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
if (argLevel == 0)
|
||||
{
|
||||
if (namedArg)
|
||||
{
|
||||
namedArgs.append
|
||||
(
|
||||
Tuple2<word, string>
|
||||
(
|
||||
argName,
|
||||
funcArgs(start, i - start)
|
||||
)
|
||||
);
|
||||
namedArg = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
args.append(wordRe(funcArgs(start, i - start)));
|
||||
}
|
||||
start = i+1;
|
||||
}
|
||||
}
|
||||
else if (c == '=')
|
||||
{
|
||||
argName = funcArgs(start, i - start);
|
||||
string::stripInvalid<variable>(argName);
|
||||
start = i+1;
|
||||
namedArg = true;
|
||||
}
|
||||
else if (c == ')')
|
||||
{
|
||||
--argLevel;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Pair<Foam::word> Foam::dictAndKeyword(const word& scopedName)
|
||||
{
|
||||
string::size_type i = scopedName.find_last_of
|
||||
|
||||
@ -748,6 +748,14 @@ void dictArgList
|
||||
List<Tuple2<word, string>>& namedArgs
|
||||
);
|
||||
|
||||
//- Parse dictionary substitution argument list
|
||||
void dictArgList
|
||||
(
|
||||
const string& funcArgs,
|
||||
wordReList& args,
|
||||
List<Tuple2<word, string>>& namedArgs
|
||||
);
|
||||
|
||||
//- Extracts dict name and keyword
|
||||
Pair<word> dictAndKeyword(const word& scopedName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user