diff --git a/src/OpenFOAM/db/error/messageStream.C b/src/OpenFOAM/db/error/messageStream.C index 4511a4bafa..55d3db1b22 100644 --- a/src/OpenFOAM/db/error/messageStream.C +++ b/src/OpenFOAM/db/error/messageStream.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,6 +31,7 @@ Note #include "error.H" #include "dictionary.H" +#include "foamVersion.H" #include "Pstream.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -167,7 +168,7 @@ std::ostream& Foam::messageStream::stdStream() Foam::OSstream& Foam::messageStream::operator() ( - const string& functionName + const std::string& functionName ) { OSstream& os = this->stream(); @@ -182,6 +183,57 @@ Foam::OSstream& Foam::messageStream::operator() } +Foam::OSstream& Foam::messageStream::deprecated +( + const int afterVersion, + const char* functionName, + const char* sourceFileName, + const int sourceFileLineNumber +) +{ + OSstream& os = this->stream(); + + // No warning for 0 (unversioned) or -ve values (silent versioning). + // Also no warning for (version >= foamVersion::api), which + // can be used to denote future expiry dates of transition features. + + if (afterVersion > 0 && afterVersion < foamVersion::api) + { + const int months = + ( + // YYMM -> months + (12 * (foamVersion::api/100) + (foamVersion::api % 100)) + - (12 * (afterVersion/100) + (afterVersion % 100)) + ); + + os << nl + << ">>> DEPRECATED after version " << afterVersion; + + if (afterVersion < 1000) + { + // Predates YYMM versioning (eg, 240 for version 2.4) + os << ". This is very old! <<<" << nl; + } + else + { + os << ". This is about " << months << " months old. <<<" << nl; + } + } + + os << nl; + + if (functionName) // nullptr check + { + os << " From " << functionName << nl + << " in file " << sourceFileName + << " at line " << sourceFileLineNumber << nl; + } + os << " "; + + return os; +} + + Foam::OSstream& Foam::messageStream::operator() ( const char* functionName, @@ -194,7 +246,7 @@ Foam::OSstream& Foam::messageStream::operator() os << nl << " From " << functionName << nl << " in file " << sourceFileName - << " at line " << sourceFileLineNumber << endl + << " at line " << sourceFileLineNumber << nl << " "; return os; @@ -203,7 +255,7 @@ Foam::OSstream& Foam::messageStream::operator() Foam::OSstream& Foam::messageStream::operator() ( - const string& functionName, + const std::string& functionName, const char* sourceFileName, const int sourceFileLineNumber ) @@ -222,7 +274,7 @@ Foam::OSstream& Foam::messageStream::operator() const char* functionName, const char* sourceFileName, const int sourceFileLineNumber, - const string& ioFileName, + const std::string& ioFileName, const label ioStartLineNumber, const label ioEndLineNumber ) @@ -233,7 +285,7 @@ Foam::OSstream& Foam::messageStream::operator() << " From " << functionName << nl << " in file " << sourceFileName << " at line " << sourceFileLineNumber << nl - << " Reading " << ioFileName; + << " Reading \"" << ioFileName.c_str() << '"'; if (ioStartLineNumber >= 0) { diff --git a/src/OpenFOAM/db/error/messageStream.H b/src/OpenFOAM/db/error/messageStream.H index c4f23fcd35..be382ec536 100644 --- a/src/OpenFOAM/db/error/messageStream.H +++ b/src/OpenFOAM/db/error/messageStream.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -54,7 +54,8 @@ SourceFiles #define Foam_messageStream_H #include "label.H" -#include "string.H" +#include "word.H" +#include #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -170,6 +171,17 @@ public: //- Return std::ostream for output operations. std::ostream& stdStream(); + //- Report deprecation (after specified API version) with + //- 'From function-name, source file, line number'. + // \return OSstream for further operations + OSstream& deprecated + ( + const int afterVersion, + const char* functionName, + const char* sourceFileName, + const int sourceFileLineNumber = 0 + ); + //- Implicit cast to OSstream for << operations operator OSstream&() { @@ -186,11 +198,10 @@ public: // \return OSstream for further operations OSstream& operator() ( - const string& functionName + const std::string& functionName ); //- Report 'From function-name, source file, line number' - //- Print basic message // \return OSstream for further operations OSstream& operator() ( @@ -203,7 +214,7 @@ public: // \return OSstream for further operations OSstream& operator() ( - const string& functionName, + const std::string& functionName, const char* sourceFileName, const int sourceFileLineNumber = 0 ); @@ -216,7 +227,7 @@ public: const char* functionName, const char* sourceFileName, const int sourceFileLineNumber, - const string& ioFileName, + const std::string& ioFileName, const label ioStartLineNumber = -1, const label ioEndLineNumber = -1 ); @@ -328,6 +339,11 @@ extern messageStream SeriousError; // for FUNCTION_NAME in file __FILE__ at line __LINE__ #define WarningInFunction WarningIn(FUNCTION_NAME) +//- Report a warning using Foam::Warning +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +#define DeprecatedInFunction(afterVersion) \ + ::Foam::Warning.deprecated(afterVersion, FUNCTION_NAME, __FILE__, __LINE__) + //- Report an IO warning using Foam::Warning // for functionName in file __FILE__ at line __LINE__ diff --git a/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C b/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C index eabf883256..fcf136ecbd 100644 --- a/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C +++ b/src/finiteVolume/expressions/fields/fvPatchFields/exprFixedValueFvPatchField.C @@ -107,6 +107,10 @@ Foam::exprFixedValueFvPatchField::exprFixedValueFvPatchField ), driver_(this->patch(), dict_) { + DeprecatedInFunction(2212) + << "Use uniformFixedValue with an expression Function1 instead." << nl + << " This boundary condition will be removed in the future" << endl; + setDebug(); DebugInFunction << nl; diff --git a/src/genericPatchFields/genericPatchFieldBase/genericPatchFieldBase.C b/src/genericPatchFields/genericPatchFieldBase/genericPatchFieldBase.C index ae032898ae..b5bd0c839e 100644 --- a/src/genericPatchFields/genericPatchFieldBase/genericPatchFieldBase.C +++ b/src/genericPatchFields/genericPatchFieldBase/genericPatchFieldBase.C @@ -26,7 +26,7 @@ License \*---------------------------------------------------------------------------*/ #include "genericPatchFieldBase.H" -#include "messageStream.H" +#include "error.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //