mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
- partial revert for commit d21869b580
* only add extra newlines for a top-level dictionary that is output as such
- make "#inputMode merge" the default instead of "#inputMode error"
* this corresponds to a very common usage case
188 lines
4.6 KiB
C
188 lines
4.6 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
|
\\/ M anipulation |
|
|
-------------------------------------------------------------------------------
|
|
License
|
|
This file is part of OpenFOAM.
|
|
|
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
option) any later version.
|
|
|
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "dictionary.H"
|
|
#include "IFstream.H"
|
|
#include "inputModeEntry.H"
|
|
#include "regExp.H"
|
|
|
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
|
|
bool Foam::dictionary::read(Istream& is)
|
|
{
|
|
if (!is.good())
|
|
{
|
|
FatalIOErrorIn("dictionary::read(Istream&, const word&)", is)
|
|
<< "Istream not OK for reading dictionary "
|
|
<< exit(FatalIOError);
|
|
|
|
return false;
|
|
}
|
|
|
|
token currToken(is);
|
|
if (currToken != token::BEGIN_BLOCK)
|
|
{
|
|
is.putBack(currToken);
|
|
}
|
|
|
|
while (!is.eof() && entry::New(*this, is))
|
|
{}
|
|
|
|
// Remove the FoamFile header entry if it exists
|
|
remove("FoamFile");
|
|
|
|
if (is.bad())
|
|
{
|
|
Info<< "dictionary::read(Istream&, const word&) : "
|
|
<< "Istream not OK after reading dictionary " << name()
|
|
<< endl;
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
bool Foam::dictionary::substituteKeyword(const word& keyword)
|
|
{
|
|
word varName = keyword(1, keyword.size()-1);
|
|
|
|
// lookup the variable name in the given dictionary
|
|
const entry* ePtr = lookupEntryPtr(varName, true, true);
|
|
|
|
// if defined insert its entries into this dictionary
|
|
if (ePtr != NULL)
|
|
{
|
|
const dictionary& addDict = ePtr->dict();
|
|
|
|
forAllConstIter(IDLList<entry>, addDict, iter)
|
|
{
|
|
add(iter());
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
|
|
Foam::dictionary::dictionary
|
|
(
|
|
const dictionary& parentDict,
|
|
Istream& is
|
|
)
|
|
:
|
|
name_(is.name()),
|
|
parent_(parentDict)
|
|
{
|
|
read(is);
|
|
}
|
|
|
|
|
|
Foam::dictionary::dictionary(Istream& is)
|
|
:
|
|
name_(is.name()),
|
|
parent_(dictionary::null)
|
|
{
|
|
// Reset input mode as this is a "top-level" dictionary
|
|
functionEntries::inputModeEntry::clear();
|
|
|
|
read(is);
|
|
}
|
|
|
|
|
|
Foam::autoPtr<Foam::dictionary> Foam::dictionary::New(Istream& is)
|
|
{
|
|
return autoPtr<dictionary>(new dictionary(is));
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
|
|
|
|
Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
|
|
{
|
|
// Reset input mode assuming this is a "top-level" dictionary
|
|
functionEntries::inputModeEntry::clear();
|
|
|
|
dict.clear();
|
|
dict.read(is);
|
|
|
|
return is;
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
|
|
|
|
void Foam::dictionary::write(Ostream& os, bool subDict) const
|
|
{
|
|
if (subDict)
|
|
{
|
|
os << nl << indent << token::BEGIN_BLOCK << incrIndent << nl;
|
|
}
|
|
|
|
forAllConstIter(IDLList<entry>, *this, iter)
|
|
{
|
|
const entry& e = *iter;
|
|
|
|
// Write entry
|
|
os << e;
|
|
|
|
// Add extra new line between entries for "top-level" dictionaries
|
|
if (!subDict && parent() == dictionary::null && e != *last())
|
|
{
|
|
os << nl;
|
|
}
|
|
|
|
// Check stream before going to next entry.
|
|
if (!os.good())
|
|
{
|
|
WarningIn("dictionary::write(Ostream&, bool subDict)")
|
|
<< "Can't write entry " << iter().keyword()
|
|
<< " for dictionary " << name()
|
|
<< endl;
|
|
}
|
|
}
|
|
|
|
if (subDict)
|
|
{
|
|
os << decrIndent << indent << token::END_BLOCK << endl;
|
|
}
|
|
}
|
|
|
|
|
|
Foam::Ostream& Foam::operator<<(Ostream& os, const dictionary& dict)
|
|
{
|
|
dict.write(os, true);
|
|
return os;
|
|
}
|
|
|
|
|
|
// ************************************************************************* //
|