1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "dictionary.H"
29 #include "inputModeEntry.H"
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 bool Foam::dictionary::read(Istream& is)
38 FatalIOErrorIn("dictionary::read(Istream&, const word&)", is)
39 << "Istream not OK for reading dictionary "
40 << exit(FatalIOError);
46 if (currToken != token::BEGIN_BLOCK)
48 is.putBack(currToken);
51 while (!is.eof() && entry::New(*this, is))
54 // Remove the FoamFile header entry if it exists
59 Info<< "dictionary::read(Istream&, const word&) : "
60 << "Istream not OK after reading dictionary " << name()
70 bool Foam::dictionary::substituteKeyword(const word& keyword)
72 word varName = keyword(1, keyword.size()-1);
74 // lookup the variable name in the given dictionary
75 const entry* ePtr = lookupEntryPtr(varName, true, true);
77 // if defined insert its entries into this dictionary
80 const dictionary& addDict = ePtr->dict();
82 forAllConstIter(IDLList<entry>, addDict, iter)
94 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 Foam::dictionary::dictionary
98 const dictionary& parentDict,
109 Foam::dictionary::dictionary(Istream& is)
112 parent_(dictionary::null)
114 // Reset input mode as this is a "top-level" dictionary
115 functionEntries::inputModeEntry::clear();
121 Foam::autoPtr<Foam::dictionary> Foam::dictionary::New(Istream& is)
123 return autoPtr<dictionary>(new dictionary(is));
127 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
129 Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
131 // Reset input mode assuming this is a "top-level" dictionary
132 functionEntries::inputModeEntry::clear();
141 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
143 void Foam::dictionary::write(Ostream& os, bool subDict) const
147 os << nl << indent << token::BEGIN_BLOCK << incrIndent << nl;
150 forAllConstIter(IDLList<entry>, *this, iter)
152 const entry& e = *iter;
157 // Add extra new line between entries for "top-level" dictionaries
158 if (!subDict && parent() == dictionary::null && e != *last())
163 // Check stream before going to next entry.
166 WarningIn("dictionary::write(Ostream&, bool subDict)")
167 << "Can't write entry " << iter().keyword()
168 << " for dictionary " << name()
175 os << decrIndent << indent << token::END_BLOCK << endl;
180 Foam::Ostream& Foam::operator<<(Ostream& os, const dictionary& dict)
182 dict.write(os, true);
187 // ************************************************************************* //