Gadget
errorhandler.h
Go to the documentation of this file.
1 #ifndef errorhandler_h
2 #define errorhandler_h
3 
4 #include "strstack.h"
5 #include "doublevector.h"
6 #include "gadget.h"
7 
9 
14 class ErrorHandler {
15 public:
19  ErrorHandler();
23  ~ErrorHandler();
28  void Open(const char* filename);
32  void Close();
38  void checkIfFailure(ios& infile, const char* text);
43  void setLogFile(const char* filename);
48  int checkLogFile() { return uselog; };
52  void logFinish();
58  void logMessage(LogLevel mlevel, const char* msg);
65  void logMessage(LogLevel mlevel, const char* msg1, const char* msg2);
72  void logMessage(LogLevel mlevel, const char* msg, int number);
79  void logMessage(LogLevel mlevel, const char* msg, double number);
87  void logMessage(LogLevel mlevel, const char* msg1, int number, const char* msg2);
95  void logMessage(LogLevel mlevel, const char* msg1, double number, const char* msg2);
101  void logMessage(LogLevel mlevel, DoubleVector vec);
107  void logMessageNaN(LogLevel mlevel, const char* msg);
113  void logFileMessage(LogLevel mlevel, const char* msg);
120  void logFileMessage(LogLevel mlevel, const char* msg, int number);
127  void logFileMessage(LogLevel mlevel, const char* msg, double number);
134  void logFileMessage(LogLevel mlevel, const char* msg1, const char* msg2);
139  void logFileEOFMessage(LogLevel mlevel);
146  void logFileUnexpected(LogLevel mlevel, const char* msg1, const char* msg2);
151  void setRunOptimise(int opt) { runopt = opt; };
156  int getRunOptimise() const { return runopt; };
161  void setLogLevel(int level);
166  LogLevel getLogLevel() const { return loglevel; };
171  int getNaNFlag() const { return nanflag; };
175  void setNaNFlag(int flag) { nanflag = flag; };
176 protected:
180  ofstream logfile;
185 private:
189  int nanflag;
193  int runopt;
197  int uselog;
201  int numwarn;
205  LogLevel loglevel;
206 };
207 
208 #endif
This class implements a dynamic vector of double values.
Definition: doublevector.h:11
This is the class used to handle errors in the model, by displaying error messages to the user and lo...
Definition: errorhandler.h:14
StrStack * files
This is the StrStack of the names of files that are currently open to read from.
Definition: errorhandler.h:184
void setLogLevel(int level)
This function will set the level of logging information used for the current model run.
Definition: errorhandler.cc:22
void logMessageNaN(LogLevel mlevel, const char *msg)
This function will log a warning message about a NaN found in the model.
Definition: errorhandler.cc:407
void Close()
This function will close the last file opened for reading data from.
Definition: errorhandler.cc:75
void setRunOptimise(int opt)
This function will set the optimise flag for the current model run.
Definition: errorhandler.h:151
void setNaNFlag(int flag)
This function will return the flag denoting whether a NaN error has been rasied or not.
Definition: errorhandler.h:175
ofstream logfile
This ofstream is the file that all the logging information will get sent to.
Definition: errorhandler.h:175
void logFileEOFMessage(LogLevel mlevel)
This function will log an EOF warning message generated when reading information from file.
Definition: errorhandler.cc:666
int checkLogFile()
This function will return the flag used to determine whether ta logfile exists.
Definition: errorhandler.h:48
int getRunOptimise() const
This function will return the optimise flag for the current model run.
Definition: errorhandler.h:156
void logMessage(LogLevel mlevel, const char *msg)
This function will log a warning message.
Definition: errorhandler.cc:84
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)...
Definition: errorhandler.cc:753
void logFileUnexpected(LogLevel mlevel, const char *msg1, const char *msg2)
This function will log an 'unexpected' warning message generated when reading information from file.
Definition: errorhandler.cc:707
~ErrorHandler()
This is the default ErrorHandler destructor.
Definition: errorhandler.cc:18
void Open(const char *filename)
This function will open a file for reading data from, and store the name of the file.
Definition: errorhandler.cc:70
ErrorHandler()
This is the ErrorHandler constructor.
Definition: errorhandler.cc:9
void setLogFile(const char *filename)
This function will open the file that the logging information will be written to.
Definition: errorhandler.cc:59
void logFinish()
This function will log information about the finish of the current model run to std::cout and a log f...
Definition: errorhandler.cc:768
int getNaNFlag() const
This function will return the flag denoting whether a NaN error has been rasied or not.
Definition: errorhandler.h:171
LogLevel getLogLevel() const
This function will return the level of logging information used for the current model run.
Definition: errorhandler.h:166
void logFileMessage(LogLevel mlevel, const char *msg)
This function will log a warning message generated when reading information from file.
Definition: errorhandler.cc:453
This class implements a simple stack of string objects.
Definition: strstack.h:10
LogLevel
Definition: errorhandler.h:8
@ LOGFAIL
Definition: errorhandler.h:8
@ LOGNONE
Definition: errorhandler.h:8
@ LOGWARN
Definition: errorhandler.h:8
@ LOGDETAIL
Definition: errorhandler.h:8
@ LOGINFO
Definition: errorhandler.h:8
@ LOGDEBUG
Definition: errorhandler.h:8
@ LOGMESSAGE
Definition: errorhandler.h:8