Cantera  2.0
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Private Attributes | List of all members

Class to hold global data. More...

#include <application.h>

Collaboration diagram for Application:
[legend]

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.
 
void addError (std::string r, std::string msg)
 Set an error condition in the application class without throwing an exception.
 
int getErrorCount ()
 Return the number of errors that have been encountered so far.
 
void popError ()
 Discard the last error message.
 
std::string lastErrorMessage ()
 Retrieve the last error message in a string.
 
void getErrors (std::ostream &f)
 Prints all of the error messages to an ostream.
 
void logErrors ()
 Prints all of the error messages using writelog.
 
void addDataDirectory (std::string dir)
 Add a directory to the data file search path.
 
std::string findInputFile (std::string name)
 Find an input file.
 
XML_Nodeget_XML_File (std::string file, int debug=0)
 Return a pointer to the XML tree for a Cantera input file.
 
void close_XML_File (std::string file)
 Close an XML File.
 
void writelog (const std::string &msg)
 Write a message to the screen.
 
void writelogendl ()
 Write an endl to the screen and flush output.
 
void writelog (const char *pszmsg)
 Write a message to the screen.
 
void logerror (const std::string &msg)
 Write an error message and quit.
 
int getUserEnv ()
 Returns an integer specifying the application environment.
 
void setLogger (Logger *logwriter)
 Install a logger - Called by the language interfaces to install an appropriate logger.
 
void thread_complete ()
 Delete Messenger object allocated per thread.
 
void beginLogGroup (std::string title, int loglevel)
 Create a new group for log messages.
 
void addLogEntry (std::string tag, std::string value)
 Add an entry to an HTML log file.
 
void addLogEntry (std::string tag, doublereal value)
 Add an entry to an HTML log file.
 
void addLogEntry (std::string tag, int value)
 Add an entry to an HTML log file.
 
void addLogEntry (std::string msg)
 Add an entry to an HTML log file.
 
void endLogGroup (std::string title)
 Close the current group of log messages.
 
void write_logfile (std::string file)
 Write the HTML log file.
 

Static Public Member Functions

static ApplicationInstance ()
 Return a pointer to the one and only instance of class Application.
 
static void ApplicationDestroy ()
 Static function that destroys the application class's data.
 

Protected Types

typedef boost::shared_ptr
< Messages
pMessages_t
 Typedef for thread specific messages.
 

Protected Member Functions

 Application ()
 Constructor for class sets up the initial conditions Protected ctor access thru static member function Instance.
 
void setDefaultDirectories ()
 Set the default directories for input files.
 

Protected Attributes

std::vector< std::string > inputDirs
 Current vector of input directories to search for input files.
 
bool stop_on_error
 Current list of error messages.
 
std::map< std::string,
std::string > 
options
 Current map of options.
 
std::string tmp_dir
 Current value of tmp_dir.
 
std::map< std::string, XML_Node * > xmlfiles
 Current vector of xml file trees that have been previously parsed.
 
ThreadMessages pMessenger
 Current pointer to the logwriter.
 

Static Private Attributes

static Applications_app = 0
 Pointer to the single Application instance.
 

Detailed Description

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.

Member Typedef Documentation

typedef boost::shared_ptr< Messages > pMessages_t
protected

Typedef for thread specific messages.

Definition at line 311 of file application.h.

Constructor & Destructor Documentation

Application ( )
protected

Constructor for class sets up the initial conditions Protected ctor access thru static member function Instance.

Definition at line 333 of file application.cpp.

References Application::pMessenger, Application::setDefaultDirectories(), and Unit::units().

Referenced by Application::Instance().

~Application ( )
virtual

Destructor for class deletes global data.

Delete any open XML trees, the logwriter, and the XML log, if any.

Definition at line 366 of file application.cpp.

References Application::xmlfiles.

Member Function Documentation

Application * Instance ( )
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 358 of file application.cpp.

References Cantera::app_mutex, Application::Application(), and Application::s_app.

Referenced by CanteraError::save().

void ApplicationDestroy ( )
static

Static function that destroys the application class's data.

Definition at line 376 of file application.cpp.

References Cantera::app_mutex, and Application::s_app.

int getErrorCount ( )
inline

Return the number of errors that have been encountered so far.

Definition at line 380 of file application.h.

References Application::Messages::getErrorCount(), and Application::pMessenger.

Referenced by Cantera::nErrors().

XML_Node * get_XML_File ( 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.

Parameters
fileString containing the relative or absolute file name
debugDebug flag

Definition at line 392 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 ( std::string  file)

Close an XML File.

Close a file that is opened by this application object

Parameters
fileString containing the relative or absolute file name

Definition at line 487 of file application.cpp.

References Cantera::xml_mutex, and Application::xmlfiles.

Referenced by Cantera::close_XML_File().

void logerror ( const std::string &  msg)
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.

Parameters
msgError message to be written to cerr.

Definition at line 548 of file application.h.

References Application::Messages::logerror(), and Application::pMessenger.

Referenced by Cantera::error().

int getUserEnv ( )
inline

Returns an integer specifying the application environment.

Deprecated:

Definition at line 554 of file application.h.

References Application::Messages::getUserEnv(), and Application::pMessenger.

Referenced by Cantera::userInterface().

void thread_complete ( )

Delete Messenger object allocated per thread.

Definition at line 384 of file application.cpp.

References Application::pMessenger, and Application::ThreadMessages::removeThreadMessages().

Referenced by Cantera::thread_complete().

void write_logfile ( std::string  file)
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.

Parameters
fileName of the file to be written

Definition at line 671 of file application.h.

References Application::pMessenger, and Application::Messages::write_logfile().

Referenced by Application::Messages::endLogGroup(), Cantera::write_logfile(), and Application::Messages::~Messages().

Member Data Documentation

std::vector<std::string> inputDirs
protected

Current vector of input directories to search for input files.

Definition at line 708 of file application.h.

Referenced by Application::addDataDirectory(), Application::findInputFile(), and Application::setDefaultDirectories().

bool stop_on_error
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 720 of file application.h.

std::map<std::string, std::string> options
protected

Current map of options.

Definition at line 722 of file application.h.

std::string tmp_dir
protected

Current value of tmp_dir.

Definition at line 724 of file application.h.

std::map<std::string, XML_Node*> xmlfiles
protected

Current vector of xml file trees that have been previously parsed.

Definition at line 726 of file application.h.

Referenced by Application::close_XML_File(), Application::get_XML_File(), and Application::~Application().

ThreadMessages pMessenger
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 743 of file application.h.

Referenced by Application::addError(), Application::addLogEntry(), Application::Application(), Application::beginLogGroup(), Application::endLogGroup(), Application::getErrorCount(), Application::getErrors(), Application::getUserEnv(), Application::lastErrorMessage(), Application::logerror(), Application::logErrors(), Application::popError(), Application::setLogger(), Application::thread_complete(), Application::write_logfile(), Application::writelog(), and Application::writelogendl().

Application * s_app = 0
staticprivate

Pointer to the single Application instance.

Definition at line 750 of file application.h.

Referenced by Application::ApplicationDestroy(), and Application::Instance().


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