foamDictionary: Simplified the handling of the dictionary file type
Also added the header separator comment for serial operation.
This commit is contained in:
@ -174,7 +174,7 @@ IOstream::streamFormat readDict(dictionary& dict, const fileName& dictFileName)
|
||||
|
||||
// If the first entry is the "FoamFile" header dictionary
|
||||
// read and set the stream format
|
||||
if (firstEntry->isDict() && firstEntry->keyword() == "FoamFile")
|
||||
if (firstEntry->isDict() && firstEntry->keyword() == IOobject::foamFile)
|
||||
{
|
||||
dictFormat = IOstream::formatEnum(firstEntry->dict().lookup("format"));
|
||||
dictFile().format(dictFormat);
|
||||
@ -184,7 +184,7 @@ IOstream::streamFormat readDict(dictionary& dict, const fileName& dictFileName)
|
||||
dict.add(firstEntry);
|
||||
|
||||
// Read and add the rest of the dictionary entries
|
||||
// preserving the "FoamFile" header dictionary if present
|
||||
// preserving the IOobject::foamFile header dictionary if present
|
||||
dict.read(dictFile(), true);
|
||||
|
||||
return dictFormat;
|
||||
@ -435,9 +435,6 @@ int main(int argc, char *argv[])
|
||||
runTimePtr->setTime(time, 0);
|
||||
}
|
||||
|
||||
const word oldTypeName = localIOdictionary::typeName;
|
||||
const_cast<word&>(localIOdictionary::typeName) = word::null;
|
||||
|
||||
localDictPtr = new localIOdictionary
|
||||
(
|
||||
IOobject
|
||||
@ -450,10 +447,6 @@ int main(int argc, char *argv[])
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
const_cast<word&>(localIOdictionary::typeName) = oldTypeName;
|
||||
const_cast<word&>(localDictPtr->type()) =
|
||||
localDictPtr->headerClassName();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -688,6 +681,13 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
OFstream os(dictPath, dictFormat);
|
||||
IOobject::writeBanner(os);
|
||||
if (dictPtr->found(IOobject::foamFile))
|
||||
{
|
||||
os << IOobject::foamFile;
|
||||
dictPtr->subDict(IOobject::foamFile).write(os);
|
||||
dictPtr->remove(IOobject::foamFile);
|
||||
IOobject::writeDivider(os) << nl;
|
||||
}
|
||||
dictPtr->write(os, false);
|
||||
IOobject::writeEndDivider(os);
|
||||
}
|
||||
|
||||
@ -29,6 +29,8 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::word Foam::IOobject::foamFile("FoamFile");
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(IOobject, 0);
|
||||
|
||||
@ -95,6 +95,10 @@ class IOobject
|
||||
|
||||
public:
|
||||
|
||||
//- Keyword for the FoamFile header sub-dictionary
|
||||
static const word foamFile;
|
||||
|
||||
|
||||
// Public data types
|
||||
|
||||
//- Enumeration defining the valid states of an IOobject
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -62,7 +62,7 @@ bool Foam::IOobject::readHeader(Istream& is)
|
||||
(
|
||||
is.good()
|
||||
&& firstToken.isWord()
|
||||
&& firstToken.wordToken() == "FoamFile"
|
||||
&& firstToken.wordToken() == foamFile
|
||||
)
|
||||
{
|
||||
dictionary headerDict(is);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -44,7 +44,7 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
|
||||
}
|
||||
|
||||
writeBanner(os)
|
||||
<< "FoamFile\n{\n"
|
||||
<< foamFile << "\n{\n"
|
||||
<< " version " << os.version() << ";\n"
|
||||
<< " format " << os.format() << ";\n"
|
||||
<< " class " << type << ";\n";
|
||||
|
||||
@ -196,7 +196,7 @@ void Foam::decomposedBlockData::writeHeader
|
||||
)
|
||||
{
|
||||
IOobject::writeBanner(os)
|
||||
<< "FoamFile\n{\n"
|
||||
<< IOobject::foamFile << "\n{\n"
|
||||
<< " version " << version << ";\n"
|
||||
<< " format " << format << ";\n"
|
||||
<< " class " << type << ";\n";
|
||||
@ -1076,7 +1076,7 @@ Foam::label Foam::decomposedBlockData::numBlocks(const fileName& fName)
|
||||
(
|
||||
is.good()
|
||||
&& firstToken.isWord()
|
||||
&& firstToken.wordToken() == "FoamFile"
|
||||
&& firstToken.wordToken() == IOobject::foamFile
|
||||
)
|
||||
{
|
||||
dictionary headerDict(is);
|
||||
|
||||
@ -24,6 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "IOobject.H"
|
||||
#include "inputSyntaxEntry.H"
|
||||
#include "inputModeEntry.H"
|
||||
#include "regExp.H"
|
||||
@ -113,7 +114,7 @@ bool Foam::dictionary::read(Istream& is, const bool keepHeader)
|
||||
// normally remove the FoamFile header entry if it exists
|
||||
if (!keepHeader)
|
||||
{
|
||||
remove("FoamFile");
|
||||
remove(IOobject::foamFile);
|
||||
}
|
||||
|
||||
if (is.bad())
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -25,13 +25,13 @@ License
|
||||
|
||||
#include "dictionaryListEntry.H"
|
||||
#include "keyType.H"
|
||||
#include "IOstreams.H"
|
||||
#include "IOobject.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::dictionaryListEntry::realSize(const dictionary& dict)
|
||||
{
|
||||
if (dict.size() < 1 || dict.first()->keyword() != "FoamFile")
|
||||
if (dict.size() < 1 || dict.first()->keyword() != IOobject::foamFile)
|
||||
{
|
||||
return dict.size();
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -28,7 +28,7 @@ License
|
||||
#include "IFstream.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
#include "stringOps.H"
|
||||
#include "IOstreams.H"
|
||||
#include "IOobject.H"
|
||||
#include "fileOperation.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -143,9 +143,9 @@ bool Foam::functionEntries::includeEntry::execute
|
||||
|
||||
// Cache the FoamFile entry if present
|
||||
dictionary foamFileDict;
|
||||
if (parentDict.found("FoamFile"))
|
||||
if (parentDict.found(IOobject::foamFile))
|
||||
{
|
||||
foamFileDict = parentDict.subDict("FoamFile");
|
||||
foamFileDict = parentDict.subDict(IOobject::foamFile);
|
||||
}
|
||||
|
||||
// Read and clear the FoamFile entry
|
||||
@ -156,7 +156,7 @@ bool Foam::functionEntries::includeEntry::execute
|
||||
{
|
||||
dictionary parentDictTmp(parentDict);
|
||||
parentDict.clear();
|
||||
parentDict.add("FoamFile", foamFileDict);
|
||||
parentDict.add(IOobject::foamFile, foamFileDict);
|
||||
parentDict += parentDictTmp;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2015-2018 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2015-2019 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -27,7 +27,7 @@ License
|
||||
#include "etcFiles.H"
|
||||
#include "stringOps.H"
|
||||
#include "addToMemberFunctionSelectionTable.H"
|
||||
#include "IOstreams.H"
|
||||
#include "IOobject.H"
|
||||
#include "fileOperation.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -119,9 +119,9 @@ bool Foam::functionEntries::includeEtcEntry::execute
|
||||
|
||||
// Cache the FoamFile entry if present
|
||||
dictionary foamFileDict;
|
||||
if (parentDict.found("FoamFile"))
|
||||
if (parentDict.found(IOobject::foamFile))
|
||||
{
|
||||
foamFileDict = parentDict.subDict("FoamFile");
|
||||
foamFileDict = parentDict.subDict(IOobject::foamFile);
|
||||
}
|
||||
|
||||
// Read and clear the FoamFile entry
|
||||
@ -132,7 +132,7 @@ bool Foam::functionEntries::includeEtcEntry::execute
|
||||
{
|
||||
dictionary parentDictTmp(parentDict);
|
||||
parentDict.clear();
|
||||
parentDict.add("FoamFile", foamFileDict);
|
||||
parentDict.add(IOobject::foamFile, foamFileDict);
|
||||
parentDict += parentDictTmp;
|
||||
}
|
||||
|
||||
|
||||
@ -153,21 +153,27 @@ Foam::Istream& Foam::regIOobject::readStream
|
||||
readStream(read);
|
||||
|
||||
// Check the className of the regIOobject
|
||||
// dictionary is an allowable name in case the actual class
|
||||
// instantiated is a dictionary
|
||||
// dictionary is an allowable name so that any file can be processed
|
||||
// as raw dictionary and the original type preserved
|
||||
if
|
||||
(
|
||||
read
|
||||
&& expectName.size()
|
||||
&& headerClassName() != expectName
|
||||
&& headerClassName() != "dictionary"
|
||||
)
|
||||
{
|
||||
FatalIOErrorInFunction(isPtr_())
|
||||
<< "unexpected class name " << headerClassName()
|
||||
<< " expected " << expectName << endl
|
||||
<< " while reading object " << name()
|
||||
<< exit(FatalIOError);
|
||||
if (expectName == dictionary::typeName)
|
||||
{
|
||||
const_cast<word&>(type()) = headerClassName();
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorInFunction(isPtr_())
|
||||
<< "unexpected class name " << headerClassName()
|
||||
<< " expected " << expectName << endl
|
||||
<< " while reading object " << name()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -215,7 +215,7 @@ bool Foam::fileOperations::collatedFileOperation::appendObject
|
||||
if (isMaster)
|
||||
{
|
||||
IOobject::writeBanner(os)
|
||||
<< "FoamFile\n{\n"
|
||||
<< IOobject::foamFile << "\n{\n"
|
||||
<< " version " << os.version() << ";\n"
|
||||
<< " format " << os.format() << ";\n"
|
||||
<< " class " << decomposedBlockData::typeName
|
||||
|
||||
Reference in New Issue
Block a user