Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Private Attributes | List of all members
Application Class Reference

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. 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_Nodeget_XML_File (const std::string &file, int debug=0)
 Return a pointer to the XML tree for a Cantera input file. More...
 
XML_Nodeget_XML_from_string (const std::string &text)
 Read a CTI or CTML string and fill up an XML tree. 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...
 

Static Public Member Functions

static ApplicationInstance ()
 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,
std::pair< XML_Node *, int > > 
xmlfiles
 Current vector of XML file trees that have been previously parsed The second element of the value is used to store the last-modified time for the file, to enable change detection. 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 Applications_app = 0
 Pointer to the single Application instance. More...
 

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 40 of file application.h.

Member Typedef Documentation

typedef boost::shared_ptr< Messages > pMessages_t
protected

Typedef for thread specific messages.

Definition at line 175 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 171 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 196 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 187 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 206 of file application.cpp.

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

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

Parameters
rProcedure name which is generating the error condition
msgDescriptive message of the error condition.

Definition at line 227 of file application.h.

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

Referenced by CanteraError::save(), and Cantera::setError().

int getErrorCount ( )
inline

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

Definition at line 232 of file application.h.

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

Referenced by Cantera::nErrors().

void popError ( )
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 237 of file application.h.

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

Referenced by Cantera::popError().

std::string lastErrorMessage ( )
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 242 of file application.h.

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

Referenced by Cantera::lastErrorMessage().

void getErrors ( std::ostream &  f)
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.

Parameters
fostream which will receive the error messages

Definition at line 247 of file application.h.

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

Referenced by Cantera::showErrors().

void logErrors ( )
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 252 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.

Parameters
fileString containing the relative or absolute file name
debugDebug flag

Definition at line 233 of file application.cpp.

References XML_Node::build(), Cantera::ct2ctml_string(), Application::findInputFile(), XML_Node::lock(), Cantera::npos, Cantera::xml_mutex, and Application::xmlfiles.

Referenced by Cantera::get_XML_File().

XML_Node * get_XML_from_string ( const std::string &  text)

Read a CTI or CTML string and fill up an XML tree.

Return a pointer to the XML tree corresponding to the specified CTI or XML string. If the given string has been processed before, the cached XML tree will be returned. Otherwise, the XML tree will be generated and stored in the cache.

Parameters
textCTI or CTML string
Returns
Root of the corresponding XML tree

Definition at line 279 of file application.cpp.

References Cantera::ct_string2ctml_string(), Cantera::xml_mutex, and Application::xmlfiles.

Referenced by Cantera::get_XML_from_string().

void close_XML_File ( const 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 299 of file application.cpp.

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

Referenced by Cantera::close_XML_File().

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

Parameters
msgc++ string to be written to the screen

Definition at line 328 of file application.h.

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

Referenced by Application::Messages::logErrors(), Application::warn_deprecated(), and Cantera::writelog().

void writelogendl ( )
inline

Write an endl to the screen and flush output.

Definition at line 333 of file application.h.

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

Referenced by Application::warn_deprecated(), and Cantera::writelogendl().

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.
Deprecated:
To be removed after Cantera 2.2

Definition at line 338 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 215 of file application.cpp.

References Application::warnings, Application::writelog(), and Application::writelogendl().

Referenced by Cantera::warn_deprecated().

void suppress_deprecation_warnings ( )
inline

Globally disable printing of deprecation warnings.

Used primarily to prevent certain tests from failing.

Definition at line 350 of file application.h.

Referenced by Cantera::suppress_deprecation_warnings().

void setLogger ( Logger logwriter)
inline

Install a logger.

Called by the language interfaces to install an appropriate logger. The logger is used for the writelog() function

Parameters
logwriterPointer to a logger object
See Also
Logger.

Definition at line 355 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 226 of file application.cpp.

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

Referenced by Cantera::thread_complete().

Member Data Documentation

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

Current vector of input directories to search for input files.

Definition at line 398 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 410 of file application.h.

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

Current map of options.

Definition at line 412 of file application.h.

std::string tmp_dir
protected

Current value of tmp_dir.

Definition at line 414 of file application.h.

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

Current vector of XML file trees that have been previously parsed The second element of the value is used to store the last-modified time for the file, to enable change detection.

Definition at line 418 of file application.h.

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

std::set<std::string> warnings
protected

Vector of deprecation warnings that have been emitted (to suppress duplicates)

Definition at line 420 of file application.h.

Referenced by Application::warn_deprecated().

ThreadMessages pMessenger
protected
Application * s_app = 0
staticprivate

Pointer to the single Application instance.

Definition at line 435 of file application.h.

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


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