SUMO - Simulation of Urban MObility

OutputDevice Class Reference

Static storage of an output device and its base (abstract) implementation. More...

#include <OutputDevice.h>

Inheritance diagram for OutputDevice:
MsgRetrievingFunction< T > OutputDevice_COUT OutputDevice_File OutputDevice_Network OutputDevice_String

Static Public Member Functions

static std::string realString (const SUMOReal v, const int precision=OUTPUT_ACCURACY)
 Abstract output operator.
static access methods to OutputDevices
static OutputDevice & getDevice (const std::string &name, const std::string &base="")
 Returns the described OutputDevice.
static bool createDeviceByOption (const std::string &optionName, const std::string &rootElement="")
 Creates the device using the output definition stored in the named option.
static OutputDevice & getDeviceByOption (const std::string &name) throw (IOError, InvalidArgument)
 Returns the device described by the option.
static void closeAll ()

Private Attributes

Non-static members of each OutputDevice
std::vector< std::string > myXMLStack
 The stack of begun xml elements.
unsigned int myDefaultIndentation
 The initial indentation level.

OutputDevice member methods

 OutputDevice (const unsigned int defaultIndentation=0)
 Constructor.
virtual ~OutputDevice ()
 Destructor.
virtual bool ok ()
 returns the information whether one can write into the device
void close ()
 Closes the device and removes it from the dictionary.
void setPrecision (unsigned int precision=OUTPUT_ACCURACY)
 Sets the precison or resets it to default.
bool writeXMLHeader (const std::string &rootElement, const std::string xmlParams="", const std::string &attrs="", const std::string &comment="")
 Writes an XML header with optional configuration.
OutputDevice & indent ()
 Adds indentation.
OutputDevice & openTag (const std::string &xmlElement)
 Opens an XML tag.
OutputDevice & openTag (const SumoXMLTag &xmlElement)
 Opens an XML tag.
bool closeTag (bool abbreviated=false)
 Closes the most recently opened tag.
OutputDevice & writeAttr (std::string attr, std::string val)
 writes an arbitrary attribute
template<class T >
OutputDevice & writeAttr (const SumoXMLAttr attr, const T &val)
 writes an named attribute
void inform (const std::string &msg)
 Retrieves a message to this device.
template<class T >
OutputDevice & operator<< (const T &t)
 Abstract output operator.
virtual std::ostream & getOStream ()=0
 Returns the associated ostream.
virtual void postWriteHook ()
 Called after every write access.

static members

typedef std::map< std::string,
OutputDevice * > 
DeviceMap
 Definition of a map from names to output devices.
static DeviceMap myOutputDevices
 map from names to output devices

Detailed Description

Static storage of an output device and its base (abstract) implementation.

OutputDevices are basically a capsule around an std::ostream, which give a unified access to sockets, files and stdout.

Usually, an application builds as many output devices as needed. Each output device may also be used to save outputs from several sources (several detectors, for example). Building is done using OutputDevice::getDevice() what also parses the given output description in order to decide what kind of an OutputDevice shall be built. OutputDevices are closed via OutputDevice::closeAll(), normally called at the application's end.

Although everything that can be written to a stream can also be written to an OutputDevice, there is special support for XML tags (remembering all open tags to close them at the end). OutputDevices are still lacking support for function pointers with the '<<' operator (no endl, use '
'). The most important method to implement in subclasses is getOStream, the most used part of the interface is the '<<' operator.

The Boolean markers are used rarely and might get removed in future versions.

Definition at line 70 of file OutputDevice.h.


Member Typedef Documentation

typedef std::map<std::string, OutputDevice*> OutputDevice::DeviceMap [private]

Definition of a map from names to output devices.

Definition at line 284 of file OutputDevice.h.


Constructor & Destructor Documentation

OutputDevice::OutputDevice ( const unsigned int  defaultIndentation = 0)

Constructor.

Definition at line 148 of file OutputDevice.cpp.

virtual OutputDevice::~OutputDevice ( ) [inline, virtual]

Destructor.

Definition at line 148 of file OutputDevice.h.


Member Function Documentation

void OutputDevice::closeAll ( ) [static]

Closes all registered devices

Definition at line 119 of file OutputDevice.cpp.

References myOutputDevices.

Referenced by GUIRunThread::deleteSim(), and main().

bool OutputDevice::closeTag ( bool  abbreviated = false)

Closes the most recently opened tag.

The topmost xml-element from the stack is written into the stream as a closing element ("</" + element + ">") and is then removed from the stack. If abbreviated closing is requested, only "/>" is the output.

Parameters:
[in]namewhether abbreviated closing is performed
Returns:
Whether a further element existed in the stack and could be closed
Todo:
it is not verified that the topmost element was closed

Definition at line 221 of file OutputDevice.cpp.

References getOStream(), indent(), myDefaultIndentation, myXMLStack, and postWriteHook().

Referenced by close(), MSPersonControl::erase(), MSDevice_Vehroutes::generateOutput(), PCPolyContainer::save(), ROVehicle::saveAllAsXML(), MSVehicleControl::scheduleVehicleRemoval(), SUMOVTypeParameter::write(), ODMatrix::write(), MSXMLRawOut::write(), MSInstantInductLoop::write(), NWWriter_SUMO::writeConnection(), NWWriter_SUMO::writeDistrict(), NWWriter_SUMO::writeEdge(), MSXMLRawOut::writeEdge(), MSMeanData::writeEdge(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), NWWriter_SUMO::writeInternalConnection(), NWWriter_SUMO::writeInternalEdge(), NWWriter_SUMO::writeInternalNodes(), NWWriter_SUMO::writeLane(), MSXMLRawOut::writeLane(), NBRequest::writeLaneResponse(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), NWWriter_SUMO::writeProhibitions(), NWWriter_SUMO::writeRoundabout(), NWWriter_SUMO::writeTrafficLights(), MSXMLRawOut::writeVehicle(), RORouteDef_Complete::writeXMLDefinition(), RORouteDef_Alternatives::writeXMLDefinition(), RORoute::writeXMLDefinition(), MSRouteProbe::writeXMLOutput(), and MSMeanData::writeXMLOutput().

bool OutputDevice::createDeviceByOption ( const std::string &  optionName,
const std::string &  rootElement = "" 
) [static]

Creates the device using the output definition stored in the named option.

Creates and returns the device named by the option. Asks whether the option and retrieves the name from the option if so. Optionally the XML header gets written as well. Returns whether a device was created (option was set).

Please note, that we do not have to consider the "application base" herein, because this call is only used to get file names of files referenced within XML-declarations of structures which paths already is aware of the cwd.

Parameters:
[in]optionNameThe name of the option to use for retrieving the output definition
[in]rootElementThe root element to use (XML-output)
Returns:
Whether a device was built (the option was set)
Exceptions:
IOErrorIf the output could not be built for any reason (error message is supplied)

Definition at line 95 of file OutputDevice.cpp.

References getDevice(), OptionsCont::getOptions(), and writeXMLHeader().

Referenced by MSFrame::buildStreams(), MSDevice_Vehroutes::init(), and main().

OutputDevice & OutputDevice::getDevice ( const std::string &  name,
const std::string &  base = "" 
) [static]

Returns the described OutputDevice.

Creates and returns the named device. "stdout" and "-" refer to standard out, "hostname:port" initiates socket connection. Otherwise a filename is assumed and the second parameter may be used to give a base directory. If there already is a device with the same name this one is returned.

Parameters:
[in]nameThe description of the output name/port/whatever
[in]baseThe base path the application is run within
Returns:
The corresponding (built or existing) device
Exceptions:
IOErrorIf the output could not be built for any reason (error message is supplied)

Definition at line 64 of file OutputDevice.cpp.

References FileHelpers::checkForRelativity(), getOStream(), FileHelpers::isSocket(), myOutputDevices, and setPrecision().

Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addInstantE1Detector(), NLHandler::addRouteProbeDetector(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), createDeviceByOption(), getDeviceByOption(), MsgHandler::initOutputOptions(), GUIDialog_ViewSettings::onCmdExportSetting(), GUIParameterTracker::onCmdSave(), GUIDialog_EditViewport::onCmdSave(), GUIDialog_Breakpoints::onCmdSave(), RONet::openOutput(), RODFDetectorCon::save(), PCPolyContainer::save(), GUISelectedStorage::save(), RODFDetectorCon::saveAsPOIs(), GUIDialog_ViewSettings::saveDecals(), RODFDetectorCon::saveRoutes(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), NWWriter_SUMO::writeNetwork(), NWWriter_OpenDrive::writeNetwork(), NWWriter_MATSim::writeNetwork(), NWFrame::writeNetwork(), NWWriter_XML::writeNodes(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), NWWriter_XML::writeTrafficLights(), and RODFDetectorCon::writeValidationDetectors().

OutputDevice & OutputDevice::getDeviceByOption ( const std::string &  name) throw (IOError, InvalidArgument) [static]

Returns the device described by the option.

Returns the device named by the option. If the option is unknown, unset or the device was not created before, InvalidArgument is thrown.

Please note, that we do not have to consider the "application base" herein.

Parameters:
[in]nameThe name of the option to use for retrieving the output definition
Returns:
The corresponding (built or existing) device
Exceptions:
IOErrorIf the output could not be built for any reason (error message is supplied)
InvalidArgumentIf the option with the given name does not exist

Definition at line 109 of file OutputDevice.cpp.

References getDevice(), OptionsCont::getOptions(), and OptionsCont::getString().

Referenced by MSPersonControl::erase(), MSDevice_Vehroutes::generateOutput(), MSDevice_Tripinfo::generateOutput(), MSDevice_HBEFA::generateOutput(), main(), MSVehicleControl::scheduleVehicleRemoval(), and MSNet::writeOutput().

virtual std::ostream& OutputDevice::getOStream ( ) [protected, pure virtual]
OutputDevice & OutputDevice::indent ( )

Adds indentation.

An intendation, depending on the current xml-element-stack size, is written.

Returns:
The OutputDevice for further processing

Definition at line 198 of file OutputDevice.cpp.

References getOStream(), myDefaultIndentation, myXMLStack, and postWriteHook().

Referenced by closeTag(), and MSMeanData::writePrefix().

void OutputDevice::inform ( const std::string &  msg)

Retrieves a message to this device.

Implementation of the MessageRetriever interface. Writes the given message to the output device.

Parameters:
[in]msgThe msg to write to the device

Definition at line 242 of file OutputDevice.cpp.

References getOStream(), and postWriteHook().

bool OutputDevice::ok ( ) [virtual]

returns the information whether one can write into the device

Returns:
Whether the device can be used (stream is good)

Definition at line 154 of file OutputDevice.cpp.

References getOStream().

OutputDevice & OutputDevice::openTag ( const std::string &  xmlElement)

Opens an XML tag.

An indentation, depending on the current xml-element-stack size, is written followed by the given xml element ("<" + xmlElement) The xml element is added to the stack, then.

Parameters:
[in]xmlElementName of element to open
Returns:
The OutputDevice for further processing

Definition at line 206 of file OutputDevice.cpp.

References getOStream(), myDefaultIndentation, myXMLStack, and postWriteHook().

Referenced by MSPersonControl::erase(), MSDevice_Vehroutes::generateOutput(), MSDevice_Tripinfo::generateOutput(), MSDevice_HBEFA::generateOutput(), openTag(), PCPolyContainer::save(), MSPerson::MSPersonStage_Waiting::tripInfoOutput(), MSPerson::MSPersonStage_Driving::tripInfoOutput(), MSPerson::MSPersonStage_Walking::tripInfoOutput(), SUMOVTypeParameter::write(), ODMatrix::write(), MSXMLRawOut::write(), MSInstantInductLoop::write(), SUMOVehicleParameter::writeAs(), NWWriter_SUMO::writeConnection(), NWWriter_SUMO::writeDistrict(), NWWriter_SUMO::writeEdge(), MSXMLRawOut::writeEdge(), MSMeanData::writeEdge(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), NWWriter_SUMO::writeInternalConnection(), NWWriter_SUMO::writeInternalEdge(), NWWriter_SUMO::writeInternalNodes(), NWWriter_SUMO::writeJunction(), NWWriter_SUMO::writeLane(), MSXMLRawOut::writeLane(), NBRequest::writeLaneResponse(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), NWWriter_SUMO::writeProhibitions(), NWWriter_SUMO::writeRoundabout(), NWWriter_SUMO::writeTrafficLights(), MSXMLRawOut::writeVehicle(), RORouteDef_Complete::writeXMLDefinition(), RORouteDef_Alternatives::writeXMLDefinition(), RORoute::writeXMLDefinition(), writeXMLHeader(), MSRouteProbe::writeXMLOutput(), MSMeanData::writeXMLOutput(), and MSDevice_Vehroutes::writeXMLRoute().

OutputDevice & OutputDevice::openTag ( const SumoXMLTag &  xmlElement)

Opens an XML tag.

Helper method which finds the correct string before calling openTag.

Parameters:
[in]xmlElementId of the element to open
Returns:
The OutputDevice for further processing

Definition at line 215 of file OutputDevice.cpp.

References openTag(), and toString().

template<class T >
OutputDevice& OutputDevice::operator<< ( const T &  t) [inline]

Abstract output operator.

Returns:
The OutputDevice for further processing

Definition at line 261 of file OutputDevice.h.

References getOStream(), and postWriteHook().

void OutputDevice::postWriteHook ( ) [protected, virtual]

Called after every write access.

Default implementation does nothing.

Reimplemented in MsgRetrievingFunction< T >, and OutputDevice_Network.

Definition at line 238 of file OutputDevice.cpp.

Referenced by closeTag(), indent(), inform(), openTag(), and operator<<().

std::string OutputDevice::realString ( const SUMOReal  v,
const int  precision = OUTPUT_ACCURACY 
) [static]

Abstract output operator.

Returns:
The OutputDevice for further processing

Definition at line 128 of file OutputDevice.cpp.

Referenced by MSDevice_HBEFA::generateOutput(), and MSMeanData_HBEFA::MSLaneMeanDataValues::write().

void OutputDevice::setPrecision ( unsigned int  precision = OUTPUT_ACCURACY)

Sets the precison or resets it to default.

Parameters:
[in]precisionThe accuracy (number of digits behind '.') to set

Definition at line 173 of file OutputDevice.cpp.

References getOStream().

Referenced by MSVTypeProbe::execute(), getDevice(), NWWriter_XML::writeEdgesAndConnections(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), RORouteDef_Alternatives::writeXMLDefinition(), and RORoute::writeXMLDefinition().

template<class T >
OutputDevice& OutputDevice::writeAttr ( const SumoXMLAttr  attr,
const T &  val 
) [inline]

writes an named attribute

Parameters:
[in]attrThe attribute (name)
[in]valThe attribute value

Definition at line 243 of file OutputDevice.h.

References getOStream(), toString(), and writeAttr().

bool OutputDevice::writeXMLHeader ( const std::string &  rootElement,
const std::string  xmlParams = "",
const std::string &  attrs = "",
const std::string &  comment = "" 
)

Writes an XML header with optional configuration.

If something has been written (myXMLStack is not empty), nothing is written and false returned.

Parameters:
[in]rootElementThe root element to use
[in]xmlParamsAdditional parameters (such as encoding) to include in the <?xml> declaration
[in]attrsAdditional attributes to save within the rootElement
[in]commentAdditional comment (saved in front the rootElement)
Todo:

Check which parameter is used herein

Describe what is saved

Definition at line 179 of file OutputDevice.cpp.

References OptionsCont::getOptions(), getOStream(), myXMLStack, openTag(), and OptionsCont::writeXMLHeader().

Referenced by Command_SaveTLSState::Command_SaveTLSState(), Command_SaveTLSSwitches::Command_SaveTLSSwitches(), Command_SaveTLSSwitchStates::Command_SaveTLSSwitchStates(), createDeviceByOption(), MSVTypeProbe::MSVTypeProbe(), RONet::openOutput(), RODFDetectorCon::save(), PCPolyContainer::save(), RODFDetectorCon::saveAsPOIs(), RODFDetectorCon::saveRoutes(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), NWWriter_SUMO::writeNetwork(), NWWriter_XML::writeNodes(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), NWWriter_XML::writeTrafficLights(), RODFDetectorCon::writeValidationDetectors(), MSRouteProbe::writeXMLDetectorProlog(), MSMeanData::writeXMLDetectorProlog(), MSInstantInductLoop::writeXMLDetectorProlog(), MSInductLoop::writeXMLDetectorProlog(), MSE3Collector::writeXMLDetectorProlog(), MSE2Collector::writeXMLDetectorProlog(), and MS_E2_ZS_CollectorOverLanes::writeXMLDetectorProlog().


Field Documentation

unsigned int OutputDevice::myDefaultIndentation [private]

The initial indentation level.

Definition at line 299 of file OutputDevice.h.

Referenced by closeTag(), indent(), and openTag().

map from names to output devices

Definition at line 287 of file OutputDevice.h.

Referenced by close(), closeAll(), and getDevice().

std::vector<std::string> OutputDevice::myXMLStack [private]

The stack of begun xml elements.

Definition at line 296 of file OutputDevice.h.

Referenced by closeTag(), indent(), openTag(), and writeXMLHeader().


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