Loading...
Searching...
No Matches
messageStream Class Reference

Handle output messages in a simple, consistent stream-based manner. More...

#include <messageStream.H>

Inheritance diagram for messageStream:
Collaboration diagram for messageStream:

Public Types

enum  errorSeverity : int {
  INFO = 1 , WARNING , SERIOUS , FATAL ,
  USE_STDERR = 0x80
}
 Message type, error severity flags. More...

Public Member Functions

 messageStream (errorSeverity severity, int maxErrors=0, bool use_stderr=false)
 Construct untitled with given characteristics.
 messageStream (const char *title, errorSeverity severity, int maxErrors=0, bool use_stderr=false)
 Construct from components.
 messageStream (string title, errorSeverity severity, int maxErrors=0, bool use_stderr=false)
 Construct from components.
 messageStream (const dictionary &dict)
 Construct from dictionary as Fatal, extracting 'title'.
const stringtitle () const noexcept
 The title of this error type.
int maxErrors () const noexcept
 The maximum number of errors before program termination.
int maxErrors (int nErrors) noexcept
 Set the maximum number of errors before program termination.
OSstreamstream (OSstream *alternative=nullptr, int communicator=-1)
 Return OSstream for output operations.
OSstreammasterStream (int communicator)
 Return OSstream for output operations on the master process only, Snull on other processes.
std::ostream & stdStream ()
 Return std::ostream for output operations.
OSstreamdeprecated (const int afterVersion, const char *functionName=nullptr, const char *sourceFileName=nullptr, const int sourceFileLineNumber=0)
 Report deprecation (after specified API version) with 'From function-name, source file, line number'.
 operator OSstream & ()
 Implicit cast to OSstream for << operations.
OSstreamoperator() ()
 Explicitly convert to OSstream for << operations.
OSstreamoperator() (const std::string &functionName, const char *sourceFileName=nullptr, const int sourceFileLineNumber=0)
 Report 'From function-name', optionally with 'source file, line number'.
OSstreamoperator() (const char *functionName, const char *sourceFileName=nullptr, const int sourceFileLineNumber=0)
 Report 'From function-name', optionally with 'source file, line number'.
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const std::string &ioFileName, const label ioStartLineNumber=-1, const label ioEndLineNumber=-1)
 Report 'From function-name, source file, line number' as well as io-file name and location.
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const IOstream &)
 Report 'From function-name, source file, line number' as well as io-file name and location.
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const dictionary &)
 Report 'From function-name, source file, line number' as well as io-file name and location.

Static Public Attributes

static int level
 The output level (verbosity) of messages.
static int redirect
 The output redirection of messages.

Protected Attributes

string title_
 The title of this error type.
int severity_
 The message type / error severity, possibly with USE_STDERR mask.
int maxErrors_
 The maximum number of errors before program termination.
int errorCount_
 The current number of errors counted.

Detailed Description

Handle output messages in a simple, consistent stream-based manner.

The messageStream class is globally instantiated with a title string and a severity (which controls the program termination), optionally with a max number of errors before termination.

Errors, messages and other data are sent to the messageStream class in the standard manner.

For parallel applications, the output for 'standard' messages (Info, Warnings) is effectively suppressed on all sub-processes, which results in a single output message instead of a flood of output messages from each process. The error type of messages do, however, retain output on all processes, which ensures that parallel termination occurs correctly and the source of the problem is properly traceable to the originating processor.

Source files

Definition at line 72 of file messageStream.H.

Member Enumeration Documentation

◆ errorSeverity

enum errorSeverity : int

Message type, error severity flags.

Enumerator
INFO 

General information output (stdout).

WARNING 

Warning of possible problem.

SERIOUS 

A serious problem - eg, data corruption.

FATAL 

A fatal error.

USE_STDERR 

Bitmask for stderr output (for the above enums).

Definition at line 79 of file messageStream.H.

Constructor & Destructor Documentation

