From f9d4a778284097e1e905f79c211838f9eac421ab Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Fri, 6 Sep 2013 13:05:02 +0100 Subject: [PATCH] ENH: #calc: allow in primitiveEntry --- .../functionEntries/calcEntry/calcEntry.C | 54 ++++++++++++++++++- .../functionEntries/calcEntry/calcEntry.H | 5 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C index 7bb6c1c14a3..bc5a1e65eaa 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,6 +37,14 @@ namespace functionEntries { defineTypeNameAndDebug(calcEntry, 0); + addToMemberFunctionSelectionTable + ( + functionEntry, + calcEntry, + execute, + dictionaryIstream + ); + addToMemberFunctionSelectionTable ( functionEntry, @@ -96,4 +104,48 @@ bool Foam::functionEntries::calcEntry::execute } +bool Foam::functionEntries::calcEntry::execute +( + dictionary& parentDict, + Istream& is +) +{ + Info<< "Using #calcEntry at line " << is.lineNumber() + << " in file " << parentDict.name() << endl; + + dynamicCode::checkSecurity + ( + "functionEntries::calcEntry::execute(..)", + parentDict + ); + + // Read string + string s(is); + // Make sure we stop this entry + //is.putBack(token(token::END_STATEMENT, is.lineNumber())); + + // Construct codeDict for codeStream + // must reference parent for stringOps::expand to work nicely. + dictionary codeSubDict; + codeSubDict.add("code", "os << (" + s + ");"); + dictionary codeDict(parentDict, codeSubDict); + + codeStream::streamingFunctionType function = codeStream::getFunction + ( + parentDict, + codeDict + ); + + // use function to write stream + OStringStream os(is.format()); + (*function)(os, parentDict); + + // get the entry from this stream + IStringStream resultStream(os.str()); + parentDict.read(resultStream); + + return true; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H index 9e26072c5f2..e1083db42a4 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/calcEntry/calcEntry.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -89,6 +89,9 @@ public: // Member Functions //- Execute the functionEntry in a sub-dict context + static bool execute(dictionary& parentDict, Istream&); + + //- Execute the functionEntry in a primitiveEntry context static bool execute ( const dictionary& parentDict, -- GitLab