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 "dictionary.H"
28 #include "inputModeEntry.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 Foam::dictionary::dictionary
36 const dictionary& parentDict,
40 dictionaryName(parentDict.name() + "::" + name),
47 Foam::dictionary::dictionary(Istream& is)
49 dictionaryName(is.name()),
50 parent_(dictionary::null)
52 // Reset input mode as this is a "top-level" dictionary
53 functionEntries::inputModeEntry::clear();
59 Foam::dictionary::dictionary(Istream& is, const bool keepHeader)
61 dictionaryName(is.name()),
62 parent_(dictionary::null)
64 // Reset input mode as this is a "top-level" dictionary
65 functionEntries::inputModeEntry::clear();
71 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
73 Foam::autoPtr<Foam::dictionary> Foam::dictionary::New(Istream& is)
75 return autoPtr<dictionary>(new dictionary(is));
79 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
81 bool Foam::dictionary::read(Istream& is, const bool keepHeader)
85 FatalIOErrorIn("dictionary::read(Istream&, bool)", is)
86 << "Istream not OK for reading dictionary "
87 << exit(FatalIOError);
93 if (currToken != token::BEGIN_BLOCK)
95 is.putBack(currToken);
98 while (!is.eof() && entry::New(*this, is))
101 // normally remove the FoamFile header entry if it exists
109 Info<< "dictionary::read(Istream&, bool) : "
110 << "Istream not OK after reading dictionary " << name()
120 bool Foam::dictionary::read(Istream& is)
122 return this->read(is, false);
126 bool Foam::dictionary::substituteKeyword(const word& keyword)
128 word varName = keyword(1, keyword.size()-1);
130 // lookup the variable name in the given dictionary
131 const entry* ePtr = lookupEntryPtr(varName, true, true);
133 // if defined insert its entries into this dictionary
136 const dictionary& addDict = ePtr->dict();
138 forAllConstIter(IDLList<entry>, addDict, iter)
150 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
152 Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
154 // Reset input mode assuming this is a "top-level" dictionary
155 functionEntries::inputModeEntry::clear();
158 dict.name() = is.name();
165 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
167 void Foam::dictionary::write(Ostream& os, bool subDict) const
171 os << nl << indent << token::BEGIN_BLOCK << incrIndent << nl;
174 forAllConstIter(IDLList<entry>, *this, iter)
176 const entry& e = *iter;
181 // Add extra new line between entries for "top-level" dictionaries
182 if (!subDict && parent() == dictionary::null && e != *last())
187 // Check stream before going to next entry.
190 WarningIn("dictionary::write(Ostream&, bool subDict)")
191 << "Can't write entry " << iter().keyword()
192 << " for dictionary " << name()
199 os << decrIndent << indent << token::END_BLOCK << endl;
204 Foam::Ostream& Foam::operator<<(Ostream& os, const dictionary& dict)
206 dict.write(os, true);
211 // ************************************************************************* //