Cantera
2.1.2
|
Class to hold global data. More...
#include <application.h>
Classes | |
class | Messages |
Class to carry out messages. More... | |
class | ThreadMessages |
Class that stores thread messages for each thread, and retrieves them based on the thread id. More... | |
Public Member Functions | |
virtual | ~Application () |
Destructor for class deletes global data. More... | |
void | addError (const std::string &r, const std::string &msg) |
Set an error condition in the application class without throwing an exception. More... | |
int | getErrorCount () |
Return the number of errors that have been encountered so far. More... | |
void | popError () |
Discard the last error message. More... | |
std::string | lastErrorMessage () |
Retrieve the last error message in a string. More... | |
void | getErrors (std::ostream &f) |
Prints all of the error messages to an ostream. More... | |
void | logErrors () |
Prints all of the error messages using writelog. More... | |
void | addDataDirectory (const std::string &dir) |
Add a directory to the data file search path. More... | |
std::string | findInputFile (const std::string &name) |
Find an input file. More... | |
XML_Node * | get_XML_File (const std::string &file, int debug=0) |
Return a pointer to the XML tree for a Cantera input file. More... | |
void | close_XML_File (const std::string &file) |
Close an XML File. More... | |
void | writelog (const std::string &msg) |
Write a message to the screen. More... | |
void | writelogendl () |
Write an endl to the screen and flush output. More... | |
void | logerror (const std::string &msg) |
Write an error message and quit. More... | |
void | warn_deprecated (const std::string &method, const std::string &extra="") |
Print a warning indicating that method is deprecated. More... | |
void | suppress_deprecation_warnings () |
Globally disable printing of deprecation warnings. More... | |
void | setLogger (Logger *logwriter) |
Install a logger. More... | |
void | thread_complete () |
Delete and free memory allocated per thread in multithreaded applications. More... | |
void | beginLogGroup (const std::string &title, int loglevel) |
Create a new group for log messages. More... | |
void | addLogEntry (const std::string &tag, const std::string &value) |
Add an entry to an HTML log file. More... | |
void | addLogEntry (const std::string &tag, doublereal value) |
Add an entry to an HTML log file. More... | |
void | addLogEntry (const std::string &tag, int value) |
Add an entry to an HTML log file. More... | |
void | addLogEntry (const std::string &msg) |
Add an entry to an HTML log file. More... | |
void | endLogGroup (const std::string &title) |
Close the current group of log messages. More... | |
void | write_logfile (const std::string &file) |
Write the HTML log file. More... | |
Static Public Member Functions | |
static Application * | Instance () |
Return a pointer to the one and only instance of class Application. More... | |
static void | ApplicationDestroy () |
Static function that destroys the application class's data. More... | |
Protected Types | |
typedef boost::shared_ptr < Messages > | pMessages_t |
Typedef for thread specific messages. More... | |
Protected Member Functions | |
Application () | |
Constructor for class sets up the initial conditions Protected ctor access thru static member function Instance. More... | |
void | setDefaultDirectories () |
Set the default directories for input files. More... | |
Protected Attributes | |
std::vector< std::string > | inputDirs |
Current vector of input directories to search for input files. More... | |
bool | stop_on_error |
Current list of error messages. More... | |
std::map< std::string, std::string > | options |
Current map of options. More... | |
std::string | tmp_dir |
Current value of tmp_dir. More... | |
std::map< std::string, XML_Node * > | xmlfiles |
Current vector of xml file trees that have been previously parsed. More... | |
std::set< std::string > | warnings |
Vector of deprecation warnings that have been emitted (to suppress duplicates) More... | |
bool | m_suppress_deprecation_warnings |
ThreadMessages | pMessenger |
Current pointer to the logwriter. More... | |
Static Private Attributes | |
static Application * | s_app = 0 |
Pointer to the single Application instance. More... | |
Class to hold global data.
Class Application is the top-level class that stores data that should persist for the duration of the process. The class should not be instantiated directly; instead, it is instantiated as needed by the functions declared here. At most one instance is created, and it is not destroyed until the process terminates.
Definition at line 41 of file application.h.
|
protected |
Typedef for thread specific messages.
Definition at line 288 of file application.h.
|
protected |
Constructor for class sets up the initial conditions Protected ctor access thru static member function Instance.
Definition at line 320 of file application.cpp.
References Application::pMessenger, Application::setDefaultDirectories(), and Unit::units().
Referenced by Application::Instance().
|
virtual |
Destructor for class deletes global data.
Delete any open XML trees, the logwriter, and the XML log, if any.
Definition at line 356 of file application.cpp.
References Application::xmlfiles.
|
static |
Return a pointer to the one and only instance of class Application.
If the an Application object has not yet been created it is created
Definition at line 347 of file application.cpp.
References Cantera::app_mutex, Application::Application(), and Application::s_app.
Referenced by CanteraError::save().
|
static |
Static function that destroys the application class's data.
Definition at line 366 of file application.cpp.
References Cantera::app_mutex, and Application::s_app.
|
inline |
Set an error condition in the application class without throwing an exception.
This routine adds an error message to the end of the stack of errors that Cantera accumulates in the Application class.
r | Procedure name which is generating the error condition |
msg | Descriptive message of the error condition. |
Definition at line 340 of file application.h.
References Application::Messages::addError(), and Application::pMessenger.
Referenced by CanteraError::save(), and Cantera::setError().
|
inline |
Return the number of errors that have been encountered so far.
Definition at line 345 of file application.h.
References Application::Messages::getErrorCount(), and Application::pMessenger.
Referenced by Cantera::nErrors().
|
inline |
Discard the last error message.
Cantera saves a stack of exceptions that it has caught in the Application class. This routine eliminates the last exception to be added to that stack.
Definition at line 350 of file application.h.
References Application::pMessenger, and Application::Messages::popError().
Referenced by Cantera::popError().
|
inline |
Retrieve the last error message in a string.
This routine will retrieve the last error message and return it in the return string.
Definition at line 355 of file application.h.
References Application::Messages::lastErrorMessage(), and Application::pMessenger.
Referenced by Cantera::lastErrorMessage().
|
inline |
Prints all of the error messages to an ostream.
Write out all of the saved error messages to the ostream f using the function Logger::writelog. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages to the ostream and then clears them from internal storage.
f | ostream which will receive the error messages |
Definition at line 360 of file application.h.
References Application::Messages::getErrors(), and Application::pMessenger.
Referenced by Cantera::showErrors().
|
inline |
Prints all of the error messages using writelog.
Print all of the error messages using function writelog. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages and then clears them from internal storage.
Definition at line 365 of file application.h.
References Application::Messages::logErrors(), and Application::pMessenger.
Referenced by Cantera::showErrors().
XML_Node * get_XML_File | ( | const std::string & | file, |
int | debug = 0 |
||
) |
Return a pointer to the XML tree for a Cantera input file.
This routine will find the file and read the XML file into an XML tree structure. Then, a pointer will be returned. If the file has already been processed, then just the pointer will be returned.
file | String containing the relative or absolute file name |
debug | Debug flag |
Definition at line 394 of file application.cpp.
References ctml::ct2ctml(), Application::findInputFile(), Cantera::npos, Application::writelog(), Cantera::xml_mutex, and Application::xmlfiles.
Referenced by Cantera::get_XML_File().
void close_XML_File | ( | const std::string & | file | ) |
Close an XML File.
Close a file that is opened by this application object
file | String containing the relative or absolute file name |
Definition at line 489 of file application.cpp.
References Cantera::xml_mutex, and Application::xmlfiles.
Referenced by Cantera::close_XML_File().
|
inline |
Write a message to the screen.
The string may be of any length, and may contain end-of-line characters. This method is used throughout Cantera to write log messages. It can also be called by user programs. The advantage of using writelog over writing directly to the standard output is that messages written with writelog will display correctly even when Cantera is used from MATLAB or other application that do not have a standard output stream.
msg | c++ string to be written to the screen |
Definition at line 430 of file application.h.
References Application::pMessenger, and Application::Messages::writelog().
Referenced by Application::Messages::endLogGroup(), Application::get_XML_File(), Application::Messages::logErrors(), Application::warn_deprecated(), Application::Messages::write_logfile(), and Cantera::writelog().
|
inline |
Write an endl to the screen and flush output.
Definition at line 435 of file application.h.
References Application::pMessenger, and Application::Messages::writelogendl().
Referenced by Application::warn_deprecated(), and Cantera::writelogendl().
|
inline |
Write an error message and quit.
The default behavior is to write to the standard error stream, and then call exit(). Note that no end-of-line character is appended to the message, and so if one is desired it must be included in the string. Note that this default behavior will terminate the application Cantera is invoked from (MATLAB, Excel, etc.) If this is not desired, then derive a class and reimplement this method.
msg | Error message to be written to cerr. |
Definition at line 440 of file application.h.
References Application::Messages::logerror(), and Application::pMessenger.
Referenced by Cantera::error().
void warn_deprecated | ( | const std::string & | method, |
const std::string & | extra = "" |
||
) |
Print a warning indicating that method is deprecated.
Additional information (removal version, alternatives) can be specified in extra. Deprecation warnings are printed once per method per invocation of the application.
Definition at line 375 of file application.cpp.
References Application::warnings, Application::writelog(), and Application::writelogendl().
Referenced by Cantera::warn_deprecated().
|
inline |
Globally disable printing of deprecation warnings.
Used primarily to prevent certain tests from failing.
Definition at line 452 of file application.h.
Referenced by Cantera::suppress_deprecation_warnings().
|
inline |
Install a logger.
Called by the language interfaces to install an appropriate logger. The logger is used for the writelog() function
logwriter | Pointer to a logger object |
Definition at line 457 of file application.h.
References Application::pMessenger, and Application::Messages::setLogger().
Referenced by Cantera::setLogger().
void thread_complete | ( | ) |
Delete and free memory allocated per thread in multithreaded applications.
Delete the memory allocated per thread by Cantera. It should be called from within the thread just before the thread terminates. If your version of Cantera has not been specifically compiled for thread safety this function does nothing.
Definition at line 386 of file application.cpp.
References Application::pMessenger, and Application::ThreadMessages::removeThreadMessages().
Referenced by Cantera::thread_complete().
|
inline |
Create a new group for log messages.
Usually this is called upon entering the function, with the title parameter equal to the name of the function or method. Subsequent messages written with addLogEntry will appear grouped under this heading, until endLogGroup() is called.
title | String name of the LogGroup |
loglevel | loglevel of the group. |
Definition at line 472 of file application.h.
References Application::Messages::beginLogGroup(), and Application::pMessenger.
Referenced by Cantera::beginLogGroup().
|
inline |
Add an entry to an HTML log file.
Entries appear in the form "tag:value".
tag | tag |
value | string value |
Definition at line 477 of file application.h.
References Application::Messages::addLogEntry(), and Application::pMessenger.
Referenced by Cantera::addLogEntry().
|
inline |
Add an entry to an HTML log file.
Entries appear in the form "tag:value".
tag | tag |
value | double value |
Definition at line 482 of file application.h.
References Application::Messages::addLogEntry(), and Application::pMessenger.
|
inline |
Add an entry to an HTML log file.
Entries appear in the form "tag:value".
tag | tag |
value | integer value |
Definition at line 487 of file application.h.
References Application::Messages::addLogEntry(), and Application::pMessenger.
|
inline |
Add an entry to an HTML log file.
Entries appear in the form "msg".
msg | Message to be added |
Definition at line 492 of file application.h.
References Application::Messages::addLogEntry(), and Application::pMessenger.
|
inline |
Close the current group of log messages.
This is typically called just before leaving a function or method, to close the group of messages that were output from this function. Subsequent messages written with addLogEntry() will appear at the next-higher level in the outline, unless beginLogGroup() is called first to create a new group.
title | Name of the log group. It defaults to the most recent log group created. |
Definition at line 497 of file application.h.
References Application::Messages::endLogGroup(), and Application::pMessenger.
Referenced by Cantera::endLogGroup().
|
inline |
Write the HTML log file.
Log entries are stored in memory in an XML tree until this function is called, which writes the tree to a file and clears the entries stored in memory. The output file will have the name specified in the 'file' argument. If this argument has no extension, the extension '.html' will be appended. Also, if the file already exists, an integer will be appended to the name so that no existing log file will be overwritten. WITH_HTML_LOGS must be defined.
file | Name of the file to be written |
Definition at line 502 of file application.h.
References Application::pMessenger, and Application::Messages::write_logfile().
Referenced by Application::Messages::endLogGroup(), and Cantera::write_logfile().
|
protected |
Current vector of input directories to search for input files.
Definition at line 537 of file application.h.
Referenced by Application::addDataDirectory(), Application::findInputFile(), and Application::setDefaultDirectories().
|
protected |
Current list of error messages.
Current list of warning messages Current error Routine Last error message Current line length Current value of stop_on_error
Definition at line 549 of file application.h.
|
protected |
Current map of options.
Definition at line 551 of file application.h.
|
protected |
Current value of tmp_dir.
Definition at line 553 of file application.h.
|
protected |
Current vector of xml file trees that have been previously parsed.
Definition at line 555 of file application.h.
Referenced by Application::close_XML_File(), Application::get_XML_File(), and Application::~Application().
|
protected |
Vector of deprecation warnings that have been emitted (to suppress duplicates)
Definition at line 557 of file application.h.
Referenced by Application::warn_deprecated().
|
protected |
Current pointer to the logwriter.
Current pointer to the top of the XML_Node tree for the current HTML log Pointer to the last current position in the XML_Node tree for the current HTML log Current value of loglevel Vector of loglevels for loggroups that are open Current vector of loggroups that are open
Definition at line 577 of file application.h.
Referenced by Application::addError(), Application::addLogEntry(), Application::Application(), Application::beginLogGroup(), Application::endLogGroup(), Application::getErrorCount(), Application::getErrors(), Application::lastErrorMessage(), Application::logerror(), Application::logErrors(), Application::popError(), Application::setLogger(), Application::thread_complete(), Application::write_logfile(), Application::writelog(), and Application::writelogendl().
|
staticprivate |
Pointer to the single Application instance.
Definition at line 584 of file application.h.
Referenced by Application::ApplicationDestroy(), and Application::Instance().