SUMO - Simulation of Urban MObility

MsgHandler Class Reference

#include <MsgHandler.h>

Public Types

enum  MsgType { MT_MESSAGE, MT_WARNING, MT_ERROR }

Public Member Functions

void addRetriever (OutputDevice *retriever)
 Adds a further retriever to the instance responsible for a certain msg type.
void beginProcessMsg (std::string msg, bool addType=true)
 Begins a process information.
void clear ()
 Clears information whether an error occured previously.
void endProcessMsg (std::string msg)
 Ends a process information.
void inform (std::string msg, bool addType=true)
 adds a new error to the list
template<class T >
MsgHandler & operator<< (const T &t)
 Generic output operator.
void progressMsg (std::string msg, bool addType=true)
 Writes a progress message.
void removeRetriever (OutputDevice *retriever)
 Removes the retriever from the.
void report2cerr (bool value)
 Sets the information whether stderr shall be used as output device.
void report2cout (bool value)
 Sets the information whether stdout shall be used as output device.
bool wasInformed () const
 Returns the information whether any messages were added.

Static Public Member Functions

static void assignLock (AbstractMutex *lock)
 Sets the lock to use The lock will not be deleted.
static void cleanupOnEnd ()
 Removes pending handler.
static MsgHandler * getErrorInstance ()
 Returns the instance to add errors to.
static MsgHandler * getMessageInstance ()
 Returns the instance to add normal messages to.
static MsgHandler * getWarningInstance ()
 Returns the instance to add warnings to.
static void initOutputOptions (bool gui=false)

Protected Member Functions

std::string build (const std::string &msg, bool addType)
 Builds the string which includes the mml-message type.

Private Types

typedef std::vector
< OutputDevice * > 
RetrieverVector
 Definition of the list of retrievers to inform.

Private Member Functions

 MsgHandler (MsgType type)
 standard constructor
 MsgHandler (const MsgHandler &s)
MsgHandler & operator= (const MsgHandler &s)
 ~MsgHandler ()
 destructor

Private Attributes

bool myReport2CERR
 Information whether stderr shall be used as output device, too.
bool myReport2COUT
 Information whether stdout shall be used as output device, too.
RetrieverVector myRetrievers
 The list of retrievers that shall be informed about new messages or errors.
MsgType myType
 The type of the instance.
bool myWasInformed
 information wehther an error occured at all

Static Private Attributes

static bool myAmProcessingProcess = false
 Information whether a process information is printed to cout.
static MsgHandler * myErrorInstance = 0
 The instance to handle errors.
static AbstractMutex * myLock = 0
 The lock if any has to be used The lock will not be deleted.
static MsgHandler * myMessageInstance = 0
 The instance to handle normal messages.
static MsgHandler * myWarningInstance = 0
 The instance to handle warnings.

Detailed Description

MsgHandler

Definition at line 59 of file MsgHandler.h.


Member Typedef Documentation

typedef std::vector<OutputDevice*> MsgHandler::RetrieverVector [private]

Definition of the list of retrievers to inform.

Definition at line 210 of file MsgHandler.h.


Member Enumeration Documentation

An enumeration to differ between different types of messages (errors, warning and information)

Enumerator:
MT_MESSAGE 

The message is only something to show.

MT_WARNING 

The message is a warning.

MT_ERROR 

The message is an error.

Definition at line 66 of file MsgHandler.h.


Constructor & Destructor Documentation

MsgHandler::MsgHandler ( MsgType  type) [private]

standard constructor

Definition at line 367 of file MsgHandler.cpp.

Referenced by getErrorInstance(), getMessageInstance(), and getWarningInstance().

MsgHandler::~MsgHandler ( ) [private]

destructor

Definition at line 372 of file MsgHandler.cpp.

MsgHandler::MsgHandler ( const MsgHandler &  s) [private]

invalid copy constructor


Member Function Documentation

void MsgHandler::addRetriever ( OutputDevice *  retriever)
void MsgHandler::assignLock ( AbstractMutex *  lock) [static]

Sets the lock to use The lock will not be deleted.

Definition at line 383 of file MsgHandler.cpp.

References myLock.

Referenced by main().

void MsgHandler::beginProcessMsg ( std::string  msg,
bool  addType = true 
)

Begins a process information.

When a longer action is started, this method should be used to inform the user about it. There will be no newline printed, but the message handler will be informed that a process message has been begun. If an error occurs, a newline will be printed. After the action has been performed, use endProcessMsg to inform the user about it.

Definition at line 158 of file MsgHandler.cpp.

References build(), AbstractMutex::lock(), myAmProcessingProcess, myLock, myReport2CERR, myReport2COUT, myRetrievers, myWasInformed, and AbstractMutex::unlock().

std::string MsgHandler::build ( const std::string &  msg,
bool  addType 
) [inline, protected]

Builds the string which includes the mml-message type.

Definition at line 153 of file MsgHandler.h.

