diff --git a/applications/test/dictionary2/Make/files b/applications/test/dictionary2/Make/files
new file mode 100644
index 0000000000..397d8d53cb
--- /dev/null
+++ b/applications/test/dictionary2/Make/files
@@ -0,0 +1,3 @@
+Test-dictionary2.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-dictionary2
diff --git a/applications/test/dictionary2/Make/options b/applications/test/dictionary2/Make/options
new file mode 100644
index 0000000000..41306609f2
--- /dev/null
+++ b/applications/test/dictionary2/Make/options
@@ -0,0 +1 @@
+EXE_INC =
diff --git a/applications/test/dictionary2/Test-dictionary2.C b/applications/test/dictionary2/Test-dictionary2.C
new file mode 100644
index 0000000000..2541f5cba6
--- /dev/null
+++ b/applications/test/dictionary2/Test-dictionary2.C
@@ -0,0 +1,217 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2017 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 3 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, see .
+
+Application
+ Test-dictionary2
+
+Description
+
+ Test dictionary insertion
+
+\*---------------------------------------------------------------------------*/
+
+#include "argList.H"
+#include "IOstreams.H"
+#include "IOobject.H"
+#include "IFstream.H"
+#include "dictionary.H"
+#include "stringOps.H"
+
+using namespace Foam;
+
+void entryInfo(entry* e)
+{
+ if (e)
+ {
+ Info<<"added "
+ << e->keyword() << ": " << typeid(e).name() << nl;
+ }
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Main program:
+
+int main(int argc, char *argv[])
+{
+ argList::noBanner();
+ argList::noParallel();
+
+ argList args(argc, argv);
+
+ dictionary dict1;
+ for (label i=0; i<5; ++i)
+ {
+ dictionary tmpdict;
+
+ {
+ entry* e = dict1.add
+ (
+ Foam::name("entry%d", i),
+ string("entry" + Foam::name(i))
+ );
+ entryInfo(e);
+ }
+
+ {
+ entry* e = tmpdict.add
+ (
+ Foam::name("subentry%d", i),
+ string("subentry" + Foam::name(i))
+ );
+ entryInfo(e);
+ }
+
+ {
+ entry* e = dict1.add
+ (
+ Foam::name("dict%d", i),
+ tmpdict
+ );
+ entryInfo(e);
+ }
+ }
+
+ // Insert new dictionary or merge into existing one
+ for (auto k : { "dict1", "dict10" })
+ {
+ const word key(k);
+ entry* e = dict1.add(key, dictionary(), true);
+
+ if (e && e->isDict())
+ {
+ e->dict().add(word("sub1" + key), 10);
+ e->dict().add(word("sub2" + key), 20);
+ e->dict().add(word("sub3" + key), 30);
+ e->dict().add(word("sub4" + key), 40);
+ e->dict().add(word("sub5" + key), 50);
+ e->dict().add(word("sub6" + key), 60);
+ }
+ }
+
+
+ // overwrite existing
+ {
+ dict1.set("entry3", 1000); // overwrite
+ entry* e = dict1.set(word("dict3"), 1000); // overwrite
+ entryInfo(e);
+ }
+
+ // merge into existing dictionary: returns pointer to existing dict
+ {
+ dictionary tmpdict;
+ tmpdict.add(word("something"), 3.14159);
+
+ entry* e = dict1.add(word("dict4"), tmpdict, true); // merge
+ entryInfo(e);
+
+ if (e) Info<< nl << "=> " << *e << nl;
+
+ tmpdict.clear();
+ tmpdict.add(word("other"), 2.718281);
+
+ dict1.add(word("dict1"), tmpdict, true); // merge
+ }
+
+ Info<< nl << "dictionary" << nl << nl;
+ dict1.write(Info, false);
+
+
+ {
+ dict1.foundCompat
+ (
+ "newEntry", {{"entry1", 1612}, {"entry15", 1606}}
+ );
+ dict1.foundCompat
+ (
+ "newEntry", {{"entry15", 1612}, {"entry2", 1606}}
+ );
+ dict1.foundCompat
+ (
+ "newEntry", {{"entry3", 240}, {"entry2", 1606}}
+ );
+
+ // And some success
+ dict1.foundCompat
+ (
+ "entry4", {{"none", 240}, {"entry2", 1606}}
+ );
+ }
+
+ {
+ label lval = readLabel
+ (
+ dict1.lookupCompat
+ (
+ "entry400", {{"none", 240}, {"entry3", 1606}}
+ )
+ );
+ Info<< "int value: " << lval << nl;
+ }
+
+
+ // Could have different dictionary names and different entries names etc.
+ // Quite ugly!
+ {
+ scalar sval = readScalar
+ (
+ dict1.csearchCompat
+ (
+ "newdictName", {{"dict4", 1706}, {"dict1", 1606}}
+ )
+ .dict()
+ .lookupCompat
+ (
+ "newval", {{"something", 1606}, {"other", 1612}}
+ )
+ );
+
+ Info<< "scalar value: " << sval << nl;
+
+ sval = readScalar
+ (
+ dict1.csearchCompat
+ (
+ "newdictName", {{"dict1", 1606}, {"dict4", 1706}}
+ )
+ .dict()
+ .lookupCompat
+ (
+ "newval", {{"something", 1606}, {"other", 1612}}
+ )
+ );
+
+ Info<< "scalar value = " << sval << nl;
+ }
+
+
+ Info<< nl << "dictionary" << nl << nl;
+ dict1.write(Info, false);
+
+ Info<< "\nDone\n" << endl;
+
+ return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C
index 50a70387ee..b06da4f4a7 100644
--- a/applications/utilities/parallelProcessing/decomposePar/decomposePar.C
+++ b/applications/utilities/parallelProcessing/decomposePar/decomposePar.C
@@ -404,7 +404,11 @@ int main(int argc, char *argv[])
Info<< "Removing " << nProcs
<< " existing processor directories" << endl;
- fileHandler().rmDir(runTime.path()/word("processors"));
+ fileHandler().rmDir
+ (
+ runTime.path()/word("processors"),
+ true // silent (may not have been collated)
+ );
// remove existing processor dirs
// reverse order to avoid gaps if someone interrupts the process
diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
index cfe98bfe64..130b48e5b3 100644
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -203,6 +203,7 @@ dictionary = db/dictionary
$(dictionary)/dictionary.C
$(dictionary)/dictionaryIO.C
$(dictionary)/dictionarySearch.C
+$(dictionary)/dictionaryCompat.C
entry = $(dictionary)/entry
$(entry)/entry.C
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
index 926a3f9016..85e19aed49 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
@@ -737,7 +737,7 @@ protected:
inline Iterator(bool, table_type* tbl);
//- Construct by finding key in hash table
- inline Iterator(table_type* tbl, const Key& key);
+ Iterator(table_type* tbl, const Key& key);
// Protected Member Functions
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H
index 27ac134006..0373ed9c7f 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H
@@ -60,7 +60,7 @@ inline bool Foam::HashTable::empty() const
template
-bool Foam::HashTable::found(const Key& key) const
+inline bool Foam::HashTable::found(const Key& key) const
{
if (size_)
{
diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C
index d5815133b5..2a569fb8af 100644
--- a/src/OpenFOAM/db/dictionary/dictionary.C
+++ b/src/OpenFOAM/db/dictionary/dictionary.C
@@ -532,11 +532,11 @@ Foam::List Foam::dictionary::keys(bool patterns) const
}
-bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
+Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
{
if (!entryPtr)
{
- return false;
+ return nullptr;
}
auto iter = hashedEntries_.find(entryPtr->keyword());
@@ -549,7 +549,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
iter()->dict().merge(entryPtr->dict());
delete entryPtr;
- return true;
+ return iter(); // pointer to existing dictionary
}
@@ -571,7 +571,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
);
}
- return true;
+ return entryPtr; // now an entry in the dictionary
}
@@ -582,7 +582,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
parent_type::remove(entryPtr);
delete entryPtr;
- return false;
+ return nullptr;
}
@@ -600,71 +600,86 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
);
}
- return true;
+ return entryPtr; // now an entry in the dictionary
}
IOWarningInFunction((*this))
- << "attempt to add entry "<< entryPtr->keyword()
+ << "attempt to add entry " << entryPtr->keyword()
<< " which already exists in dictionary " << name()
<< endl;
delete entryPtr;
- return false;
+ return nullptr;
}
-void Foam::dictionary::add(const entry& e, bool mergeEntry)
+Foam::entry* Foam::dictionary::add(const entry& e, bool mergeEntry)
{
- add(e.clone(*this).ptr(), mergeEntry);
+ return add(e.clone(*this).ptr(), mergeEntry);
}
-void Foam::dictionary::add(const keyType& k, const word& v, bool overwrite)
+Foam::entry* Foam::dictionary::add
+(
+ const keyType& k,
+ const word& v,
+ bool overwrite
+)
{
- add(new primitiveEntry(k, token(v)), overwrite);
+ return add(new primitiveEntry(k, token(v)), overwrite);
}
-void Foam::dictionary::add
+Foam::entry* Foam::dictionary::add
(
const keyType& k,
const Foam::string& v,
bool overwrite
)
{
- add(new primitiveEntry(k, token(v)), overwrite);
+ return add(new primitiveEntry(k, token(v)), overwrite);
}
-void Foam::dictionary::add(const keyType& k, const label v, bool overwrite)
+Foam::entry* Foam::dictionary::add
+(
+ const keyType& k,
+ const label v,
+ bool overwrite
+)
{
- add(new primitiveEntry(k, token(v)), overwrite);
+ return add(new primitiveEntry(k, token(v)), overwrite);
}
-void Foam::dictionary::add(const keyType& k, const scalar v, bool overwrite)
+Foam::entry* Foam::dictionary::add
+(
+ const keyType& k,
+ const scalar v,
+ bool overwrite
+)
{
- add(new primitiveEntry(k, token(v)), overwrite);
+ return add(new primitiveEntry(k, token(v)), overwrite);
}
-void Foam::dictionary::add
+Foam::entry* Foam::dictionary::add
(
const keyType& k,
const dictionary& v,
bool mergeEntry
)
{
- add(new dictionaryEntry(k, *this, v), mergeEntry);
+ return add(new dictionaryEntry(k, *this, v), mergeEntry);
}
-void Foam::dictionary::set(entry* entryPtr)
+Foam::entry* Foam::dictionary::set(entry* entryPtr)
{
if (!entryPtr)
{
- return;
+ return nullptr;
}
// Find non-recursive with patterns
@@ -675,19 +690,20 @@ void Foam::dictionary::set(entry* entryPtr)
{
finder.dict().clear();
}
- add(entryPtr, true);
+
+ return add(entryPtr, true);
}
-void Foam::dictionary::set(const entry& e)
+Foam::entry* Foam::dictionary::set(const entry& e)
{
- set(e.clone(*this).ptr());
+ return set(e.clone(*this).ptr());
}
-void Foam::dictionary::set(const keyType& k, const dictionary& v)
+Foam::entry* Foam::dictionary::set(const keyType& k, const dictionary& v)
{
- set(new dictionaryEntry(k, *this, v));
+ return set(new dictionaryEntry(k, *this, v));
}
diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H
index 918ee9b7fe..671aba903d 100644
--- a/src/OpenFOAM/db/dictionary/dictionary.H
+++ b/src/OpenFOAM/db/dictionary/dictionary.H
@@ -684,32 +684,42 @@ public:
//- Add a new entry.
// \param mergeEntry dictionaries are interwoven and primitive
// entries are overwritten
- bool add(entry* entryPtr, bool mergeEntry=false);
+ // \return pointer to inserted entry, or place of merging
+ // or nullptr on failure
+ entry* add(entry* entryPtr, bool mergeEntry=false);
//- Add an entry.
// \param mergeEntry dictionaries are interwoven and primitive
// entries are overwritten
- void add(const entry& e, bool mergeEntry=false);
+ // \return pointer to inserted entry, or place of merging
+ // or nullptr on failure
+ entry* add(const entry& e, bool mergeEntry=false);
//- Add a word entry.
// \param overwrite force overwrite of an existing entry.
- void add(const keyType& k, const word& v, bool overwrite=false);
+ // \return pointer to inserted entry or nullptr on failure
+ entry* add(const keyType& k, const word& v, bool overwrite=false);
//- Add a string entry.
// \param overwrite force overwrite of an existing entry.
- void add(const keyType& k, const string& v, bool overwrite=false);
+ // \return pointer to inserted entry or nullptr on failure
+ entry* add(const keyType& k, const string& v, bool overwrite=false);
//- Add a label entry.
// \param overwrite force overwrite of an existing entry.
- void add(const keyType& k, const label v, bool overwrite=false);
+ // \return pointer to inserted entry or nullptr on failure
+ entry* add(const keyType& k, const label v, bool overwrite=false);
//- Add a scalar entry.
// \param overwrite force overwrite of an existing entry.
- void add(const keyType& k, const scalar v, bool overwrite=false);
+ // \return pointer to inserted entry or nullptr on failure
+ entry* add(const keyType& k, const scalar v, bool overwrite=false);
//- Add a dictionary entry.
// \param mergeEntry merge into an existing sub-dictionary
- void add
+ // \return pointer to inserted entry, or place of merging
+ // or nullptr on failure
+ entry* add
(
const keyType& k,
const dictionary& d,
@@ -718,21 +728,29 @@ public:
//- Add a T entry
// \param overwrite force overwrite of existing entry
+ // \return pointer to inserted entry or nullptr on failure
template
- void add(const keyType& k, const T& v, bool overwrite=false);
+ entry* add(const keyType& k, const T& v, bool overwrite=false);
//- Assign a new entry, overwriting any existing entry.
- void set(entry* entryPtr);
+ //
+ // \return pointer to inserted entry or nullptr on failure
+ entry* set(entry* entryPtr);
//- Assign a new entry, overwriting any existing entry.
- void set(const entry& e);
+ //
+ // \return pointer to inserted entry or nullptr on failure
+ entry* set(const entry& e);
//- Assign a dictionary entry, overwriting any existing entry.
- void set(const keyType& k, const dictionary& v);
+ //
+ // \return pointer to inserted entry or nullptr on failure
+ entry* set(const keyType& k, const dictionary& v);
//- Assign a T entry, overwriting any existing entry.
+ // \return pointer to inserted entry or nullptr on failure
template
- void set(const keyType& k, const T& v);
+ entry* set(const keyType& k, const T& v);
//- Remove an entry specified by keyword
bool remove(const word& keyword);
@@ -890,6 +908,127 @@ public:
dictionary* makeScopedDictPtr(const fileName& dictPath);
+ // Compatibility helpers
+
+ //- Search dictionary for given keyword and any compatibility names
+ // Default search: non-recursive with patterns.
+ //
+ // \param compat list of old compatibility keywords and the last
+ // OpenFOAM version for which they were used.
+ // Old version 1600=OpenFOAM-v3.0, 240=OpenFOAM-2.4.x,
+ // 170=OpenFOAM-1.7.x,...
+ //
+ // \param recursive search parent dictionaries
+ // \param patternMatch use regular expressions
+ const_searcher csearchCompat
+ (
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive = false,
+ bool patternMatch = true
+ ) const;
+
+ //- Search dictionary for given keyword and any compatibility names
+ // Default search: non-recursive with patterns.
+ //
+ // \param compat list of old compatibility keywords and the last
+ // OpenFOAM version for which they were used.
+ // \param recursive search parent dictionaries
+ // \param patternMatch use regular expressions
+ bool foundCompat
+ (
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive = false,
+ bool patternMatch = true
+ ) const;
+
+ //- Find and return an entry pointer if present, or return a nullptr,
+ //- using any compatibility names it needed.
+ //
+ // \param compat list of old compatibility keywords and the last
+ // OpenFOAM version for which they were used.
+ // \param recursive search parent dictionaries
+ // \param patternMatch use regular expressions
+ const entry* lookupEntryPtrCompat
+ (
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive,
+ bool patternMatch
+ ) const;
+
+ //- Find and return an entry if present otherwise error,
+ //- using any compatibility names it needed.
+ //
+ // \param compat list of old compatibility keywords and the last
+ // OpenFOAM version for which they were used.
+ // \param recursive search parent dictionaries
+ // \param patternMatch use regular expressions
+ const entry& lookupEntryCompat
+ (
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive,
+ bool patternMatch
+ ) const;
+
+ //- Find and return an entry data stream,
+ //- using any compatibility names it needed.
+ // Default search: non-recursive with patterns.
+ //
+ // \param compat list of old compatibility keywords and the last
+ // OpenFOAM version for which they were used.
+ // \param recursive search parent dictionaries
+ // \param patternMatch use regular expressions
+ ITstream& lookupCompat
+ (
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive = false,
+ bool patternMatch = true
+ ) const;
+
+ //- Find and return a T, or return the given default value
+ //- using any compatibility names it needed.
+ // Default search: non-recursive with patterns.
+ //
+ // \param compat list of old compatibility keywords and the last
+ // OpenFOAM version for which they were used.
+ // \param recursive search parent dictionaries
+ // \param patternMatch use regular expressions
+ template
+ T lookupOrDefaultCompat
+ (
+ const word& keyword,
+ std::initializer_list> compat,
+ const T& deflt,
+ bool recursive = false,
+ bool patternMatch = true
+ ) const;
+
+ //- Find an entry if present, and assign to T val
+ //- using any compatibility names it needed.
+ // Default search: non-recursive with patterns.
+ //
+ // \param compat list of old compatibility keywords and the last
+ // OpenFOAM version for which they were used.
+ // \param val the value to read
+ // \param recursive search parent dictionaries
+ // \param patternMatch use regular expressions
+ //
+ // \return true if the entry was found.
+ template
+ bool readIfPresentCompat
+ (
+ const word& keyword,
+ std::initializer_list> compat,
+ T& val,
+ bool recursive = false,
+ bool patternMatch = true
+ ) const;
+
+
// Member Operators
//- Find and return an entry data stream (identical to #lookup method).
diff --git a/src/OpenFOAM/db/dictionary/dictionaryCompat.C b/src/OpenFOAM/db/dictionary/dictionaryCompat.C
new file mode 100644
index 0000000000..624231fd14
--- /dev/null
+++ b/src/OpenFOAM/db/dictionary/dictionaryCompat.C
@@ -0,0 +1,162 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2017 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 3 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, see .
+
+\*---------------------------------------------------------------------------*/
+
+#include "dictionary.H"
+
+// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
+
+static void warnAboutAge(const int oldVersion)
+{
+ if (oldVersion < 1000)
+ {
+ // Emit warning
+ std::cerr
+ << " This keyword is considered to be VERY old!\n"
+ << std::endl;
+ }
+#if (OPENFOAM_PLUS > 1600)
+ else if (OPENFOAM_PLUS > oldVersion)
+ {
+ const int months =
+ (
+ // YYMM -> months
+ (12 * (OPENFOAM_PLUS/100) + (OPENFOAM_PLUS % 100))
+ - (12 * (oldVersion/100) + (oldVersion % 100))
+ );
+
+ std::cerr
+ << " This keyword is deemed to be " << months
+ << " months old.\n"
+ << std::endl;
+ }
+#endif
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
+(
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive,
+ bool patternMatch
+) const
+{
+ const_searcher finder(csearch(keyword, recursive,patternMatch));
+
+ if (finder.found())
+ {
+ return finder;
+ }
+
+ for (const std::pair& iter : compat)
+ {
+ finder = csearch(word::validate(iter.first), recursive,patternMatch);
+
+ if (finder.found())
+ {
+ // Emit warning
+ std::cerr
+ << "--> FOAM IOWarning :" << nl
+ << " Found [v" << iter.second << "] '"
+ << iter.first << "' instead of '"
+ << keyword.c_str() << "' in dictionary \""
+ << name().c_str() << "\" "
+ << nl
+ << std::endl;
+
+ warnAboutAge(iter.second);
+
+ break;
+ }
+ }
+
+ return finder;
+}
+
+
+bool Foam::dictionary::foundCompat
+(
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive,
+ bool patternMatch
+) const
+{
+ return csearchCompat(keyword, compat, recursive,patternMatch).found();
+}
+
+
+const Foam::entry* Foam::dictionary::lookupEntryPtrCompat
+(
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive,
+ bool patternMatch
+) const
+{
+ return csearchCompat(keyword, compat, recursive,patternMatch).ptr();
+}
+
+
+const Foam::entry& Foam::dictionary::lookupEntryCompat
+(
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive,
+ bool patternMatch
+) const
+{
+ const const_searcher
+ finder(csearchCompat(keyword, compat, recursive,patternMatch));
+
+ if (!finder.found())
+ {
+ FatalIOErrorInFunction
+ (
+ *this
+ ) << "keyword " << keyword << " is undefined in dictionary "
+ << name()
+ << exit(FatalIOError);
+ }
+
+ return finder.ref();
+}
+
+
+Foam::ITstream& Foam::dictionary::lookupCompat
+(
+ const word& keyword,
+ std::initializer_list> compat,
+ bool recursive,
+ bool patternMatch
+) const
+{
+ return lookupEntryCompat(keyword, compat, recursive,patternMatch).stream();
+}
+
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
index 9e887c08f6..833647b951 100644
--- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
+++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
@@ -35,6 +35,20 @@ Foam::wordList Foam::dictionary::sortedToc(const Compare& comp) const
}
+template
+Foam::entry* Foam::dictionary::add(const keyType& k, const T& v, bool overwrite)
+{
+ return add(new primitiveEntry(k, v), overwrite);
+}
+
+
+template
+Foam::entry* Foam::dictionary::set(const keyType& k, const T& v)
+{
+ return set(new primitiveEntry(k, v));
+}
+
+
template
T Foam::dictionary::lookupType
(
@@ -43,7 +57,7 @@ T Foam::dictionary::lookupType
bool patternMatch
) const
{
- auto finder = csearch(keyword, recursive, patternMatch);
+ const const_searcher finder(csearch(keyword, recursive, patternMatch));
if (!finder.found())
{
@@ -68,7 +82,7 @@ T Foam::dictionary::lookupOrDefault
bool patternMatch
) const
{
- auto finder = csearch(keyword, recursive, patternMatch);
+ const const_searcher finder(csearch(keyword, recursive, patternMatch));
if (finder.found())
{
@@ -96,7 +110,7 @@ T Foam::dictionary::lookupOrAddDefault
bool patternMatch
)
{
- auto finder = csearch(keyword, recursive, patternMatch);
+ const const_searcher finder(csearch(keyword, recursive, patternMatch));
if (finder.found())
{
@@ -125,7 +139,7 @@ bool Foam::dictionary::readIfPresent
bool patternMatch
) const
{
- auto finder = csearch(keyword, recursive, patternMatch);
+ const const_searcher finder(csearch(keyword, recursive, patternMatch));
if (finder.found())
{
@@ -146,16 +160,63 @@ bool Foam::dictionary::readIfPresent
template
-void Foam::dictionary::add(const keyType& k, const T& v, bool overwrite)
+T Foam::dictionary::lookupOrDefaultCompat
+(
+ const word& keyword,
+ std::initializer_list> compat,
+ const T& deflt,
+ bool recursive,
+ bool patternMatch
+) const
{
- add(new primitiveEntry(k, v), overwrite);
+ const const_searcher
+ finder(csearchCompat(keyword, compat, recursive, patternMatch));
+
+ if (finder.found())
+ {
+ return pTraits(finder.ptr()->stream());
+ }
+
+ if (writeOptionalEntries)
+ {
+ IOInfoInFunction(*this)
+ << "Optional entry '" << keyword << "' is not present,"
+ << " returning the default value '" << deflt << "'"
+ << endl;
+ }
+
+ return deflt;
}
template
-void Foam::dictionary::set(const keyType& k, const T& v)
+bool Foam::dictionary::readIfPresentCompat
+(
+ const word& keyword,
+ std::initializer_list> compat,
+ T& val,
+ bool recursive,
+ bool patternMatch
+) const
{
- set(new primitiveEntry(k, v));
+ const const_searcher
+ finder(csearchCompat(keyword, compat, recursive, patternMatch));
+
+ if (finder.found())
+ {
+ finder.ptr()->stream() >> val;
+ return true;
+ }
+
+ if (writeOptionalEntries)
+ {
+ IOInfoInFunction(*this)
+ << "Optional entry '" << keyword << "' is not present,"
+ << " the default value '" << val << "' will be used."
+ << endl;
+ }
+
+ return false;
}
diff --git a/src/OpenFOAM/db/dictionary/functionEntries/README b/src/OpenFOAM/db/dictionary/functionEntries/README
index 0dc051a5d7..c75c21043a 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/README
+++ b/src/OpenFOAM/db/dictionary/functionEntries/README
@@ -14,7 +14,7 @@
#includeIfPresent | dict/primitive | string
#includeFunc | dict | word
| |
- #calcEntry | dict/primitive | string
+ #calc | dict/primitive | string
#codeStream | dict/primitive | dictionary
diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H
index 6e776320d0..f7044aa08e 100644
--- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H
+++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H
@@ -247,7 +247,12 @@ public:
virtual bool rm(const fileName&) const = 0;
//- Remove a dirctory and its contents
- virtual bool rmDir(const fileName&) const = 0;
+ // \param silent do not report missing directory
+ virtual bool rmDir
+ (
+ const fileName& dir,
+ const bool silent = false
+ ) const = 0;
// //- Open a shared library. Return handle to library. Print error
// // message if library cannot be loaded (check = true)
diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
index f436b45776..41c949fe50 100644
--- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C
@@ -630,10 +630,11 @@ bool Foam::fileOperations::masterUncollatedFileOperation::rm
bool Foam::fileOperations::masterUncollatedFileOperation::rmDir
(
- const fileName& dir
+ const fileName& dir,
+ const bool silent
) const
{
- return masterOp(dir, rmDirOp());
+ return masterOp(dir, rmDirOp(silent));
}
diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H
index 5061b1e5cf..b57ced6153 100644
--- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H
+++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.H
@@ -249,10 +249,19 @@ protected:
class rmDirOp
{
+ bool silent_;
public:
+ rmDirOp()
+ :
+ silent_(false)
+ {}
+ rmDirOp(const bool silent)
+ :
+ silent_(silent)
+ {}
bool operator()(const fileName& fName) const
{
- return Foam::rmDir(fName);
+ return Foam::rmDir(fName, silent_);
}
};
@@ -533,7 +542,12 @@ public:
virtual bool rm(const fileName&) const;
//- Remove a dirctory and its contents
- virtual bool rmDir(const fileName&) const;
+ // \param silent do not report missing directory
+ virtual bool rmDir
+ (
+ const fileName& dir,
+ const bool silent = false
+ ) const;
// //- Open a shared library. Return handle to library. Print error
// // message if library cannot be loaded (check = true)
diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C
index e6a509e74c..66e51751fe 100644
--- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C
@@ -292,10 +292,11 @@ bool Foam::fileOperations::uncollatedFileOperation::rm
bool Foam::fileOperations::uncollatedFileOperation::rmDir
(
- const fileName& dir
+ const fileName& dir,
+ const bool silent
) const
{
- return Foam::rmDir(dir);
+ return Foam::rmDir(dir, silent);
}
diff --git a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H
index f2d624a9c9..8e750214e3 100644
--- a/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H
+++ b/src/OpenFOAM/global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.H
@@ -192,7 +192,11 @@ public:
virtual bool rm(const fileName&) const;
//- Remove a dirctory and its contents
- virtual bool rmDir(const fileName&) const;
+ virtual bool rmDir
+ (
+ const fileName& dir,
+ const bool silent = false
+ ) const;
// //- Open a shared library. Return handle to library. Print error
// // message if library cannot be loaded (check = true)