From ccc751e55d5d60a90229a9d71446d276a7f5d932 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Fri, 9 Jul 2021 20:30:26 +0200 Subject: [PATCH] ENH: centralize checks for keyword age into Foam::error STYLE: additional note about include/exclude HashTable.C --- .../HashTables/HashTable/HashTable.H | 2 +- src/OpenFOAM/db/IOstreams/IOstreams/Istream.H | 1 + src/OpenFOAM/db/dictionary/dictionaryCompat.C | 33 +++--------- src/OpenFOAM/db/error/error.C | 50 ++++++++++++------- src/OpenFOAM/db/error/error.H | 8 ++- .../functionObjects/timeControl/timeControl.C | 12 ++--- src/OpenFOAM/global/argList/argList.C | 37 ++++---------- 7 files changed, 65 insertions(+), 78 deletions(-) diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index b3cd98f1904..7296b8c18df 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -943,7 +943,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifndef NoHashTableC +#ifndef NoHashTableC // Excluded from token.H #ifdef NoRepository #include "HashTable.C" #endif diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H index cb5b350be25..08c49464a8d 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Istream.H @@ -272,6 +272,7 @@ namespace Detail // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Previously excluded (via token.H) #ifdef NoRepository #include "HashTable.C" #endif diff --git a/src/OpenFOAM/db/dictionary/dictionaryCompat.C b/src/OpenFOAM/db/dictionary/dictionaryCompat.C index 5df4d1c4b93..c4668e57bf9 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryCompat.C +++ b/src/OpenFOAM/db/dictionary/dictionaryCompat.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,23 +28,6 @@ License #include "dictionary.H" #include "Pstream.H" -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // - -namespace -{ - -// Should issue warning if there is +ve versioning (+ve version number) -// and the this version number is older than the current OpenFOAM version -// as conveyed by the OPENFOAM compiler define. - -static inline constexpr bool shouldWarnVersion(const int version) -{ - return (version > 0 && version < OPENFOAM); -} - -} // End anonymous namespace - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::dictionary::const_searcher Foam::dictionary::csearchCompat @@ -61,9 +44,9 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat return finder; } - for (const std::pair<const char*,int>& iter : compat) + for (const std::pair<const char*,int>& alt : compat) { - finder = csearch(word::validate(iter.first), matchOpt); + finder = csearch(word::validate(alt.first), matchOpt); if (finder.good()) { @@ -71,20 +54,20 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat // Pstream::master() when Pstream has not yet been initialized if ( - shouldWarnVersion(iter.second) - && (Pstream::parRun() ? Pstream::master() : true) + (Pstream::parRun() ? Pstream::master() : true) + && error::warnAboutAge(alt.second) ) { std::cerr << "--> FOAM IOWarning :" << nl - << " Found [v" << iter.second << "] '" - << iter.first << "' entry instead of '" + << " Found [v" << alt.second << "] '" + << alt.first << "' entry instead of '" << keyword.c_str() << "' in dictionary \"" << name().c_str() << "\" " << nl << std::endl; - error::warnAboutAge("keyword", iter.second); + error::warnAboutAge("keyword", alt.second); } break; diff --git a/src/OpenFOAM/db/error/error.C b/src/OpenFOAM/db/error/error.C index 46ada0c4681..09920fe1298 100644 --- a/src/OpenFOAM/db/error/error.C +++ b/src/OpenFOAM/db/error/error.C @@ -38,21 +38,23 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -void Foam::error::warnAboutAge(const char* what, const int version) +bool Foam::error::warnAboutAge(const int version) noexcept { - if (version <= 0) - { - // No warning for 0 (unversioned) or -ve values (silent versioning) - } - else if (version < 1000) - { - // Warning for things that predate the YYMM versioning - // (eg, 240 for version 2.4) - std::cerr - << " This " << what << " is very old.\n" - << std::endl; - } - else if (version < foamVersion::api) + // No warning for 0 (unversioned) or -ve values (silent versioning) + return ((version > 0) && (version < foamVersion::api)); +} + + +bool Foam::error::warnAboutAge(const char* what, const int version) +{ + // No warning for 0 (unversioned) or -ve values (silent versioning) + const bool old = ((version > 0) && (version < foamVersion::api)); + + // Note: + // No warning for (version >= foamVersion::api), which + // can be used to denote future expiry dates of transition features. + + if (old) { const int months = ( @@ -61,12 +63,22 @@ void Foam::error::warnAboutAge(const char* what, const int version) - (12 * (version/100) + (version % 100)) ); - std::cerr - << " This " << what << " is " << months << " months old.\n" - << std::endl; + if (version < 1000) + { + // For things that predate YYMM versioning (eg, 240 for version 2.4) + std::cerr + << " This " << what << " is very old.\n" + << std::endl; + } + else + { + std::cerr + << " This " << what << " is " << months << " months old.\n" + << std::endl; + } } - // No warning for (foamVersion::api < version). - // We use this to denote future expiry dates of transition features. + + return old; } diff --git a/src/OpenFOAM/db/error/error.H b/src/OpenFOAM/db/error/error.H index 62cc4d48fad..13f88a87556 100644 --- a/src/OpenFOAM/db/error/error.H +++ b/src/OpenFOAM/db/error/error.H @@ -116,12 +116,18 @@ public: // Static Functions + //- Test if an age warning should be emitted. + // \param version is the old version (YYMM) for determining the + // age in months compared to the current OpenFOAM version + // as conveyed by the \c foamVersion::api value. + static bool warnAboutAge(const int version) noexcept; + //- Emit warning on stderr about something being old. // \param what description for the warning // \param version is the old version (YYMM) for determining the // age in months compared to the current OpenFOAM version // as conveyed by the \c foamVersion::api value. - static void warnAboutAge(const char* what, const int version); + static bool warnAboutAge(const char* what, const int version); // Member Functions diff --git a/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C b/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C index ff7a3ebbadc..9550509a6b7 100644 --- a/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C +++ b/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C @@ -124,15 +124,15 @@ void Foam::timeControl::read(const dictionary& dict) { // Accept deprecated 'outputControl' instead of 'writeControl' - IOWarningInFunction(dict) - << "Using deprecated 'outputControl'" << nl - << " Please use 'writeControl' with 'writeInterval'" - << endl; - error::warnAboutAge("outputControl", 1606); - // Change to the old names for this option controlName = "outputControl"; intervalName = "outputInterval"; + + IOWarningInFunction(dict) + << "Found deprecated 'outputControl'" << nl + << " Use 'writeControl' with 'writeInterval'" + << endl; + error::warnAboutAge("keyword", 1606); } } diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 9eb2fb42935..16ab2ed7fa1 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -194,21 +194,6 @@ Foam::argList::initValidTables dummyInitValidTables; // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // -namespace -{ - -// Should issue warning if there is +ve versioning (+ve version number) -// and the this version number is older than the current OpenFOAM version -// as conveyed by the OPENFOAM compiler define. - -static inline constexpr bool shouldWarnVersion(const int version) -{ - return (version > 0 && version < OPENFOAM); -} - -} // End anonymous namespace - - namespace Foam { @@ -553,22 +538,22 @@ Foam::word Foam::argList::optionCompat(const word& optName) if (fnd.found()) { - const auto& iter = *fnd; + const auto& alt = fnd.val(); - if (shouldWarnVersion(iter.second)) + if (error::warnAboutAge(alt.second)) { std::cerr << "--> FOAM IOWarning :" << nl - << " Found [v" << iter.second << "] '" + << " Found [v" << alt.second << "] '" << optName << "' instead of '-" - << iter.first << "' option" + << alt.first << "' option" << nl << std::endl; - error::warnAboutAge("option", iter.second); + error::warnAboutAge("option", alt.second); } - return "-" + iter.first; + return "-" + alt.first; } } @@ -587,23 +572,23 @@ int Foam::argList::optionIgnore(const word& optName) if (fnd.found()) { - const auto& iter = *fnd; + const auto& alt = fnd.val(); // Number to skip (including the option itself) // '-option ARG' or '-option' - const int nskip = (iter.first ? 2 : 1); + const int nskip = (alt.first ? 2 : 1); - if (shouldWarnVersion(iter.second)) + if (error::warnAboutAge(alt.second)) { std::cerr << "--> FOAM IOWarning :" << nl - << " Ignoring [v" << iter.second << "] '-" + << " Ignoring [v" << alt.second << "] '-" << optName << (nskip > 1 ? " ARG" : "") << "' option" << nl << std::endl; - error::warnAboutAge("option", iter.second); + error::warnAboutAge("option", alt.second); } return nskip; -- GitLab