References MT_ERROR, MT_MESSAGE, MT_WARNING, and myType.

Referenced by beginProcessMsg(), inform(), and progressMsg().

void MsgHandler::cleanupOnEnd ( ) [static]
void MsgHandler::clear ( )

Clears information whether an error occured previously.

Definition at line 215 of file MsgHandler.cpp.

References AbstractMutex::lock(), myLock, myWasInformed, and AbstractMutex::unlock().

Referenced by loadJTRDefinitions(), main(), NBLoadedTLDef::myCompute(), and GUILoadThread::run().

void MsgHandler::endProcessMsg ( std::string  msg)
template<class T >
MsgHandler& MsgHandler::operator<< ( const T &  t) [inline]

Generic output operator.

Returns:
The MsgHandler for further processing

Definition at line 136 of file MsgHandler.h.

References myReport2CERR, myReport2COUT, and myRetrievers.

MsgHandler& MsgHandler::operator= ( const MsgHandler &  s) [private]

invalid assignment operator

void MsgHandler::progressMsg ( std::string  msg,
bool  addType = true 
)

Writes a progress message.

Writes the message and closes it with a (char) 13

Definition at line 127 of file MsgHandler.cpp.

References build(), AbstractMutex::lock(), myAmProcessingProcess, myLock, myReport2CERR, myReport2COUT, myRetrievers, myWasInformed, and AbstractMutex::unlock().

Referenced by NIVissimConnectionCluster::joinBySameEdges(), ODMatrix::write(), and ROLoader::writeStats().

void MsgHandler::removeRetriever ( OutputDevice *  retriever)
void MsgHandler::report2cerr ( bool  value)
void MsgHandler::report2cout ( bool  value)

Sets the information whether stdout shall be used as output device.

Definition at line 275 of file MsgHandler.cpp.

References OptionsCont::exists(), OptionsCont::getBool(), OptionsCont::getOptions(), AbstractMutex::lock(), MT_MESSAGE, MT_WARNING, myLock, myReport2COUT, myRetrievers, myType, and AbstractMutex::unlock().

Referenced by initOutputOptions(), main(), and GUILoadThread::run().

bool MsgHandler::wasInformed ( ) const

Returns the information whether any messages were added.

Definition at line 377 of file MsgHandler.cpp.

References myWasInformed.

Referenced by NLBuilder::build(), ROLoader::makeSingleStep(), ROLoader::processRoutesStepWise(), and XMLSubSys::runParser().


Field Documentation

bool MsgHandler::myAmProcessingProcess = false [static, private]

Information whether a process information is printed to cout.

Definition at line 190 of file MsgHandler.h.

Referenced by beginProcessMsg(), endProcessMsg(), inform(), and progressMsg().

MsgHandler * MsgHandler::myErrorInstance = 0 [static, private]

The instance to handle errors.

Definition at line 181 of file MsgHandler.h.

Referenced by cleanupOnEnd(), and getErrorInstance().

AbstractMutex * MsgHandler::myLock = 0 [static, private]

The lock if any has to be used The lock will not be deleted.

Definition at line 194 of file MsgHandler.h.

Referenced by addRetriever(), assignLock(), beginProcessMsg(), cleanupOnEnd(), clear(), endProcessMsg(), inform(), progressMsg(), removeRetriever(), report2cerr(), and report2cout().

MsgHandler * MsgHandler::myMessageInstance = 0 [static, private]

The instance to handle normal messages.

Definition at line 187 of file MsgHandler.h.

Referenced by cleanupOnEnd(), and getMessageInstance().

Information whether stderr shall be used as output device, too.

Definition at line 207 of file MsgHandler.h.

Referenced by beginProcessMsg(), endProcessMsg(), inform(), operator<<(), progressMsg(), and report2cerr().

Information whether stdout shall be used as output device, too.

Definition at line 204 of file MsgHandler.h.

Referenced by beginProcessMsg(), endProcessMsg(), inform(), operator<<(), progressMsg(), removeRetriever(), report2cerr(), and report2cout().

The list of retrievers that shall be informed about new messages or errors.

Definition at line 213 of file MsgHandler.h.

Referenced by addRetriever(), beginProcessMsg(), endProcessMsg(), inform(), operator<<(), progressMsg(), removeRetriever(), report2cerr(), and report2cout().

The type of the instance.

Definition at line 198 of file MsgHandler.h.

Referenced by addRetriever(), build(), removeRetriever(), report2cerr(), and report2cout().

MsgHandler * MsgHandler::myWarningInstance = 0 [static, private]

The instance to handle warnings.

Definition at line 184 of file MsgHandler.h.

Referenced by cleanupOnEnd(), and getWarningInstance().

information wehther an error occured at all

Definition at line 201 of file MsgHandler.h.

Referenced by beginProcessMsg(), clear(), endProcessMsg(), inform(), progressMsg(), and wasInformed().


The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines