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/>.
25 PrimitiveEntry constructor from Istream and Ostream output operator.
27 \*---------------------------------------------------------------------------*/
29 #include "primitiveEntry.H"
30 #include "functionEntry.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 void Foam::primitiveEntry::append
36 const token& currToken,
37 const dictionary& dict,
41 if (currToken.isWord())
43 const word& w = currToken.wordToken();
47 disableFunctionEntries
50 !(w[0] == '$' && expandVariable(w, dict))
51 && !(w[0] == '#' && expandFunction(w, dict, is))
55 newElmt(tokenIndex()++) = currToken;
60 newElmt(tokenIndex()++) = currToken;
65 bool Foam::primitiveEntry::expandFunction
68 const dictionary& parentDict,
72 word functionName = keyword(1, keyword.size()-1);
73 return functionEntry::execute(functionName, parentDict, *this, is);
77 bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
81 "primitiveEntry::readData(const dictionary&, Istream&)"
89 !is.read(currToken).bad()
91 && currToken != token::END_STATEMENT
94 append(currToken, dict, is);
98 currToken == token::BEGIN_BLOCK
99 || currToken == token::BEGIN_LIST
107 !is.read(currToken).bad()
109 && !(currToken == token::END_STATEMENT && blockCount == 0)
114 currToken == token::BEGIN_BLOCK
115 || currToken == token::BEGIN_LIST
122 currToken == token::END_BLOCK
123 || currToken == token::END_LIST
129 append(currToken, dict, is);
135 "primitiveEntry::readData(const dictionary&, Istream&)"
138 if (currToken.good())
149 void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is)
151 label keywordLineNumber = is.lineNumber();
156 setSize(tokenIndex());
161 std::ostringstream os;
162 os << "ill defined primitiveEntry starting at keyword '"
164 << " on line " << keywordLineNumber
165 << " and ending at line " << is.lineNumber();
169 "primitiveEntry::readEntry(const dictionary&, Istream&)",
177 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
179 Foam::primitiveEntry::primitiveEntry
182 const dictionary& dict,
189 is.name() + "::" + key,
199 Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is)
204 is.name() + "::" + key,
210 readEntry(dictionary::null, is);
214 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
216 void Foam::primitiveEntry::write(Ostream& os, const bool contentsOnly) const
220 os.writeKeyword(keyword());
223 for (label i=0; i<size(); ++i)
225 const token& t = operator[](i);
226 if (t.type() == token::VERBATIMSTRING)
228 os << token::HASH << token::BEGIN_BLOCK;
229 os.writeQuoted(t.stringToken(), false);
230 os << token::HASH << token::END_BLOCK;
245 os << token::END_STATEMENT << endl;
250 void Foam::primitiveEntry::write(Ostream& os) const
252 this->write(os, false);
256 // * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * * //
259 Foam::Ostream& Foam::operator<<
262 const InfoProxy<primitiveEntry>& ip
265 const primitiveEntry& e = ip.t_;
269 const label nPrintTokens = 10;
271 os << " primitiveEntry '" << e.keyword() << "' comprises ";
273 for (label i=0; i<min(e.size(), nPrintTokens); i++)
275 os << nl << " " << e[i].info();
278 if (e.size() > nPrintTokens)
289 // ************************************************************************* //