Eclipse SUMO - Simulation of Urban MObility
MsgHandler Class Reference

#include <MsgHandler.h>

Inheritance diagram for MsgHandler:
Collaboration diagram for MsgHandler:

Public Types

enum  MsgType {
  MT_MESSAGE, MT_WARNING, MT_ERROR, MT_DEBUG,
  MT_GLDEBUG
}
 

Public Member Functions

virtual void addRetriever (OutputDevice *retriever)
 Adds a further retriever to the instance responsible for a certain msg type. More...
 
virtual void beginProcessMsg (std::string msg, bool addType=true)
 Begins a process information. More...
 
virtual void clear ()
 Clears information whether an error occurred previously. More...
 
virtual void endProcessMsg (std::string msg)
 Ends a process information. More...
 
virtual void inform (std::string msg, bool addType=true)
 adds a new error to the list More...
 
template<typename T , typename... Targs>
void informf (const std::string &format, T value, Targs... Fargs)
 adds a new formatted message More...
 
bool isRetriever (OutputDevice *retriever) const
 Returns whether the given output device retrieves messages from the handler. More...
 
template<class T >
MsgHandleroperator<< (const T &t)
 Generic output operator. More...
 
virtual void removeRetriever (OutputDevice *retriever)
 Removes the retriever from the handler. More...
 
bool wasInformed () const
 Returns the information whether any messages were added. More...
 

Static Public Member Functions

static void cleanupOnEnd ()
 Removes pending handler. More...
 
static void enableDebugGLMessages (bool enable)
 enable/disable gl-debug messages More...
 
static void enableDebugMessages (bool enable)
 enable/disable debug messages More...
 
static MsgHandlergetDebugInstance ()
 Returns the instance to add debug to. More...
 
static MsgHandlergetErrorInstance ()
 Returns the instance to add errors to. More...
 
static MsgHandlergetGLDebugInstance ()
 Returns the instance to add GLdebug to. More...
 
static MsgHandlergetMessageInstance ()
 Returns the instance to add normal messages to. More...
 
static MsgHandlergetWarningInstance ()
 Returns the instance to add warnings to. More...
 
static void initOutputOptions ()
 init output options More...
 
static void removeRetrieverFromAllInstances (OutputDevice *out)
 ensure that that given output device is no longer used as retriever by any instance More...
 
static void setFactory (Factory func)
 Sets the factory function to use for new MsgHandlers. More...
 
static bool writeDebugGLMessages ()
 check whether to enable/disable gl-debug messages More...
 
static bool writeDebugMessages ()
 check whether to enable/disable debug messages More...
 

Protected Member Functions

void _informf (const char *format)
 
template<typename T , typename... Targs>
void _informf (const char *format, T value, Targs... Fargs)
 adds a new formatted message More...
 
std::string build (const std::string &msg, bool addType)
 Builds the string which includes the mml-message type. More...
 
 MsgHandler (MsgType type)
 standard constructor More...
 
void setAggregationThreshold (const int thresh)
 
virtual ~MsgHandler ()
 destructor More...
 

Private Types

typedef MsgHandler *(* Factory) (MsgType)
 

Private Member Functions

 MsgHandler (const MsgHandler &s)=delete
 invalid copy constructor More...
 
MsgHandleroperator= (const MsgHandler &s)=delete
 invalid assignment operator More...
 

Private Attributes

std::map< const std::string, int > myAggregationCount
 count for messages of the same type More...
 
int myAggregationThreshold
 do not output more messages of the same type if the count exceeds this threshold More...
 
std::vector< OutputDevice * > myRetrievers
 The list of retrievers that shall be informed about new messages or errors. More...
 
MsgType myType
 The type of the instance. More...
 
bool myWasInformed
 information whether an output occurred at all More...
 

Static Private Attributes

static bool myAmProcessingProcess = false
 Information whether a process information is printed to cout. More...
 
static MsgHandlermyDebugInstance = nullptr
 The instance to handle debug. More...
 
static MsgHandlermyErrorInstance = nullptr
 The instance to handle errors. More...
 
static Factory myFactory = nullptr
 The function to call for new MsgHandlers, nullptr means use default constructor. More...
 
static MsgHandlermyGLDebugInstance = nullptr
 The instance to handle glDebug. More...
 
static MsgHandlermyMessageInstance = nullptr
 The instance to handle normal messages. More...
 
static MsgHandlermyWarningInstance = nullptr
 The instance to handle warnings. More...
 
static bool myWriteDebugGLMessages
 
static bool myWriteDebugMessages
 Flag to enable or disable debug GL Functions. More...
 

Detailed Description

MsgHandler

Definition at line 38 of file MsgHandler.h.

Member Typedef Documentation

◆ Factory

typedef MsgHandler*(* MsgHandler::Factory) (MsgType)
private

Definition at line 59 of file MsgHandler.h.

Member Enumeration Documentation

◆ MsgType

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.

MT_DEBUG 

The message is an debug.

MT_GLDEBUG 

The message is an debug.

Definition at line 45 of file MsgHandler.h.

Constructor & Destructor Documentation

◆ MsgHandler() [1/2]

MsgHandler::MsgHandler ( MsgType  type)
protected

◆ ~MsgHandler()

MsgHandler::~MsgHandler ( )
protectedvirtual

destructor

Definition at line 274 of file MsgHandler.cpp.

◆ MsgHandler() [2/2]

MsgHandler::MsgHandler ( const MsgHandler s)
privatedelete

invalid copy constructor

Member Function Documentation

◆ _informf() [1/2]

void MsgHandler::_informf ( const char *  format)
inlineprotected

Definition at line 190 of file MsgHandler.h.

References inform().

Referenced by _informf(), and informf().

◆ _informf() [2/2]

template<typename T , typename... Targs>
void MsgHandler::_informf ( const char *  format,
value,
Targs...  Fargs 
)
inlineprotected

adds a new formatted message

Definition at line 197 of file MsgHandler.h.

References _informf().

◆ addRetriever()

void MsgHandler::addRetriever ( OutputDevice retriever)
virtual

◆ beginProcessMsg()

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

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.

Reimplemented in MsgHandlerSynchronized.

Definition at line 135 of file MsgHandler.cpp.

References build(), myAmProcessingProcess, myRetrievers, and myWasInformed.

Referenced by MsgHandlerSynchronized::beginProcessMsg().

◆ build()

std::string MsgHandler::build ( const std::string &  msg,
bool  addType 
)
inlineprotected

Builds the string which includes the mml-message type.

Definition at line 166 of file MsgHandler.h.

References MT_DEBUG, MT_ERROR, MT_GLDEBUG, MT_MESSAGE, MT_WARNING, and myType.

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

◆ cleanupOnEnd()

void MsgHandler::cleanupOnEnd ( )
static

Removes pending handler.

Definition at line 250 of file MsgHandler.cpp.

References myDebugInstance, myErrorInstance, myGLDebugInstance, myMessageInstance, and myWarningInstance.

Referenced by SystemFrame::close(), GUIRunThread::deleteSim(), and setFactory().

◆ clear()

void MsgHandler::clear ( )
virtual

◆ enableDebugGLMessages()

void MsgHandler::enableDebugGLMessages ( bool  enable)
static

enable/disable gl-debug messages

Definition at line 113 of file MsgHandler.cpp.

References myWriteDebugGLMessages.

Referenced by GUIDialog_Options::InputBool::onCmdSetOption(), and GNELoadThread::run().

◆ enableDebugMessages()

void MsgHandler::enableDebugMessages ( bool  enable)
static

enable/disable debug messages

Definition at line 108 of file MsgHandler.cpp.

References myWriteDebugMessages.

Referenced by GUIDialog_Options::InputBool::onCmdSetOption(), and GNELoadThread::run().

◆ endProcessMsg()

void MsgHandler::endProcessMsg ( std::string  msg)
virtual

◆ getDebugInstance()

MsgHandler * MsgHandler::getDebugInstance ( )
static

◆ getErrorInstance()

◆ getGLDebugInstance()

MsgHandler * MsgHandler::getGLDebugInstance ( )
static

◆ getMessageInstance()

◆ getWarningInstance()

◆ inform()

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

adds a new error to the list

Reimplemented in MsgHandlerSynchronized.

Definition at line 118 of file MsgHandler.cpp.

References build(), getMessageInstance(), inform(), myAmProcessingProcess, myRetrievers, and myWasInformed.

Referenced by _informf(), RORouteHandler::addPersonTrip(), NLHandler::addPhase(), ROVehicle::addStop(), RORouteHandler::addStop(), MSSOTLTrafficLightLogic::checkPhases(), clear(), RORouteHandler::closeFlow(), RORouteHandler::closeRoute(), RORouteHandler::closeRouteDistribution(), RORouteHandler::closeVehicle(), RORouteHandler::closeVehicleTypeDistribution(), ROJTRRouter::compute(), DijkstraRouter< E, V >::compute(), AStarRouter< E, V >::compute(), ROPerson::computeIntermodal(), ROVehicle::computeRoute(), MSDeterministicHiLevelTrafficLightLogic::decideNextPhase(), MSSwarmTrafficLightLogic::decideNextPhase(), MsgHandlerSynchronized::inform(), inform(), GUIRunThread::init(), main(), GUIRunThread::makeStep(), MSPhaseDefinition::MSPhaseDefinition(), MSSOTLPhaseTrafficLightLogic::MSSOTLPhaseTrafficLightLogic(), MSSOTLPolicyBasedTrafficLightLogic::MSSOTLPolicyBasedTrafficLightLogic(), MSSOTLWaveTrafficLightLogic::MSSOTLWaveTrafficLightLogic(), NIXMLConnectionsHandler::myStartElement(), RORouteHandler::myStartElement(), RORouteHandler::openRoute(), RORouteHandler::openRouteDistribution(), RORouteHandler::openVehicleTypeDistribution(), NIXMLConnectionsHandler::parseConnection(), NIXMLConnectionsHandler::parseDeprecatedLaneDefinition(), RORouteHandler::parseEdges(), RORouteHandler::parseFromViaTo(), RORouteHandler::parseGeoEdges(), NIXMLConnectionsHandler::parseLaneBound(), SUMORouteHandler::parseStop(), RORouteDef::preComputeCurrentRoute(), RORouteDef::repairCurrentRoute(), GUILoadThread::run(), MSSOTLTrafficLightLogic::setToATargetPhase(), and TraCIServer::TraCIServer().

◆ informf()

template<typename T , typename... Targs>
void MsgHandler::informf ( const std::string &  format,
value,
Targs...  Fargs 
)
inline

◆ initOutputOptions()

◆ isRetriever()

bool MsgHandler::isRetriever ( OutputDevice retriever) const

Returns whether the given output device retrieves messages from the handler.

Definition at line 191 of file MsgHandler.cpp.

References myRetrievers.

Referenced by addRetriever().

◆ operator<<()

template<class T >
MsgHandler& MsgHandler::operator<< ( const T &  t)
inline

Generic output operator.

Returns
The MsgHandler for further processing

Definition at line 156 of file MsgHandler.h.

References myRetrievers.

◆ operator=()

MsgHandler& MsgHandler::operator= ( const MsgHandler s)
privatedelete

invalid assignment operator

◆ removeRetriever()

◆ removeRetrieverFromAllInstances()

void MsgHandler::removeRetrieverFromAllInstances ( OutputDevice out)
static

ensure that that given output device is no longer used as retriever by any instance

Definition at line 197 of file MsgHandler.cpp.

References myDebugInstance, myErrorInstance, myGLDebugInstance, myMessageInstance, myWarningInstance, and removeRetriever().

Referenced by OutputDevice::close().

◆ setAggregationThreshold()

void MsgHandler::setAggregationThreshold ( const int  thresh)
inlineprotected

Definition at line 208 of file MsgHandler.h.

References myAggregationThreshold.

Referenced by initOutputOptions().

◆ setFactory()

static void MsgHandler::setFactory ( Factory  func)
inlinestatic

Sets the factory function to use for new MsgHandlers.

Definition at line 63 of file MsgHandler.h.

References cleanupOnEnd(), and myFactory.

Referenced by NLBuilder::init(), and main().

◆ wasInformed()

bool MsgHandler::wasInformed ( ) const

Returns the information whether any messages were added.

Definition at line 279 of file MsgHandler.cpp.

References myWasInformed.

Referenced by ROLoader::processRoutes(), and XMLSubSys::runParser().

◆ writeDebugGLMessages()

static bool MsgHandler::writeDebugGLMessages ( )
inlinestatic

check whether to enable/disable gl-debug messages

Definition at line 96 of file MsgHandler.h.

References myWriteDebugGLMessages.

Referenced by SUMORTree::addAdditionalGLObject(), and SUMORTree::removeAdditionalGLObject().

◆ writeDebugMessages()

static bool MsgHandler::writeDebugMessages ( )
inlinestatic

check whether to enable/disable debug messages

Definition at line 91 of file MsgHandler.h.

References myWriteDebugMessages.

Field Documentation

◆ myAggregationCount

std::map<const std::string, int> MsgHandler::myAggregationCount
private

count for messages of the same type

Definition at line 251 of file MsgHandler.h.

Referenced by clear(), and informf().

◆ myAggregationThreshold

int MsgHandler::myAggregationThreshold
private

do not output more messages of the same type if the count exceeds this threshold

Definition at line 248 of file MsgHandler.h.

Referenced by clear(), informf(), and setAggregationThreshold().

◆ myAmProcessingProcess

bool MsgHandler::myAmProcessingProcess = false
staticprivate

Information whether a process information is printed to cout.

Definition at line 238 of file MsgHandler.h.

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

◆ myDebugInstance

MsgHandler * MsgHandler::myDebugInstance = nullptr
staticprivate

The instance to handle debug.

Definition at line 223 of file MsgHandler.h.

Referenced by cleanupOnEnd(), getDebugInstance(), and removeRetrieverFromAllInstances().

◆ myErrorInstance

MsgHandler * MsgHandler::myErrorInstance = nullptr
staticprivate

The instance to handle errors.

Definition at line 229 of file MsgHandler.h.

Referenced by cleanupOnEnd(), getErrorInstance(), and removeRetrieverFromAllInstances().

◆ myFactory

MsgHandler::Factory MsgHandler::myFactory = nullptr
staticprivate

The function to call for new MsgHandlers, nullptr means use default constructor.

Definition at line 220 of file MsgHandler.h.

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

◆ myGLDebugInstance

MsgHandler * MsgHandler::myGLDebugInstance = nullptr
staticprivate

The instance to handle glDebug.

Definition at line 226 of file MsgHandler.h.

Referenced by cleanupOnEnd(), getGLDebugInstance(), and removeRetrieverFromAllInstances().

◆ myMessageInstance

MsgHandler * MsgHandler::myMessageInstance = nullptr
staticprivate

The instance to handle normal messages.

Definition at line 235 of file MsgHandler.h.

Referenced by cleanupOnEnd(), getMessageInstance(), and removeRetrieverFromAllInstances().

◆ myRetrievers

std::vector<OutputDevice*> MsgHandler::myRetrievers
private

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

Definition at line 254 of file MsgHandler.h.

Referenced by addRetriever(), beginProcessMsg(), endProcessMsg(), inform(), isRetriever(), operator<<(), and removeRetriever().

◆ myType

MsgType MsgHandler::myType
private

The type of the instance.

Definition at line 242 of file MsgHandler.h.

Referenced by build().

◆ myWarningInstance

MsgHandler * MsgHandler::myWarningInstance = nullptr
staticprivate

The instance to handle warnings.

Definition at line 232 of file MsgHandler.h.

Referenced by cleanupOnEnd(), getWarningInstance(), and removeRetrieverFromAllInstances().

◆ myWasInformed

bool MsgHandler::myWasInformed
private

information whether an output occurred at all

Definition at line 245 of file MsgHandler.h.

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

◆ myWriteDebugGLMessages

bool MsgHandler::myWriteDebugGLMessages
staticprivate

Definition at line 268 of file MsgHandler.h.

Referenced by enableDebugGLMessages(), and writeDebugGLMessages().

◆ myWriteDebugMessages

bool MsgHandler::myWriteDebugMessages
staticprivate

Flag to enable or disable debug GL Functions.

This value is used to show more internal information throught warning messages about certain operations

Definition at line 267 of file MsgHandler.h.

Referenced by enableDebugMessages(), and writeDebugMessages().


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