Gadget
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
ErrorHandler Class Reference

This is the class used to handle errors in the model, by displaying error messages to the user and logging information to a log file. More...

#include <errorhandler.h>

Collaboration diagram for ErrorHandler:
Collaboration graph

Public Member Functions

 ErrorHandler ()
 This is the ErrorHandler constructor. More...
 
 ~ErrorHandler ()
 This is the default ErrorHandler destructor. More...
 
void Open (const char *filename)
 This function will open a file for reading data from, and store the name of the file. More...
 
void Close ()
 This function will close the last file opened for reading data from. More...
 
void checkIfFailure (ios &infile, const char *text)
 This function will check to see if an iostream can be opened, and exit Gadget with exit(EXIT_FAILURE) if this check fails. More...
 
void setLogFile (const char *filename)
 This function will open the file that the logging information will be written to. More...
 
int checkLogFile ()
 This function will return the flag used to determine whether ta logfile exists. More...
 
void logFinish ()
 This function will log information about the finish of the current model run to std::cout and a log file if one exists. More...
 
void logMessage (LogLevel mlevel, const char *msg)
 This function will log a warning message. More...
 
void logMessage (LogLevel mlevel, const char *msg1, const char *msg2)
 This function will log 2 warning messages. More...
 
void logMessage (LogLevel mlevel, const char *msg, int number)
 This function will log a warning message and a number. More...
 
void logMessage (LogLevel mlevel, const char *msg, double number)
 This function will log a warning message and a number. More...
 
void logMessage (LogLevel mlevel, const char *msg1, int number, const char *msg2)
 This function will log a warning message, a number and a second message. More...
 
void logMessage (LogLevel mlevel, const char *msg1, double number, const char *msg2)
 This function will log a warning message, a number and a second message. More...
 
void logMessage (LogLevel mlevel, DoubleVector vec)
 This function will log a vector of values. More...
 
void logMessageNaN (LogLevel mlevel, const char *msg)
 This function will log a warning message about a NaN found in the model. More...
 
void logFileMessage (LogLevel mlevel, const char *msg)
 This function will log a warning message generated when reading information from file. More...
 
void logFileMessage (LogLevel mlevel, const char *msg, int number)
 This function will log a warning message and a number, generated when reading information from file. More...
 
void logFileMessage (LogLevel mlevel, const char *msg, double number)
 This function will log a warning message and a number, generated when reading information from file. More...
 
void logFileMessage (LogLevel mlevel, const char *msg1, const char *msg2)
 This function will log 2 warning messages generated when reading information from file. More...
 
void logFileEOFMessage (LogLevel mlevel)
 This function will log an EOF warning message generated when reading information from file. More...
 
void logFileUnexpected (LogLevel mlevel, const char *msg1, const char *msg2)
 This function will log an 'unexpected' warning message generated when reading information from file. More...
 
void setRunOptimise (int opt)
 This function will set the optimise flag for the current model run. More...
 
int getRunOptimise () const
 This function will return the optimise flag for the current model run. More...
 
void setLogLevel (int level)
 This function will set the level of logging information used for the current model run. More...
 
LogLevel getLogLevel () const
 This function will return the level of logging information used for the current model run. More...
 
int getNaNFlag () const
 This function will return the flag denoting whether a NaN error has been rasied or not. More...
 
void setNaNFlag (int flag)
 This function will return the flag denoting whether a NaN error has been rasied or not. More...
 

Protected Attributes

ofstream logfile
 This ofstream is the file that all the logging information will get sent to. More...
 
StrStackfiles
 This is the StrStack of the names of files that are currently open to read from. More...
 

Detailed Description

This is the class used to handle errors in the model, by displaying error messages to the user and logging information to a log file.

Constructor & Destructor Documentation

◆ ErrorHandler()

ErrorHandler::ErrorHandler ( )

This is the ErrorHandler constructor.

◆ ~ErrorHandler()

ErrorHandler::~ErrorHandler ( )

This is the default ErrorHandler destructor.

Member Function Documentation

◆ checkIfFailure()

void ErrorHandler::checkIfFailure ( ios &  infile,
const char *  text 
)

This function will check to see if an iostream can be opened, and exit Gadget with exit(EXIT_FAILURE) if this check fails.

Parameters
infileis the iostream to be checked
textis the name of the iostream to be checked

◆ checkLogFile()

int ErrorHandler::checkLogFile ( )
inline

This function will return the flag used to determine whether ta logfile exists.

Returns
uselog

◆ Close()

void ErrorHandler::Close ( )

This function will close the last file opened for reading data from.

◆ getLogLevel()

LogLevel ErrorHandler::getLogLevel ( ) const
inline

This function will return the level of logging information used for the current model run.

Returns
loglevel

◆ getNaNFlag()

int ErrorHandler::getNaNFlag ( ) const
inline

This function will return the flag denoting whether a NaN error has been rasied or not.

Returns
nanflag

◆ getRunOptimise()

int ErrorHandler::getRunOptimise ( ) const
inline

This function will return the optimise flag for the current model run.

Returns
runopt

◆ logFileEOFMessage()

void ErrorHandler::logFileEOFMessage ( LogLevel  mlevel)

This function will log an EOF warning message generated when reading information from file.