◆ messageStream() [1/4]

messageStream ( errorSeverity severity,
int maxErrors = 0,
bool use_stderr = false )
explicit

Construct untitled with given characteristics.

Definition at line 43 of file messageStream.C.

References errorCount_, maxErrors(), maxErrors_, severity_, and USE_STDERR.

Referenced by error::error(), error::error(), error::error(), messageStream(), messageStream(), and messageStream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messageStream() [2/4]

messageStream ( const char * title,
errorSeverity severity,
int maxErrors = 0,
bool use_stderr = false )

Construct from components.

Definition at line 61 of file messageStream.C.

References maxErrors(), messageStream(), title(), and title_.

Here is the call graph for this function:

◆ messageStream() [3/4]

messageStream ( string title,
errorSeverity severity,
int maxErrors = 0,
bool use_stderr = false )

Construct from components.

Definition at line 78 of file messageStream.C.

References maxErrors(), messageStream(), title(), and title_.

Here is the call graph for this function:

◆ messageStream() [4/4]

messageStream ( const dictionary & dict)
explicit

Construct from dictionary as Fatal, extracting 'title'.

Definition at line 92 of file messageStream.C.

References dict, FATAL, and messageStream().

Here is the call graph for this function:

Member Function Documentation

◆ title()

const string & title ( ) const
inlinenoexcept

The title of this error type.

Definition at line 190 of file messageStream.H.

References Foam::noexcept, and title_.

Referenced by error::error(), error::error(), IOerror::IOerror(), IOerror::IOerror(), messageStream(), messageStream(), error::write(), and IOerror::write().

Here is the caller graph for this function:

◆ maxErrors() [1/2]

int maxErrors ( ) const
inlinenoexcept

The maximum number of errors before program termination.

Definition at line 198 of file messageStream.H.

References maxErrors_, and Foam::noexcept.

Referenced by messageStream(), messageStream(), and messageStream().

Here is the caller graph for this function:

◆ maxErrors() [2/2]

int maxErrors ( int nErrors)
inlinenoexcept

Set the maximum number of errors before program termination.

Returns
the previous value for maxErrors

Definition at line 208 of file messageStream.H.

References maxErrors_.

◆ stream()

Foam::OSstream & stream ( OSstream * alternative = nullptr,
int communicator = -1 )

Return OSstream for output operations.

Parameters
alternativeAn alternative output stream (serial-only)
communicatorCommunicator. Negative is treated like UPstream::worldComm

Definition at line 100 of file messageStream.C.

References Foam::abort(), errorCount_, Foam::FatalError, FatalErrorInFunction, INFO, Foam::infoDetailLevel, level, UPstream::master(), maxErrors_, UPstream::parRun(), Foam::Perr, Foam::Pout, redirect, Foam::Serr, severity_, Foam::Snull, Foam::Sout, title_, USE_STDERR, WARNING, and UPstream::worldComm.

Referenced by deprecated(), masterStream(), operator OSstream &(), operator()(), operator()(), operator()(), and stdStream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ masterStream()

Foam::OSstream & masterStream ( int communicator)

Return OSstream for output operations on the master process only, Snull on other processes.

A negative communicator is treated like UPstream::worldComm

Definition at line 181 of file messageStream.C.

References Foam::endl(), UPstream::master(), Foam::Perr, error::printStack(), Foam::Snull, stream(), UPstream::warnComm, and UPstream::worldComm.

Here is the call graph for this function:

◆ stdStream()

std::ostream & stdStream ( )

Return std::ostream for output operations.

Definition at line 203 of file messageStream.C.

References stream().

Here is the call graph for this function:

◆ deprecated()

Foam::OSstream & deprecated ( const int afterVersion,
const char * functionName = nullptr,
const char * sourceFileName = nullptr,
const int sourceFileLineNumber = 0 )

Report deprecation (after specified API version) with 'From function-name, source file, line number'.

Returns
OSstream for further operations

Definition at line 212 of file messageStream.C.

References Foam::foamVersion::api, Foam::nl, os(), and stream().

Here is the call graph for this function:

◆ operator OSstream &()

operator OSstream & ( )
inline

Implicit cast to OSstream for << operations.

Definition at line 260 of file messageStream.H.

References stream().

Here is the call graph for this function:

◆ operator()() [1/6]

OSstream & operator() ( )
inline

Explicitly convert to OSstream for << operations.

Definition at line 268 of file messageStream.H.

References stream().

Here is the call graph for this function:

◆ operator()() [2/6]

Foam::OSstream & operator() ( const std::string & functionName,
const char * sourceFileName = nullptr,
const int sourceFileLineNumber = 0 )

Report 'From function-name', optionally with 'source file, line number'.

Returns
OSstream for further operations

Definition at line 273 of file messageStream.C.

References Foam::nl, os(), and stream().

Here is the call graph for this function:

◆ operator()() [3/6]

Foam::OSstream & operator() ( const char * functionName,
const char * sourceFileName = nullptr,
const int sourceFileLineNumber = 0 )

Report 'From function-name', optionally with 'source file, line number'.

Returns
OSstream for further operations

Definition at line 303 of file messageStream.C.

References Foam::nl, os(), and stream().

Here is the call graph for this function:

◆ operator()() [4/6]

Foam::OSstream & operator() ( const char * functionName,
const char * sourceFileName,
const int sourceFileLineNumber,
const std::string & ioFileName,
const label ioStartLineNumber = -1,
const label ioEndLineNumber = -1 )

Report 'From function-name, source file, line number' as well as io-file name and location.

Returns
OSstream for further operations

Definition at line 333 of file messageStream.C.

References Foam::endl(), and os().

Here is the call graph for this function:

◆ operator()() [5/6]

Foam::OSstream & operator() ( const char * functionName,
const char * sourceFileName,
const int sourceFileLineNumber,
const IOstream & ioStream )

Report 'From function-name, source file, line number' as well as io-file name and location.

Returns
OSstream for further operations
Parameters
ioStreamProvides name and lineNumber

Definition at line 368 of file messageStream.C.

◆ operator()() [6/6]

Foam::OSstream & operator() ( const char * functionName,
const char * sourceFileName,
const int sourceFileLineNumber,
const dictionary & dict )

Report 'From function-name, source file, line number' as well as io-file name and location.

Returns
OSstream for further operations
Parameters
dictProvides name, startLine, endLine

Definition at line 388 of file messageStream.C.

References dict.

Member Data Documentation

◆ title_

string title_
protected

The title of this error type.

Definition at line 101 of file messageStream.H.

Referenced by messageStream(), messageStream(), stream(), and title().

◆ severity_

int severity_
protected

The message type / error severity, possibly with USE_STDERR mask.

Definition at line 106 of file messageStream.H.

Referenced by messageStream(), and stream().

◆ maxErrors_

int maxErrors_
protected

The maximum number of errors before program termination.

Definition at line 111 of file messageStream.H.

Referenced by maxErrors(), maxErrors(), messageStream(), and stream().

◆ errorCount_

int errorCount_
protected

The current number of errors counted.

Definition at line 116 of file messageStream.H.

Referenced by messageStream(), and stream().

◆ level

int level
static

The output level (verbosity) of messages.

  • level == 0 : suppress all output
  • level == 1 : normal output
  • level >= 2 : report source file name and line number if available
Note
The default level is normally 2.

Definition at line 133 of file messageStream.H.

Referenced by IOobject::setBad(), stream(), error::write(), and IOerror::write().

◆ redirect

int redirect
static

The output redirection of messages.

  • redirect == 2 : use stderr instead of stdout

Definition at line 141 of file messageStream.H.

Referenced by stream().


The documentation for this class was generated from the following files: