ENH: centralize checks for keyword age into Foam::error

STYLE: additional note about include/exclude HashTable.C
This commit is contained in:
Mark Olesen
2021-07-09 20:30:26 +02:00
parent c1c1799051
commit ccc751e55d
7 changed files with 65 additions and 78 deletions

View File

@ -943,7 +943,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifndef NoHashTableC #ifndef NoHashTableC // Excluded from token.H
#ifdef NoRepository #ifdef NoRepository
#include "HashTable.C" #include "HashTable.C"
#endif #endif

View File

@ -272,6 +272,7 @@ namespace Detail
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Previously excluded (via token.H)
#ifdef NoRepository #ifdef NoRepository
#include "HashTable.C" #include "HashTable.C"
#endif #endif

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,23 +28,6 @@ License
#include "dictionary.H" #include "dictionary.H"
#include "Pstream.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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::dictionary::const_searcher Foam::dictionary::csearchCompat Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
@ -61,9 +44,9 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
return finder; 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()) if (finder.good())
{ {
@ -71,20 +54,20 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchCompat
// Pstream::master() when Pstream has not yet been initialized // Pstream::master() when Pstream has not yet been initialized
if if
( (
shouldWarnVersion(iter.second) (Pstream::parRun() ? Pstream::master() : true)
&& (Pstream::parRun() ? Pstream::master() : true) && error::warnAboutAge(alt.second)
) )
{ {
std::cerr std::cerr
<< "--> FOAM IOWarning :" << nl << "--> FOAM IOWarning :" << nl
<< " Found [v" << iter.second << "] '" << " Found [v" << alt.second << "] '"
<< iter.first << "' entry instead of '" << alt.first << "' entry instead of '"
<< keyword.c_str() << "' in dictionary \"" << keyword.c_str() << "' in dictionary \""
<< name().c_str() << "\" " << name().c_str() << "\" "
<< nl << nl
<< std::endl; << std::endl;
error::warnAboutAge("keyword", iter.second); error::warnAboutAge("keyword", alt.second);
} }
break; break;

View File

@ -38,21 +38,23 @@ License
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * 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) // No warning for 0 (unversioned) or -ve values (silent versioning)
return ((version > 0) && (version < foamVersion::api));
} }
else if (version < 1000)
bool Foam::error::warnAboutAge(const char* what, const int version)
{ {
// Warning for things that predate the YYMM versioning // No warning for 0 (unversioned) or -ve values (silent versioning)
// (eg, 240 for version 2.4) const bool old = ((version > 0) && (version < foamVersion::api));
std::cerr
<< " This " << what << " is very old.\n" // Note:
<< std::endl; // No warning for (version >= foamVersion::api), which
} // can be used to denote future expiry dates of transition features.
else if (version < foamVersion::api)
if (old)
{ {
const int months = const int months =
( (
@ -61,12 +63,22 @@ void Foam::error::warnAboutAge(const char* what, const int version)
- (12 * (version/100) + (version % 100)) - (12 * (version/100) + (version % 100))
); );
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 std::cerr
<< " This " << what << " is " << months << " months old.\n" << " This " << what << " is " << months << " months old.\n"
<< std::endl; << std::endl;
} }
// No warning for (foamVersion::api < version). }
// We use this to denote future expiry dates of transition features.
return old;
} }

View File

@ -116,12 +116,18 @@ public:
// Static Functions // 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. //- Emit warning on stderr about something being old.
// \param what description for the warning // \param what description for the warning
// \param version is the old version (YYMM) for determining the // \param version is the old version (YYMM) for determining the
// age in months compared to the current OpenFOAM version // age in months compared to the current OpenFOAM version
// as conveyed by the \c foamVersion::api value. // 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 // Member Functions

View File

@ -124,15 +124,15 @@ void Foam::timeControl::read(const dictionary& dict)
{ {
// Accept deprecated 'outputControl' instead of 'writeControl' // 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 // Change to the old names for this option
controlName = "outputControl"; controlName = "outputControl";
intervalName = "outputInterval"; intervalName = "outputInterval";
IOWarningInFunction(dict)
<< "Found deprecated 'outputControl'" << nl
<< " Use 'writeControl' with 'writeInterval'"
<< endl;
error::warnAboutAge("keyword", 1606);
} }
} }

View File

@ -194,21 +194,6 @@ Foam::argList::initValidTables dummyInitValidTables;
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 namespace Foam
{ {
@ -553,22 +538,22 @@ Foam::word Foam::argList::optionCompat(const word& optName)
if (fnd.found()) if (fnd.found())
{ {
const auto& iter = *fnd; const auto& alt = fnd.val();
if (shouldWarnVersion(iter.second)) if (error::warnAboutAge(alt.second))
{ {
std::cerr std::cerr
<< "--> FOAM IOWarning :" << nl << "--> FOAM IOWarning :" << nl
<< " Found [v" << iter.second << "] '" << " Found [v" << alt.second << "] '"
<< optName << "' instead of '-" << optName << "' instead of '-"
<< iter.first << "' option" << alt.first << "' option"
<< nl << nl
<< std::endl; << 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()) if (fnd.found())
{ {
const auto& iter = *fnd; const auto& alt = fnd.val();
// Number to skip (including the option itself) // Number to skip (including the option itself)
// '-option ARG' or '-option' // '-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 std::cerr
<< "--> FOAM IOWarning :" << nl << "--> FOAM IOWarning :" << nl
<< " Ignoring [v" << iter.second << "] '-" << " Ignoring [v" << alt.second << "] '-"
<< optName << (nskip > 1 ? " ARG" : "") << optName << (nskip > 1 ? " ARG" : "")
<< "' option" << "' option"
<< nl << nl
<< std::endl; << std::endl;
error::warnAboutAge("option", iter.second); error::warnAboutAge("option", alt.second);
} }
return nskip; return nskip;