Parameters
mlevelis the logging level of the message to be logged

◆ logFileMessage() [1/4]

void ErrorHandler::logFileMessage ( LogLevel  mlevel,
const char *  msg 
)

This function will log a warning message generated when reading information from file.

Parameters
mlevelis the logging level of the message to be logged
msgis the message to be logged

◆ logFileMessage() [2/4]

void ErrorHandler::logFileMessage ( LogLevel  mlevel,
const char *  msg,
double  number 
)

This function will log a warning message and a number, generated when reading information from file.

Parameters
mlevelis the logging level of the message to be logged
msgis the message to be logged
numberis the number to be logged

◆ logFileMessage() [3/4]

void ErrorHandler::logFileMessage ( LogLevel  mlevel,
const char *  msg,
int  number 
)

This function will log a warning message and a number, generated when reading information from file.

Parameters
mlevelis the logging level of the message to be logged
msgis the message to be logged
numberis the number to be logged

◆ logFileMessage() [4/4]

void ErrorHandler::logFileMessage ( LogLevel  mlevel,
const char *  msg1,
const char *  msg2 
)

This function will log 2 warning messages generated when reading information from file.

Parameters
mlevelis the logging level of the message to be logged
msg1is the first message to be logged
msg2is the second message to be logged

◆ logFileUnexpected()

void ErrorHandler::logFileUnexpected ( LogLevel  mlevel,
const char *  msg1,
const char *  msg2 
)

This function will log an 'unexpected' warning message generated when reading information from file.

Parameters
mlevelis the logging level of the message to be logged
msg1is the first (expected) message to be logged
msg2is the second (unexpected) message to be logged

◆ logFinish()

void ErrorHandler::logFinish ( )

This function will log information about the finish of the current model run to std::cout and a log file if one exists.

◆ logMessage() [1/7]

void ErrorHandler::logMessage ( LogLevel  mlevel,
const char *  msg 
)

This function will log a warning message.

Parameters
mlevelis the logging level of the message to be logged
msgis the message to be logged

◆ logMessage() [2/7]

void ErrorHandler::logMessage ( LogLevel  mlevel,
const char *  msg,
double  number 
)

This function will log a warning message and a number.

Parameters
mlevelis the logging level of the message to be logged
msgis the message to be logged
numberis the number to be logged

◆ logMessage() [3/7]

void ErrorHandler::logMessage ( LogLevel  mlevel,
const char *  msg,
int  number 
)

This function will log a warning message and a number.

Parameters
mlevelis the logging level of the message to be logged
msgis the message to be logged
numberis the number to be logged

◆ logMessage() [4/7]

void ErrorHandler::logMessage ( LogLevel  mlevel,
const char *  msg1,
const char *  msg2 
)

This function will log 2 warning messages.

Parameters
mlevelis the logging level of the message to be logged
msg1is the first message to be logged
msg2is the second message to be logged

◆ logMessage() [5/7]

void ErrorHandler::logMessage ( LogLevel  mlevel,
const char *  msg1,
double  number,
const char *  msg2 
)

This function will log a warning message, a number and a second message.

Parameters
mlevelis the logging level of the message to be logged
msg1is the first message to be logged
numberis the number to be logged
msg2is the second message to be logged

◆ logMessage() [6/7]

void ErrorHandler::logMessage ( LogLevel  mlevel,
const char *  msg1,
int  number,
const char *  msg2 
)

This function will log a warning message, a number and a second message.

Parameters
mlevelis the logging level of the message to be logged
msg1is the first message to be logged
numberis the number to be logged
msg2is the second message to be logged

◆ logMessage() [7/7]

void ErrorHandler::logMessage ( LogLevel  mlevel,
DoubleVector  vec 
)

This function will log a vector of values.

Parameters
mlevelis the logging level of the values to be logged
vecis the DoubleVector of values to be logged

◆ logMessageNaN()

void ErrorHandler::logMessageNaN ( LogLevel  mlevel,
const char *  msg 
)

This function will log a warning message about a NaN found in the model.

Parameters
mlevelis the logging level of the message to be logged
msgis the message to be logged

◆ Open()

void ErrorHandler::Open ( const char *  filename)

This function will open a file for reading data from, and store the name of the file.

Parameters
filenameis the name of the file

◆ setLogFile()

void ErrorHandler::setLogFile ( const char *  filename)

This function will open the file that the logging information will be written to.

Parameters
filenameis the name of the file

◆ setLogLevel()

void ErrorHandler::setLogLevel ( int  level)

This function will set the level of logging information used for the current model run.

Parameters
levelis the logging level to be set

◆ setNaNFlag()

void ErrorHandler::setNaNFlag ( int  flag)
inline

This function will return the flag denoting whether a NaN error has been rasied or not.

◆ setRunOptimise()

void ErrorHandler::setRunOptimise ( int  opt)
inline

This function will set the optimise flag for the current model run.

Parameters
optis the optimise flag to be set

Member Data Documentation

◆ files

StrStack* ErrorHandler::files
protected

This is the StrStack of the names of files that are currently open to read from.

◆ logfile

ofstream ErrorHandler::logfile
protected

This ofstream is the file that all the logging information will get sent to.


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