From 90fef11e304d95fd2cb007dd512964707afd11ff Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Fri, 30 Oct 2015 17:30:26 +0000 Subject: [PATCH] messageStream, error: Add new versions of message and error macros which use the __PRETTY_FUNCTION__ constant string to provide the function name --- src/OpenFOAM/db/error/error.H | 29 +++++++++++++++--- src/OpenFOAM/db/error/messageStream.H | 43 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/db/error/error.H b/src/OpenFOAM/db/error/error.H index 53b8d321765..5abd995af64 100644 --- a/src/OpenFOAM/db/error/error.H +++ b/src/OpenFOAM/db/error/error.H @@ -315,12 +315,23 @@ extern IOerror FatalIOError; #define FatalErrorIn(functionName) \ ::Foam::FatalError((functionName), __FILE__, __LINE__) +//- Report an error message using Foam::FatalError +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +#define FatalErrorInFunction FatalErrorIn(FUNCTION_NAME) + + //- Report an error message using Foam::FatalIOError // for functionName in file __FILE__ at line __LINE__ // for a particular IOstream #define FatalIOErrorIn(functionName, ios) \ ::Foam::FatalIOError((functionName), __FILE__, __LINE__, (ios)) +//- Report an error message using Foam::FatalIOError +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +// for a particular IOstream +#define FatalIOErrorInFunction(ios) FatalIOErrorIn(FUNCTION_NAME, ios) + + //- Report an error message using Foam::FatalIOError // (or cerr if FatalIOError not yet constructed) // for functionName in file __FILE__ at line __LINE__ @@ -329,6 +340,14 @@ extern IOerror FatalIOError; ::Foam::IOerror::SafeFatalIOError \ ((functionName), __FILE__, __LINE__, (ios), (msg)) +//- Report an error message using Foam::FatalIOError +// (or cerr if FatalIOError not yet constructed) +// for functionName in file __FILE__ at line __LINE__ +// for a particular IOstream +#define SafeFatalIOErrorInFunction(ios, msg) \ + SafeFatalIOErrorIn(FUNCTION_NAME, ios, msg) + + //- Issue a FatalErrorIn for a function not currently implemented. // The functionName is printed and then abort is called. // @@ -340,10 +359,12 @@ extern IOerror FatalIOError; << "Not implemented" << ::Foam::abort(FatalError); //- Issue a FatalErrorIn for a function not currently implemented. -// The compiler generated function name string is printed and then -// abort is called. -#define NotImplemented \ - notImplemented(__PRETTY_FUNCTION__) +// The FUNCTION_NAME is printed and then abort is called. +// +// This macro can be particularly useful when methods must be defined to +// complete the interface of a derived class even if they should never be +// called for this derived class. +#define NotImplemented notImplemented(FUNCTION_NAME) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/db/error/messageStream.H b/src/OpenFOAM/db/error/messageStream.H index 3ccbb27dc14..b3e42f1ca85 100644 --- a/src/OpenFOAM/db/error/messageStream.H +++ b/src/OpenFOAM/db/error/messageStream.H @@ -218,39 +218,82 @@ extern messageStream Info; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Convenience macros to add the file name and line number to the function name +// Compiler provided function name string: +// for gcc-compatible compilers use __PRETTY_FUNCTION__ +// otherwise use the standard __func__ +#ifdef __GNUC__ + #define FUNCTION_NAME __PRETTY_FUNCTION__ +#else + #define FUNCTION_NAME __func__ +#endif + + //- Report an error message using Foam::SeriousError // for functionName in file __FILE__ at line __LINE__ #define SeriousErrorIn(fn) \ ::Foam::SeriousError((fn), __FILE__, __LINE__) +//- Report an error message using Foam::SeriousError +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +#define SeriousErrorInFunction(fn) SeriousErrorIn(FUNCTION_NAME) + + //- Report an IO error message using Foam::SeriousError // for functionName in file __FILE__ at line __LINE__ // for a particular IOstream #define SeriousIOErrorIn(fn, ios) \ ::Foam::SeriousError((fn), __FILE__, __LINE__, ios) +//- Report an IO error message using Foam::SeriousError +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +// for a particular IOstream +#define SeriousIOErrorInFunction(ios) SeriousIOErrorIn(FUNCTION_NAME, ios) + + //- Report a warning using Foam::Warning // for functionName in file __FILE__ at line __LINE__ #define WarningIn(fn) \ ::Foam::Warning((fn), __FILE__, __LINE__) +//- Report a warning using Foam::Warning +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +#define WarningInFunction WarningIn(FUNCTION_NAME) + + //- Report an IO warning using Foam::Warning // for functionName in file __FILE__ at line __LINE__ // for a particular IOstream #define IOWarningIn(fn, ios) \ ::Foam::Warning((fn), __FILE__, __LINE__, (ios)) +//- Report an IO warning using Foam::Warning +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +// for a particular IOstream +#define IOWarningInFunction(ios) IOWarningIn(FUNCTION_NAME, ios) + + //- Report a information message using Foam::Info // for functionName in file __FILE__ at line __LINE__ #define InfoIn(fn) \ ::Foam::Info((fn), __FILE__, __LINE__) +//- Report a information message using Foam::Info +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +#define InfoInFunction InfoIn(FUNCTION_NAME) + + //- Report an IO information message using Foam::Info // for functionName in file __FILE__ at line __LINE__ // for a particular IOstream #define IOInfoIn(fn, ios) \ ::Foam::Info((fn), __FILE__, __LINE__, (ios)) +//- Report an IO information message using Foam::Info +// for FUNCTION_NAME in file __FILE__ at line __LINE__ +// for a particular IOstream +#define IOInfoInFunction(ios) IOInfoIn(FUNCTION_NAME, ios) + + //- Report a variable name and value // using Foam::Pout in file __FILE__ at line __LINE__ #define Debug(var) \ -- GitLab