ENH: use stringOps::expandDict when processing codeStream input

This commit is contained in:
Mark Olesen 2011-02-23 14:22:14 +01:00
parent 31f6d9ba5e
commit 67fc6a171a
4 changed files with 28 additions and 12 deletions

View File

@ -14,10 +14,15 @@ FoamFile
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// #include "codeStreamDefaults"
// values from outer-scope
begIter 0;
endIter 200;
writeInterval #codeStream
{
// values from inner-scope
nDumps 5;
codeInclude
#{
#include "fvCFD.H"
@ -30,14 +35,15 @@ writeInterval #codeStream
code
#{
scalar start = 0;
scalar end = 100;
label nDumps = 5;
label interval = end - start;
Info<<"on-the-fly: " << ((interval)/nDumps) << endl;
os << ((interval)/nDumps);
label interval = ($endIter - $begIter);
label nDumps = $nDumps;
os << (interval / nDumps);
#};
};
// play with cleanup
#remove begIter
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -83,17 +83,21 @@ bool Foam::functionEntries::codeStream::execute
<< exit(FatalIOError);
}
// get code dictionary
// must reference parent for stringOps::expandDict to work nicely
dictionary codeDict("#codeStream", parentDict, is);
// Read three sections of code.
// Remove any leading whitespace - necessary for compilation options,
// convenience for includes and body.
dictionary codeDict(is);
// "codeInclude" is optional
string codeInclude;
if (codeDict.found("codeInclude"))
{
codeInclude = stringOps::trim(codeDict["codeInclude"]);
stringOps::inplaceExpandDict(codeInclude, codeDict);
}
// "codeOptions" is optional
@ -101,10 +105,13 @@ bool Foam::functionEntries::codeStream::execute
if (codeDict.found("codeOptions"))
{
codeOptions = stringOps::trim(codeDict["codeOptions"]);
stringOps::inplaceExpandDict(codeOptions, codeDict);
}
// "code" is mandatory
string code = stringOps::trim(codeDict["code"]);
stringOps::inplaceExpandDict(code, codeDict);
// Create SHA1 digest from the contents
SHA1Digest sha;

View File

@ -159,12 +159,11 @@ void Foam::codeStreamTools::copyAndExpand
{
is.getLine(line);
// normal expansion according to mapping
// expand according to mapping
// expanding according to env variables might cause too many
// surprises
stringOps::inplaceExpand(line, mapping);
// expand according to env variables
stringOps::inplaceExpandEnv(line, true, true);
os << line.c_str() << nl;
}
while (is.good());

View File

@ -96,6 +96,7 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
if (dict.found("codeInclude"))
{
codeInclude = stringOps::trim(dict["codeInclude"]);
stringOps::inplaceExpandDict(codeInclude, dict);
}
// "codeOptions" is optional
@ -103,10 +104,13 @@ void Foam::codedFixedValueFvPatchScalarField::writeLibrary
if (dict.found("codeOptions"))
{
codeOptions = stringOps::trim(dict["codeOptions"]);
stringOps::inplaceExpandDict(codeOptions, dict);
}
// "code" is mandatory
string code = stringOps::trim(dict["code"]);
stringOps::inplaceExpandDict(code, dict);
// Create SHA1 digest from the contents
SHA1Digest sha;