diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H index 51df64613a..e08cf3cec5 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H @@ -92,7 +92,7 @@ public: const dictionary& dict ); - //- Construct as copy for the given parentDict + //- Construct as copy for the given parent dictionary dictionaryEntry ( const dictionary& parentDict, diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index 489395e43a..b9972d227a 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -79,7 +79,7 @@ void Foam::dictionaryEntry::write(Ostream& os) const } -// * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * // Foam::Ostream& Foam::operator<<(Ostream& os, const dictionaryEntry& de) { diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C index d3f69ddb4d..dd80336627 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C @@ -26,33 +26,92 @@ License #include "primitiveEntry.H" #include "dictionary.H" +#include "OSspecific.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::primitiveEntry::append(const UList& varTokens) +{ + forAll(varTokens, i) + { + newElmt(tokenIndex()++) = varTokens[i]; + } +} + + +bool Foam::primitiveEntry::expandVariable +( + const word& w, + const dictionary& dict +) +{ + word varName = w(1, w.size()-1); + + // lookup the variable name in the given dictionary.... + // Note: allow wildcards to match? For now disabled since following + // would expand internalField to wildcard match and not expected + // internalField: + // internalField XXX; + // boundaryField { ".*" {YYY;} movingWall {value $internalField;} + const entry* ePtr = dict.lookupEntryPtr(varName, true, false); + + // ...if defined append its tokens into this + if (ePtr) + { + append(ePtr->stream()); + } + else + { + // not in the dictionary - try an environment variable + string envStr = getEnv(varName); + + if (envStr.empty()) + { + return false; + } + append(tokenList(IStringStream('(' + envStr + ')')())); + } + return true; +} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens) +Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& is) : entry(key), - ITstream(tokens) + ITstream(is) { name() += "::" + keyword(); } -Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t) +Foam::primitiveEntry::primitiveEntry(const keyType& key, const token& t) : - entry(keyword), - ITstream(keyword, tokenList(1, t)) + entry(key), + ITstream(key, tokenList(1, t)) {} Foam::primitiveEntry::primitiveEntry ( - const keyType& keyword, - const tokenList& tokens + const keyType& key, + const UList& tokens ) : - entry(keyword), - ITstream(keyword, tokens) + entry(key), + ITstream(key, tokens) +{} + + +Foam::primitiveEntry::primitiveEntry +( + const keyType& key, + const Xfer< List >& tokens +) +: + entry(key), + ITstream(key, tokens) {} @@ -118,43 +177,4 @@ Foam::dictionary& Foam::primitiveEntry::dict() } -void Foam::primitiveEntry::insert -( - const tokenList& varTokens, - const label posI -) -{ - tokenList& tokens = *this; - - if (varTokens.empty()) - { - label end = tokens.size() - 1; - - for (label j = posI; j < end; j++) - { - tokens[j] = tokens[j+1]; - } - - tokens.setSize(tokens.size() - 1); - } - else if (varTokens.size() > 1) - { - tokens.setSize(tokens.size() + varTokens.size() - 1); - - label end = tokens.size() - 1; - label offset = varTokens.size() - 1; - - for (label j = end; j > posI; j--) - { - tokens[j] = tokens[j-offset]; - } - } - - forAll(varTokens, j) - { - tokens[posI + j] = varTokens[j]; - } -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H index afc3912483..60722f9a27 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H @@ -68,6 +68,9 @@ class primitiveEntry { // Private member functions + //- Append the given tokens starting at the current tokenIndex + void append(const UList&); + //- Append the given token to this entry void append ( @@ -76,9 +79,6 @@ class primitiveEntry Istream& ); - //- Append the given tokens starting at the current tokenIndex - void append(const tokenList&); - //- Expand the given variable (keyword starts with $) bool expandVariable(const word&, const dictionary&); @@ -93,9 +93,6 @@ class primitiveEntry //- Read the complete entry from the given stream void readEntry(const dictionary&, Istream&); - //- Insert the given tokens at token posI - void insert(const tokenList&, const label posI); - public: @@ -110,11 +107,14 @@ public: //- Construct from keyword and a ITstream primitiveEntry(const keyType&, const ITstream&); - //- Construct from keyword and a token + //- Construct from keyword and a single token primitiveEntry(const keyType&, const token&); - //- Construct from keyword and a tokenList - primitiveEntry(const keyType&, const tokenList&); + //- Construct from keyword and a list of tokens + primitiveEntry(const keyType&, const UList&); + + //- Construct from keyword and by transferring a list of tokens + primitiveEntry(const keyType&, const Xfer< List >&); //- Construct from keyword and a T template @@ -166,7 +166,7 @@ public: //- Read tokens from the given stream bool read(const dictionary&, Istream&); - // Write + //- Write void write(Ostream&) const; //- Return info proxy. diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index 64810f54f4..3fbbac5b45 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -28,10 +28,9 @@ Description \*---------------------------------------------------------------------------*/ #include "primitiveEntry.H" -#include "OSspecific.H" #include "functionEntry.H" -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::primitiveEntry::append ( @@ -63,55 +62,6 @@ void Foam::primitiveEntry::append } -void Foam::primitiveEntry::append(const tokenList& varTokens) -{ - forAll(varTokens, i) - { - newElmt(tokenIndex()++) = varTokens[i]; - } -} - - -bool Foam::primitiveEntry::expandVariable -( - const word& w, - const dictionary& dict -) -{ - word varName = w(1, w.size()-1); - - // lookup the variable name in the given dictionary.... - // Note: allow wildcards to match? For now disabled since following - // would expand internalField to wildcard match and not expected - // internalField: - // internalField XXX; - // boundaryField { ".*" {YYY;} movingWall {value $internalField;} - const entry* ePtr = dict.lookupEntryPtr(varName, true, false); - - // ...if defined insert its tokens into this - if (ePtr != NULL) - { - append(ePtr->stream()); - return true; - } - else - { - // if not in the dictionary see if it is an environment - // variable - - string enVarString = getEnv(varName); - - if (enVarString.size()) - { - append(tokenList(IStringStream('(' + enVarString + ')')())); - return true; - } - - return false; - } -} - - bool Foam::primitiveEntry::expandFunction ( const word& keyword, @@ -221,6 +171,8 @@ void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is) } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + Foam::primitiveEntry::primitiveEntry ( const keyType& key, diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C index 1bf1e7c327..293ff9df11 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C @@ -30,13 +30,13 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const T& t) +Foam::primitiveEntry::primitiveEntry(const keyType& key, const T& t) : - entry(keyword), - ITstream(keyword, tokenList(10)) + entry(key), + ITstream(key, tokenList(10)) { OStringStream os; - os << t << token::END_STATEMENT; + os << t << token::END_STATEMENT; readEntry(dictionary::null, IStringStream(os.str())()); }