Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
Warnings Class Reference

#include <Warnings.hpp>

+ Collaboration diagram for Warnings:

Public Member Functions

void AddWarning (const std::string &rMessage, const std::string &rFilename, unsigned lineNumber, bool onlyOnce=false)
 
std::string PopWarning () const
 
unsigned GetNumWarnings ()
 
std::string GetNextWarningMessage ()
 

Static Public Member Functions

static void NoisyDestroy ()
 
static void QuietDestroy ()
 
static void PrintWarnings ()
 
static WarningsInstance ()
 

Protected Member Functions

 Warnings ()
 

Private Types

typedef std::deque< std::pair< std::string, std::string > > WarningsContainerType
 

Private Attributes

WarningsContainerType mWarningMessages
 

Static Private Attributes

static WarningsmpInstance = nullptr
 

Detailed Description

The Warnings singleton class collects warnings via the AddWarning() method or the WARNING macro. This is to provide a mechanism for informing the user of error which are less severe than those demanding exceptions or assertions. (Errors which can be repaired immediately.)

Warnings can be polled with GetNumWarnings() and GetNextWarningMessage(). Warnings can be ignored and destroyed with QuietDestroy(). All warnings left at the close of the test suite (not the individual test), or the close of the executable, will be printed to the screen.

Definition at line 54 of file Warnings.hpp.

Member Typedef Documentation

◆ WarningsContainerType

typedef std::deque<std::pair<std::string, std::string> > Warnings::WarningsContainerType
private

Container type for warnings

Definition at line 61 of file Warnings.hpp.

Constructor & Destructor Documentation

◆ Warnings()

Warnings::Warnings ( )
protected

Protected constructor. Use Instance() to access the Warnings singleton.

Definition at line 50 of file Warnings.cpp.

Referenced by Instance().

Member Function Documentation

◆ AddWarning()

void Warnings::AddWarning ( const std::string &  rMessage,
const std::string &  rFilename,
unsigned  lineNumber,
bool  onlyOnce = false 
)

Make a warning with a message string and add it to the list.

Parameters
rMessagethe message
rFilenamewhich source file threw the exception
lineNumberwhich line number of the source file threw the exception
onlyOncewhether to only log the first warning thrown from this location

Definition at line 97 of file Warnings.cpp.

References mWarningMessages, and ChastePosixPathFixer::ToPosix().

◆ GetNextWarningMessage()

std::string Warnings::GetNextWarningMessage ( )
Returns
next warning. Remove and inspect a warning.

Definition at line 123 of file Warnings.cpp.

References EXCEPTION, and mWarningMessages.

◆ GetNumWarnings()

unsigned Warnings::GetNumWarnings ( )
Returns
how many warnings are in the queue.

Definition at line 118 of file Warnings.cpp.

References mWarningMessages.

◆ Instance()

Warnings * Warnings::Instance ( )
static
Returns
a pointer to the Warnings object. The object is created the first time this method is called.

Definition at line 87 of file Warnings.cpp.

References Warnings(), mpInstance, and NoisyDestroy().

◆ NoisyDestroy()

void Warnings::NoisyDestroy ( void  )
static

Default destroyer (takes the place of a destructor, using the std::atexit directive). Prints all warning messages to stdout.

Definition at line 54 of file Warnings.cpp.

References PrintWarnings(), and QuietDestroy().

Referenced by Instance().

◆ PopWarning()

std::string Warnings::PopWarning ( ) const

Get the message associated with the exception with file and line number.

Returns
The message set when the exception was thrown including file and line number information

◆ PrintWarnings()

void Warnings::PrintWarnings ( void  )
static

Prints all warning messages to stdout without changing the state of the Warnings.

Definition at line 69 of file Warnings.cpp.

References mpInstance, and mWarningMessages.

Referenced by NoisyDestroy().

◆ QuietDestroy()

void Warnings::QuietDestroy ( void  )
static

Public destroyer (takes the place of a destructor but is called by the user to make sure that no warnings appear).

Definition at line 60 of file Warnings.cpp.

References mpInstance.

Referenced by NoisyDestroy().

Member Data Documentation

◆ mpInstance

Warnings * Warnings::mpInstance = nullptr
staticprivate

Pointer to the single instance. For use as singleton

Definition at line 58 of file Warnings.hpp.

Referenced by Instance(), PrintWarnings(), and QuietDestroy().

◆ mWarningMessages

WarningsContainerType Warnings::mWarningMessages
private

Warnings messages. First in pair is the context (line number etc.). Second in pair is the actual warning,

Definition at line 63 of file Warnings.hpp.

Referenced by AddWarning(), GetNextWarningMessage(), GetNumWarnings(), and PrintWarnings().


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