diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict index 809625ee186ded41224198083d67df7c7785d1f1..7709155fecca5232fff4fdf14fce4ddfddbbbb00 100644 --- a/applications/test/dictionary/testDict +++ b/applications/test/dictionary/testDict @@ -1,23 +1,28 @@ -/*-------------------------------*- C++ -*---------------------------------*\ -| ========= | -| \\ / OpenFOAM | -| \\ / | -| \\ / The Open Source CFD Toolbox | -| \\/ http://www.OpenFOAM.org | -\*-------------------------------------------------------------------------*/ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: Any | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ FoamFile { - version 2.0; - format ascii; - class dictionary; - object testDict; + version 2.0; + format ascii; + class dictionary; + object testDict; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #inputMode merge -dimensions [ 0 2 -2 0 0 0 0 ]; internalField uniform 1; +// use 'protect' to supply defaults +#inputMode protect +internalField uniform 10; +dimensions [ 0 2 -2 0 0 0 0 ]; +#inputMode merge + active { type turbulentIntensityKineticEnergyInlet; @@ -31,6 +36,7 @@ inactive type zeroGradient; } + boundaryField { Default_Boundary_Region @@ -101,4 +107,4 @@ baz // this should work too #remove ( bar baz ) -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/test/dictionary/testDict2 b/applications/test/dictionary/testDict2 index 6c55ab384c22c0ce1c1e324306a68594e2afca1e..124f5b0aee23863884d6af7d866dbcb4f86e726a 100644 --- a/applications/test/dictionary/testDict2 +++ b/applications/test/dictionary/testDict2 @@ -1,19 +1,18 @@ -/*-------------------------------*- C++ -*---------------------------------*\ -| ========= | -| \\ / OpenFOAM | -| \\ / | -| \\ / The Open Source CFD Toolbox | -| \\/ http://www.OpenFOAM.org | -\*-------------------------------------------------------------------------*/ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: Any | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ FoamFile { - version 2.0; - format ascii; - class dictionary; - object testDict; + version 2.0; + format ascii; + class dictionary; + object testDict; } - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // boundaryField { @@ -27,4 +26,4 @@ boundaryField } #inputMode overwrite -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index fd89f0f608fec6e5e355735fad46e7785dcf5e86..5e76ecd612739eb6220803dd635697ea9813c2ae 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -53,7 +53,8 @@ bool Foam::dictionary::findInPatterns { if ( - patternMatch ? reLink()->match(Keyword) + patternMatch + ? reLink()->match(Keyword) : wcLink()->keyword() == Keyword ) { @@ -83,7 +84,8 @@ bool Foam::dictionary::findInPatterns { if ( - patternMatch ? reLink()->match(Keyword) + patternMatch + ? reLink()->match(Keyword) : wcLink()->keyword() == Keyword ) { diff --git a/src/OpenFOAM/db/dictionary/entry/entryIO.C b/src/OpenFOAM/db/dictionary/entry/entryIO.C index 76d068ea283602b6e4fab2a3eae4953b4ef658cc..509c892e1d99cac863e2a6c6cd29183a2ed98c29 100644 --- a/src/OpenFOAM/db/dictionary/entry/entryIO.C +++ b/src/OpenFOAM/db/dictionary/entry/entryIO.C @@ -73,7 +73,7 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is) { cerr<< "--> FOAM Warning : " << std::endl << " From function " - << "entry::getKeyword(keyType& keyword, Istream& is)" << std::endl + << "entry::getKeyword(keyType&, Istream&)" << std::endl << " in file " << __FILE__ << " at line " << __LINE__ << std::endl << " Reading " << is.name().c_str() << std::endl @@ -88,7 +88,7 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is) bool Foam::entry::New(dictionary& parentDict, Istream& is) { - is.fatalCheck("entry::New(const dictionary& parentDict, Istream& is)"); + is.fatalCheck("entry::New(const dictionary& parentDict, Istream&)"); keyType keyword; @@ -97,9 +97,9 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is) { return false; } - else // Keyword starts entry ... + else // Keyword starts entry ... { - if (keyword[0] == '#') // ... Function entry + if (keyword[0] == '#') // ... Function entry { word functionName = keyword(1, keyword.size()-1); return functionEntry::execute(functionName, parentDict, is); @@ -128,9 +128,14 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is) false, false ); + if (existingPtr) { - if (functionEntries::inputModeEntry::overwrite()) + if (functionEntries::inputModeEntry::merge()) + { + mergeEntry = true; + } + else if (functionEntries::inputModeEntry::overwrite()) { // clear dictionary so merge acts like overwrite if (existingPtr->isDict()) @@ -139,9 +144,30 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is) } mergeEntry = true; } - else if (functionEntries::inputModeEntry::merge()) + else if (functionEntries::inputModeEntry::protect()) { - mergeEntry = true; + // read and discard the entry + if (nextToken == token::BEGIN_BLOCK) + { + dictionaryEntry dummy(keyword, parentDict, is); + } + else + { + primitiveEntry dummy(keyword, parentDict, is); + } + return true; + } + else if (functionEntries::inputModeEntry::error()) + { + FatalIOErrorIn + ( + "entry::New(const dictionary& parentDict, Istream&)", + is + ) + << "ERROR! duplicate entry: " << keyword + << exit(FatalIOError); + + return false; } } @@ -168,7 +194,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is) Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is) { - is.fatalCheck("entry::New(Istream& is)"); + is.fatalCheck("entry::New(Istream&)"); keyType keyword; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C index e36de4108c2c0062c1f4d88a21912ec831ee3db9..e386a30f20202b9ec2b43691f941ca1ca6759f4b 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C @@ -58,7 +58,7 @@ bool Foam::functionEntry::execute is.fatalCheck ( "functionEntry::execute" - "(const word& functionName, dictionary& parentDict, Istream& is)" + "(const word& functionName, dictionary& parentDict, Istream&)" ); if (!executedictionaryIstreamMemberFunctionTablePtr_) diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index 7879369017deaa7cf3b354128025d3c3ed7bee71..2d49418fae22647e7c41ffd09072e043541d528b 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -131,7 +131,7 @@ bool Foam::functionEntries::includeEntry::execute FatalIOErrorIn ( "functionEntries::includeEntry::includeEntry" - "(dictionary& parentDict, primitiveEntry& entry, Istream&)", + "(dictionary& parentDict, primitiveEntry&, Istream&)", is ) << "Cannot open include file " << ifs.name() << " while reading dictionary " << parentDict.name() diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H index b260e3f36c624c0bb5eb410203c29306009b3850..e4255827bf60572cdf5d43f8b0cf5da577d79fe8 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H @@ -34,8 +34,8 @@ Description #include "includeFile" @endverbatim - The usual expansion of environment variables and other constructs (eg, - the @c ~OpenFOAM/ expansion) is retained. + The usual expansion of environment variables and other constructs + (eg, the @c ~OpenFOAM/ expansion) is retained. See Also fileName, string::expand() diff --git a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C index f711da80aa89bfb4d46dfedd9c764c658f018f15..986780fdeeef4d1cfb216c9e39e7c800c6a8935f 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.C @@ -72,6 +72,14 @@ void Foam::functionEntries::inputModeEntry::setMode(Istream& is) { mode_ = OVERWRITE; } + else if (mode == "protect") + { + mode_ = PROTECT; + } + else if (mode == "warn") + { + mode_ = WARN; + } else if (mode == "error") { mode_ = ERROR; @@ -79,7 +87,8 @@ void Foam::functionEntries::inputModeEntry::setMode(Istream& is) else { WarningIn("Foam::functionEntries::inputModeEntry::setMode(Istream&)") - << "unsupported input mode " << mode + << "unsupported input mode '" << mode + << "' ... defaulting to 'merge'" << endl; } } @@ -116,4 +125,15 @@ bool Foam::functionEntries::inputModeEntry::overwrite() } +bool Foam::functionEntries::inputModeEntry::protect() +{ + return mode_ == PROTECT; +} + +bool Foam::functionEntries::inputModeEntry::error() +{ + return mode_ == ERROR; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H index 9ecb558da9ad81a634cf260c18d820c0d9f35c12..da3bd7a0676ae53a969fdaa7f09e0a696916e363 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/inputModeEntry/inputModeEntry.H @@ -37,8 +37,10 @@ Description The possible input modes: @param merge merge sub-dictionaries when possible @param overwrite keep last entry and silently remove previous ones - @param error flag duplicate entry as an error - @param default currently the same as merge + @param protect keep initial entry and silently ignore subsequent ones + @param warn keep initial entry and warn about subsequent ones + @param error issue a FatalError for duplicate entries + @param default currently identical to merge SourceFiles inputModeEntry.C @@ -65,15 +67,17 @@ class inputModeEntry : public functionEntry { - //- input mode options + //- The input mode options enum inputMode { - ERROR, MERGE, - OVERWRITE + OVERWRITE, + PROTECT, + WARN, + ERROR }; - //- current input mode + //- The current input mode static inputMode mode_; @@ -100,7 +104,7 @@ public: //- Execute the functionEntry in a sub-dict context static bool execute(dictionary& parentDict, Istream&); - //- Reset the inputMode to %default + //- Reset the inputMode to %default (ie, %merge) static void clear(); //- Return true if the inputMode is %merge @@ -109,6 +113,12 @@ public: //- Return true if the inputMode is %overwrite static bool overwrite(); + //- Return true if the inputMode is %protect + static bool protect(); + + //- Return true if the inputMode is %error + static bool error(); + }; diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index adee46a6366e19a2a59b6917d5cc0043ca1c3af5..896dee8d1450fe511512ee2ffebdc168d2c54089 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -83,7 +83,7 @@ bool Foam::primitiveEntry::expandVariable // lookup the variable name in the given dictionary.... const entry* ePtr = dict.lookupEntryPtr(varName, true, true); - // ...if defined insert its tokens into this + // ...if defined insert its tokens into this if (ePtr != NULL) { append(ePtr->stream()); @@ -91,7 +91,7 @@ bool Foam::primitiveEntry::expandVariable } else { - // if not in the dictionary see if it is an environment + // if not in the dictionary see if it is an environment // variable string enVarString = getEnv(varName); @@ -123,7 +123,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) { is.fatalCheck ( - "primitiveEntry::readData(const dictionary& dict, Istream& is)" + "primitiveEntry::readData(const dictionary&, Istream&)" ); label blockCount = 0; @@ -177,7 +177,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is) is.fatalCheck ( - "primitiveEntry::readData(const dictionary& dict, Istream& is)" + "primitiveEntry::readData(const dictionary&, Istream&)" ); if (currToken.good()) @@ -205,7 +205,7 @@ void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is) { FatalIOErrorIn ( - "primitiveEntry::readEntry(const dictionary& dict,Istream& is)", + "primitiveEntry::readEntry(const dictionary&, Istream&)", is ) << "ill defined primitiveEntry starting at keyword '" << keyword() << '\'' @@ -266,7 +266,7 @@ void Foam::primitiveEntry::write(Ostream& os) const os << token::SPACE; } } - + os << token::END_STATEMENT << endl; } @@ -297,7 +297,7 @@ Foam::Ostream& Foam::operator<< { os << " ..."; } - + os << endl; return os;