1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "primitiveEntry.H"
27 #include "dictionary.H"
28 #include "OSspecific.H"
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 void Foam::primitiveEntry::append(const UList<token>& varTokens)
36 newElmt(tokenIndex()++) = varTokens[i];
41 bool Foam::primitiveEntry::expandVariable
44 const dictionary& dict
47 word varName = w(1, w.size()-1);
49 // lookup the variable name in the given dictionary....
50 // Note: allow wildcards to match? For now disabled since following
51 // would expand internalField to wildcard match and not expected
54 // boundaryField { ".*" {YYY;} movingWall {value $internalField;}
55 const entry* ePtr = dict.lookupEntryPtr(varName, true, false);
57 // ...if defined append its tokens into this
60 append(ePtr->stream());
64 // not in the dictionary - try an environment variable
65 string envStr = getEnv(varName);
71 append(tokenList(IStringStream('(' + envStr + ')')()));
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& is)
84 name() += "::" + keyword();
88 Foam::primitiveEntry::primitiveEntry(const keyType& key, const token& t)
91 ITstream(key, tokenList(1, t))
95 Foam::primitiveEntry::primitiveEntry
98 const UList<token>& tokens
102 ITstream(key, tokens)
106 Foam::primitiveEntry::primitiveEntry
109 const Xfer<List<token> >& tokens
113 ITstream(key, tokens)
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 Foam::label Foam::primitiveEntry::startLineNumber() const
121 const tokenList& tokens = *this;
129 return tokens.first().lineNumber();
134 Foam::label Foam::primitiveEntry::endLineNumber() const
136 const tokenList& tokens = *this;
144 return tokens.last().lineNumber();
149 Foam::ITstream& Foam::primitiveEntry::stream() const
151 ITstream& is = const_cast<primitiveEntry&>(*this);
157 const Foam::dictionary& Foam::primitiveEntry::dict() const
159 FatalErrorIn("const dictionary& primitiveEntry::dict() const")
160 << "Attempt to return primitive entry " << info()
161 << " as a sub-dictionary"
162 << abort(FatalError);
164 return dictionary::null;
168 Foam::dictionary& Foam::primitiveEntry::dict()
170 FatalErrorIn("const dictionary& primitiveEntry::dict()")
171 << "Attempt to return primitive entry " << info()
172 << " as a sub-dictionary"
173 << abort(FatalError);
175 return const_cast<dictionary&>(dictionary::null);
179 // ************************************************************************* //