mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: allow retention of 'FoamFile' when reading dictionaries
- used in expandDictionary
This commit is contained in:
@ -42,6 +42,12 @@ using namespace Foam;
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
argList::addNote
|
||||||
|
(
|
||||||
|
"Read the specified dictionary file, expand the macros etc. and write\n"
|
||||||
|
"the resulting dictionary to standard output."
|
||||||
|
);
|
||||||
|
|
||||||
argList::noBanner();
|
argList::noBanner();
|
||||||
argList::noParallel();
|
argList::noParallel();
|
||||||
argList::validArgs.append("inputDict");
|
argList::validArgs.append("inputDict");
|
||||||
@ -49,9 +55,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
const string dictName = args[1];
|
const string dictName = args[1];
|
||||||
|
|
||||||
Info<<"//\n// expansion of dictionary " << dictName << "\n//\n";
|
IOobject::writeBanner(Info)
|
||||||
|
<<"//\n// " << dictName << "\n//\n";
|
||||||
|
|
||||||
dictionary(IFstream(dictName)()).write(Info, false);
|
dictionary(IFstream(dictName)(), true).write(Info, false);
|
||||||
|
|
||||||
IOobject::writeDivider(Info);
|
IOobject::writeDivider(Info);
|
||||||
|
|
||||||
|
|||||||
@ -191,10 +191,14 @@ public:
|
|||||||
Istream&
|
Istream&
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct top-level dictionary from Istream, reading entries
|
//- Construct top-level dictionary from Istream,
|
||||||
// until EOF
|
// reading entries until EOF
|
||||||
dictionary(Istream&);
|
dictionary(Istream&);
|
||||||
|
|
||||||
|
//- Construct top-level dictionary from Istream,
|
||||||
|
// reading entries until EOF, optionally keeping the header
|
||||||
|
dictionary(Istream&, const bool keepHeader);
|
||||||
|
|
||||||
//- Construct as copy given the parent dictionary
|
//- Construct as copy given the parent dictionary
|
||||||
dictionary(const dictionary& parentDict, const dictionary&);
|
dictionary(const dictionary& parentDict, const dictionary&);
|
||||||
|
|
||||||
@ -441,6 +445,9 @@ public:
|
|||||||
//- Read dictionary from Istream
|
//- Read dictionary from Istream
|
||||||
bool read(Istream&);
|
bool read(Istream&);
|
||||||
|
|
||||||
|
//- Read dictionary from Istream, optionally keeping the header
|
||||||
|
bool read(Istream&, const bool keepHeader);
|
||||||
|
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
|
|
||||||
|
|||||||
@ -28,68 +28,6 @@ License
|
|||||||
#include "inputModeEntry.H"
|
#include "inputModeEntry.H"
|
||||||
#include "regExp.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 * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::dictionary::dictionary
|
Foam::dictionary::dictionary
|
||||||
@ -118,12 +56,97 @@ Foam::dictionary::dictionary(Istream& is)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::dictionary::dictionary(Istream& is, const bool keepHeader)
|
||||||
|
:
|
||||||
|
dictionaryName(is.name()),
|
||||||
|
parent_(dictionary::null)
|
||||||
|
{
|
||||||
|
// Reset input mode as this is a "top-level" dictionary
|
||||||
|
functionEntries::inputModeEntry::clear();
|
||||||
|
|
||||||
|
read(is, keepHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::autoPtr<Foam::dictionary> Foam::dictionary::New(Istream& is)
|
Foam::autoPtr<Foam::dictionary> Foam::dictionary::New(Istream& is)
|
||||||
{
|
{
|
||||||
return autoPtr<dictionary>(new dictionary(is));
|
return autoPtr<dictionary>(new dictionary(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::dictionary::read(Istream& is, const bool keepHeader)
|
||||||
|
{
|
||||||
|
if (!is.good())
|
||||||
|
{
|
||||||
|
FatalIOErrorIn("dictionary::read(Istream&, bool)", 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))
|
||||||
|
{}
|
||||||
|
|
||||||
|
// normally remove the FoamFile header entry if it exists
|
||||||
|
if (!keepHeader)
|
||||||
|
{
|
||||||
|
remove("FoamFile");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is.bad())
|
||||||
|
{
|
||||||
|
Info<< "dictionary::read(Istream&, bool) : "
|
||||||
|
<< "Istream not OK after reading dictionary " << name()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::dictionary::read(Istream& is)
|
||||||
|
{
|
||||||
|
return this->read(is, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
|
Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict)
|
||||||
|
|||||||
Reference in New Issue
Block a user