Skip to content

Commit ff10fe0

Browse files
author
Henry Weller
committed
messageStream, error: Add new versions of message and error macros
which use the __PRETTY_FUNCTION__ constant string to provide the function name
1 parent 5deddf7 commit ff10fe0

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

src/OpenFOAM/db/error/error.H

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,23 @@ extern IOerror FatalIOError;
315315
#define FatalErrorIn(functionName) \
316316
::Foam::FatalError((functionName), __FILE__, __LINE__)
317317

318+
//- Report an error message using Foam::FatalError
319+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
320+
#define FatalErrorInFunction FatalErrorIn(FUNCTION_NAME)
321+
322+
318323
//- Report an error message using Foam::FatalIOError
319324
// for functionName in file __FILE__ at line __LINE__
320325
// for a particular IOstream
321326
#define FatalIOErrorIn(functionName, ios) \
322327
::Foam::FatalIOError((functionName), __FILE__, __LINE__, (ios))
323328

329+
//- Report an error message using Foam::FatalIOError
330+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
331+
// for a particular IOstream
332+
#define FatalIOErrorInFunction(ios) FatalIOErrorIn(FUNCTION_NAME, ios)
333+
334+
324335
//- Report an error message using Foam::FatalIOError
325336
// (or cerr if FatalIOError not yet constructed)
326337
// for functionName in file __FILE__ at line __LINE__
@@ -329,6 +340,14 @@ extern IOerror FatalIOError;
329340
::Foam::IOerror::SafeFatalIOError \
330341
((functionName), __FILE__, __LINE__, (ios), (msg))
331342

343+
//- Report an error message using Foam::FatalIOError
344+
// (or cerr if FatalIOError not yet constructed)
345+
// for functionName in file __FILE__ at line __LINE__
346+
// for a particular IOstream
347+
#define SafeFatalIOErrorInFunction(ios, msg) \
348+
SafeFatalIOErrorIn(FUNCTION_NAME, ios, msg)
349+
350+
332351
//- Issue a FatalErrorIn for a function not currently implemented.
333352
// The functionName is printed and then abort is called.
334353
//
@@ -340,10 +359,12 @@ extern IOerror FatalIOError;
340359
<< "Not implemented" << ::Foam::abort(FatalError);
341360

342361
//- Issue a FatalErrorIn for a function not currently implemented.
343-
// The compiler generated function name string is printed and then
344-
// abort is called.
345-
#define NotImplemented \
346-
notImplemented(__PRETTY_FUNCTION__)
362+
// The FUNCTION_NAME is printed and then abort is called.
363+
//
364+
// This macro can be particularly useful when methods must be defined to
365+
// complete the interface of a derived class even if they should never be
366+
// called for this derived class.
367+
#define NotImplemented notImplemented(FUNCTION_NAME)
347368

348369

349370
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

src/OpenFOAM/db/error/messageStream.H

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,39 +218,82 @@ extern messageStream Info;
218218
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219219
// Convenience macros to add the file name and line number to the function name
220220

221+
// Compiler provided function name string:
222+
// for gcc-compatible compilers use __PRETTY_FUNCTION__
223+
// otherwise use the standard __func__
224+
#ifdef __GNUC__
225+
#define FUNCTION_NAME __PRETTY_FUNCTION__
226+
#else
227+
#define FUNCTION_NAME __func__
228+
#endif
229+
230+
221231
//- Report an error message using Foam::SeriousError
222232
// for functionName in file __FILE__ at line __LINE__
223233
#define SeriousErrorIn(fn) \
224234
::Foam::SeriousError((fn), __FILE__, __LINE__)
225235

236+
//- Report an error message using Foam::SeriousError
237+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
238+
#define SeriousErrorInFunction(fn) SeriousErrorIn(FUNCTION_NAME)
239+
240+
226241
//- Report an IO error message using Foam::SeriousError
227242
// for functionName in file __FILE__ at line __LINE__
228243
// for a particular IOstream
229244
#define SeriousIOErrorIn(fn, ios) \
230245
::Foam::SeriousError((fn), __FILE__, __LINE__, ios)
231246

247+
//- Report an IO error message using Foam::SeriousError
248+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
249+
// for a particular IOstream
250+
#define SeriousIOErrorInFunction(ios) SeriousIOErrorIn(FUNCTION_NAME, ios)
251+
252+
232253
//- Report a warning using Foam::Warning
233254
// for functionName in file __FILE__ at line __LINE__
234255
#define WarningIn(fn) \
235256
::Foam::Warning((fn), __FILE__, __LINE__)
236257

258+
//- Report a warning using Foam::Warning
259+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
260+
#define WarningInFunction WarningIn(FUNCTION_NAME)
261+
262+
237263
//- Report an IO warning using Foam::Warning
238264
// for functionName in file __FILE__ at line __LINE__
239265
// for a particular IOstream
240266
#define IOWarningIn(fn, ios) \
241267
::Foam::Warning((fn), __FILE__, __LINE__, (ios))
242268

269+
//- Report an IO warning using Foam::Warning
270+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
271+
// for a particular IOstream
272+
#define IOWarningInFunction(ios) IOWarningIn(FUNCTION_NAME, ios)
273+
274+
243275
//- Report a information message using Foam::Info
244276
// for functionName in file __FILE__ at line __LINE__
245277
#define InfoIn(fn) \
246278
::Foam::Info((fn), __FILE__, __LINE__)
247279

280+
//- Report a information message using Foam::Info
281+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
282+
#define InfoInFunction InfoIn(FUNCTION_NAME)
283+
284+
248285
//- Report an IO information message using Foam::Info
249286
// for functionName in file __FILE__ at line __LINE__
250287
// for a particular IOstream
251288
#define IOInfoIn(fn, ios) \
252289
::Foam::Info((fn), __FILE__, __LINE__, (ios))
253290

291+
//- Report an IO information message using Foam::Info
292+
// for FUNCTION_NAME in file __FILE__ at line __LINE__
293+
// for a particular IOstream
294+
#define IOInfoInFunction(ios) IOInfoIn(FUNCTION_NAME, ios)
295+
296+
254297
//- Report a variable name and value
255298
// using Foam::Pout in file __FILE__ at line __LINE__
256299
#define Debug(var) \

0 commit comments

Comments
 (0)