From 0d8fff3a5f31df3e1f7ab91d0652cda3a04dbf32 Mon Sep 17 00:00:00 2001 From: mattijs Date: Sat, 17 Aug 2013 05:28:31 +0100 Subject: [PATCH] ENH: codeStream: function in dictionary context --- .../functionEntries/codeStream/codeStream.C | 40 +++++++++++++++++++ .../functionEntries/codeStream/codeStream.H | 6 ++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C index 66065c4528..1c774c352b 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C @@ -39,6 +39,14 @@ namespace functionEntries { defineTypeNameAndDebug(codeStream, 0); + addToMemberFunctionSelectionTable + ( + functionEntry, + codeStream, + execute, + dictionaryIstream + ); + addToMemberFunctionSelectionTable ( functionEntry, @@ -364,6 +372,38 @@ bool Foam::functionEntries::codeStream::execute IStringStream resultStream(os.str()); entry.read(parentDict, resultStream); + return true; +} + + +bool Foam::functionEntries::codeStream::execute +( + dictionary& parentDict, + Istream& is +) +{ + Info<< "Using #codeStream at line " << is.lineNumber() + << " in file " << parentDict.name() << endl; + + dynamicCode::checkSecurity + ( + "functionEntries::codeStream::execute(..)", + parentDict + ); + + // get code dictionary + // must reference parent for stringOps::expand to work nicely + dictionary codeDict("#codeStream", parentDict, is); + + streamingFunctionType function = 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/codeStream/codeStream.H b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H index b8baa0183c..1dc2b57c87 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.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 @@ -160,6 +160,10 @@ 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,