From 9e345e178000e1a66e0148366023892eb9f203a8 Mon Sep 17 00:00:00 2001 From: andy <andy> Date: Fri, 6 Dec 2013 10:24:23 +0000 Subject: [PATCH] ENH: Enabled dictionaries to be expanded in lists --- src/OpenFOAM/db/dictionary/dictionary.C | 20 +++++++++++++++++++ src/OpenFOAM/db/dictionary/dictionary.H | 3 +++ .../primitiveEntry/primitiveEntry.C | 11 ++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 57ebd84f761..fbc567b3bdd 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -28,6 +28,7 @@ License #include "dictionaryEntry.H" #include "regExp.H" #include "OSHA1stream.H" +#include "DynamicList.H" /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ @@ -277,6 +278,25 @@ Foam::SHA1Digest Foam::dictionary::digest() const } +Foam::tokenList Foam::dictionary::tokens() const +{ + // linearise dictionary into a string + OStringStream os; + write(os, false); + IStringStream is(os.str()); + + // parse string as tokens + DynamicList<token> tokens; + token t; + while (is.read(t)) + { + tokens.append(t); + } + + return tokenList(tokens.xfer()); +} + + bool Foam::dictionary::found ( const word& keyword, diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index f7e7f8668c2..3d4bdf1c633 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -262,6 +262,9 @@ public: //- Return the SHA1 digest of the dictionary contents SHA1Digest digest() const; + //- Return the dictionary as a list of tokens + tokenList tokens() const; + // Search and lookup diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C index 779709e4a06..d605ddc0010 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -72,7 +72,14 @@ bool Foam::primitiveEntry::expandVariable // ...if defined append its tokens into this if (ePtr) { - append(ePtr->stream()); + if (ePtr->isDict()) + { + append(ePtr->dict().tokens()); + } + else + { + append(ePtr->stream()); + } } else { -- GitLab