diff --git a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C index 21e8dcfcd6..29816597df 100644 --- a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C +++ b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C @@ -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(localIOdictionary::typeName) = word::null; - localDictPtr = new localIOdictionary ( IOobject @@ -450,10 +447,6 @@ int main(int argc, char *argv[]) false ) ); - - const_cast(localIOdictionary::typeName) = oldTypeName; - const_cast(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); } diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index c54a7bb118..8cd3e37541 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -29,6 +29,8 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +const Foam::word Foam::IOobject::foamFile("FoamFile"); + namespace Foam { defineTypeNameAndDebug(IOobject, 0); diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index 8156acfc62..e5f642f8e8 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -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 diff --git a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C index 5c2b720cac..fd8f0e391d 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectReadHeader.C @@ -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); diff --git a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C index 8c0153e3a1..e1b0bcff06 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C +++ b/src/OpenFOAM/db/IOobject/IOobjectWriteHeader.C @@ -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"; diff --git a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C index e20ce5c4bd..96a39e2dd1 100644 --- a/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C +++ b/src/OpenFOAM/db/IOobjects/decomposedBlockData/decomposedBlockData.C @@ -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); diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index 3bec2cd173..f3cc0ff3be 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -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()) diff --git a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C index c4438a1242..f9e3ee1a6b 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryListEntry/dictionaryListEntryIO.C @@ -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(); } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index 3a64339901..cc74e78729 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -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; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C index fda6c1dfbc..9db2805bae 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEtcEntry/includeEtcEntry.C @@ -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; } diff --git a/src/OpenFOAM/db/regIOobject/regIOobjectRead.C b/src/OpenFOAM/db/regIOobject/regIOobjectRead.C index 52d70d4170..b692ecfb60 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobjectRead.C +++ b/src/OpenFOAM/db/regIOobject/regIOobjectRead.C @@ -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(type()) = headerClassName(); + } + else + { + FatalIOErrorInFunction(isPtr_()) + << "unexpected class name " << headerClassName() + << " expected " << expectName << endl + << " while reading object " << name() + << exit(FatalIOError); + } } } diff --git a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C index 18539d630e..c12ff643c8 100644 --- a/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/collatedFileOperation/collatedFileOperation.C @@ -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