mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: use getOrDefault instead of lookupOrDefault
- now mark methods with strict deprecation, to make it easier to find their use but without adding extra compilation noise for others ENH: minor update for Enum methods and iterator - add warnOnly (failsafe) option for readEntry and getOrDefault - add good() method to Enum iterator (simliar to HashTable) - replace unused/fragile Enum find() methods with iterator return that can be used more generally
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -110,7 +110,7 @@ int main(int argc, char *argv[])
|
||||
<< " values: " << flatOutput(otherNames2.values())
|
||||
<< nl << nl;
|
||||
|
||||
otherNames2.append
|
||||
otherNames2.push_back
|
||||
({
|
||||
{ 15, "fifteen"},
|
||||
{ 16, "sixteen"}
|
||||
@ -138,7 +138,7 @@ int main(int argc, char *argv[])
|
||||
Info<< nl;
|
||||
|
||||
otherNames2.clear();
|
||||
otherNames2.append
|
||||
otherNames2.push_back
|
||||
({
|
||||
{ 1, "one"},
|
||||
{ 2, "two"}
|
||||
@ -149,6 +149,18 @@ int main(int argc, char *argv[])
|
||||
<< otherNames2.values() << nl
|
||||
<< nl;
|
||||
|
||||
for (const auto& k : {"one", "two", "three", "four" })
|
||||
{
|
||||
const auto iter = otherNames2.find(k);
|
||||
|
||||
Info<< "find(" << k << ") good:" << iter.good();
|
||||
if (iter.good())
|
||||
{
|
||||
Info<< " value:" << int(iter.val());
|
||||
}
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
|
||||
dictionary testDict;
|
||||
testDict.add("lookup1", "c");
|
||||
@ -162,10 +174,10 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
Info<< "dict: " << testDict << endl;
|
||||
|
||||
Info<< "lookupOrDefault(notFound) = "
|
||||
Info<< "getOrDefault(notFound) = "
|
||||
<< int
|
||||
(
|
||||
testing::option1Names.lookupOrDefault
|
||||
testing::option1Names.getOrDefault
|
||||
(
|
||||
"notFound",
|
||||
testDict,
|
||||
@ -174,10 +186,10 @@ int main(int argc, char *argv[])
|
||||
)
|
||||
<< nl;
|
||||
|
||||
Info<< "lookupOrDefault(lookup1) = "
|
||||
Info<< "getOrDefault(lookup1) = "
|
||||
<< int
|
||||
(
|
||||
testing::option1Names.lookupOrDefault
|
||||
testing::option1Names.getOrDefault
|
||||
(
|
||||
"lookup1",
|
||||
testDict,
|
||||
@ -186,10 +198,10 @@ int main(int argc, char *argv[])
|
||||
)
|
||||
<< nl;
|
||||
|
||||
Info<< "lookupOrDefault(lookup1) = "
|
||||
Info<< "getOrDefault(lookup1) = "
|
||||
<< int
|
||||
(
|
||||
testing::option2Names.lookupOrDefault
|
||||
testing::option2Names.getOrDefault
|
||||
(
|
||||
"lookup1",
|
||||
testDict,
|
||||
|
||||
@ -136,13 +136,13 @@ int main(int argc, char *argv[])
|
||||
Info<< "test2 : " << dimensionedScalar("test2", dimless, 20, dict) << nl;
|
||||
Info<< "test2a : " << dimensionedScalar("test2a", dimless, 20, dict) << nl;
|
||||
Info<< "test3 : "
|
||||
<< dimensionedScalar::lookupOrDefault("test3", dict, 30) << nl;
|
||||
<< dimensionedScalar::getOrDefault("test3", dict, 30) << nl;
|
||||
|
||||
Info<< "test4 : "
|
||||
<< dimensionedScalar::lookupOrAddToDict("test4", dict, 40) << nl;
|
||||
<< dimensionedScalar::getOrAddToDict("test4", dict, 40) << nl;
|
||||
|
||||
Info<< "test5 : "
|
||||
<< dimensionedScalar::lookupOrAddToDict("test5", dict, -50) << nl;
|
||||
<< dimensionedScalar::getOrAddToDict("test5", dict, -50) << nl;
|
||||
|
||||
// Deprecated
|
||||
Info<< "Deprecated constructors" << nl;
|
||||
|
||||
Reference in New Issue
Block a user