SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OutputDevice_File Class Reference

An output device that encapsulates an ofstream. More...

#include <OutputDevice_File.h>

Inheritance diagram for OutputDevice_File:
OutputDevice

Public Member Functions

 OutputDevice_File (const std::string &fullName, const bool binary)
 Constructor. More...
 
 ~OutputDevice_File ()
 Destructor. More...
 

Static Public Member Functions

static std::string realString (const SUMOReal v, const int precision=OUTPUT_ACCURACY)
 Helper method for string formatting. More...
 
static access methods to OutputDevices
static OutputDevicegetDevice (const std::string &name)
 Returns the described OutputDevice. More...
 
static bool createDeviceByOption (const std::string &optionName, const std::string &rootElement="")
 Creates the device using the output definition stored in the named option. More...
 
static OutputDevicegetDeviceByOption (const std::string &name) throw (IOError, InvalidArgument)
 Returns the device described by the option. More...
 
static void closeAll ()
 

Protected Member Functions

Methods that override/implement OutputDevice-methods
std::ostream & getOStream ()
 Returns the associated ostream. More...
 

Private Attributes

std::ofstream * myFileStream
 The wrapped ofstream. More...
 

OutputDevice member methods

virtual bool ok ()
 returns the information whether one can write into the device More...
 
void close ()
 Closes the device and removes it from the dictionary. More...
 
void setPrecision (unsigned int precision=OUTPUT_ACCURACY)
 Sets the precison or resets it to default. More...
 
bool writeXMLHeader (const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
 Writes an XML header with optional configuration. More...
 
template<typename E >
bool writeHeader (const SumoXMLTag &rootElement)
 
OutputDeviceopenTag (const std::string &xmlElement)
 Opens an XML tag. More...
 
OutputDeviceopenTag (const SumoXMLTag &xmlElement)
 Opens an XML tag. More...
 
bool closeTag ()
 Closes the most recently opened tag. More...
 
OutputDevicewriteAttr (std::string attr, std::string val)
 writes an arbitrary attribute More...
 
template<typename T >
OutputDevicewriteAttr (const SumoXMLAttr attr, const T &val)
 writes a named attribute More...
 
void lf ()
 writes a line feed if applicable More...
 
bool isBinary () const
 Returns whether we have a binary output. More...
 
void inform (const std::string &msg, const char progress=0)
 Retrieves a message to this device. More...
 
template<class T >
OutputDeviceoperator<< (const T &t)
 Abstract output operator. More...
 
virtual void postWriteHook ()
 Called after every write access. More...
 

Detailed Description

An output device that encapsulates an ofstream.

Please note that the device gots responsible for the stream and deletes it (it should not be deleted elsewhere).

Definition at line 48 of file OutputDevice_File.h.

Constructor & Destructor Documentation

OutputDevice_File::OutputDevice_File ( const std::string &  fullName,
const bool  binary 
)

Constructor.

Parameters
[in]strmThe output stream to used
Exceptions
IOErrorShould not be thrown by this implementation

Definition at line 44 of file OutputDevice_File.cpp.

References myFileStream.

OutputDevice_File::~OutputDevice_File ( )

Destructor.

Definition at line 63 of file OutputDevice_File.cpp.

References myFileStream.

Member Function Documentation

void OutputDevice::closeAll ( )
staticinherited

Closes all registered devices

Definition at line 126 of file OutputDevice.cpp.

References OutputDevice::myOutputDevices.

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

bool OutputDevice::closeTag ( )
inherited

Closes the most recently opened tag.

The topmost xml-element from the stack is written into the stream as a closing element. Depending on the formatter used this may be something like "</" + element + ">" or "/>" or nothing at all.

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 217 of file OutputDevice.cpp.

References OutputFormatter::closeTag(), OutputDevice::getOStream(), OutputDevice::myFormatter, and OutputDevice::postWriteHook().

Referenced by RORouteHandler::addStop(), OutputDevice::close(), RORouteHandler::closePerson(), MSPersonControl::erase(), MSVTypeProbe::execute(), RORouteHandler::myStartElement(), RODFRouteCont::save(), PCPolyContainer::save(), RODFDetectorCon::save(), ROVehicle::saveAllAsXML(), MSVehicleControl::scheduleVehicleRemoval(), MSVTKExport::write(), MSFCDExport::write(), MSEmissionExport::write(), MSQueueExport::write(), MSFullExport::write(), MSXMLRawOut::write(), SUMOVTypeParameter::write(), MSMeanData_HBEFA::MSLaneMeanDataValues::write(), MSMeanData_Harmonoise::MSLaneMeanDataValues::write(), MSMeanData_Net::MSLaneMeanDataValues::write(), ODMatrix::write(), MSInstantInductLoop::write(), NBSign::writeAsPOI(), NWWriter_SUMO::writeConnection(), NWWriter_SUMO::writeDistrict(), MSQueueExport::writeEdge(), MSFullExport::writeEdge(), MSXMLRawOut::writeEdge(), NWWriter_SUMO::writeEdge(), MSMeanData::writeEdge(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitters(), ODMatrix::writeFlows(), NWWriter_SUMO::writeInternalConnection(), NWWriter_SUMO::writeInternalEdge(), NWWriter_SUMO::writeInternalNodes(), NWWriter_XML::writeJoinedJunctions(), NWWriter_SUMO::writeJunction(), MSQueueExport::writeLane(), MSFullExport::writeLane(), MSXMLRawOut::writeLane(), NWWriter_SUMO::writeLane(), NBRequest::writeLaneResponse(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), NWWriter_SUMO::writeProhibitions(), NWWriter_SUMO::writeRoundabout(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), SUMOVehicleParameter::writeStops(), MSFullExport::writeTLS(), NWWriter_SUMO::writeTrafficLights(), RODFDetectorCon::writeValidationDetectors(), MSXMLRawOut::writeVehicle(), MSFullExport::writeVehicles(), RORouteDef::writeXMLDefinition(), RORoute::writeXMLDefinition(), MSRouteProbe::writeXMLOutput(), and MSMeanData::writeXMLOutput().

bool OutputDevice::createDeviceByOption ( const std::string &  optionName,
const std::string &  rootElement = "" 
)
staticinherited

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 98 of file OutputDevice.cpp.

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

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

OutputDevice & OutputDevice::getDevice ( const std::string &  name)
staticinherited

Returns the described OutputDevice.

Creates and returns the named device. "stdout" and "stderr" refer to the relevant console streams, "hostname:port" initiates socket connection. Otherwise a filename is assumed (where "nul" and "/dev/null" do what you would expect on both platforms). If there already is a device with the same name this one is returned.

Parameters
[in]nameThe description of the output name/port/whatever
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 65 of file OutputDevice.cpp.

References TplConvert::_2int(), OutputDevice_COUT::getDevice(), OutputDevice_CERR::getDevice(), OutputDevice::getOStream(), FileHelpers::isSocket(), OutputDevice::myOutputDevices, and OutputDevice::setPrecision().

Referenced by MSDetectorControl::add(), NLDetectorBuilder::buildE2Detector(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), NLDetectorBuilder::buildVTypeProbe(), OutputDevice::createDeviceByOption(), GUIDetectorBuilder::createInstantInductLoop(), NLDetectorBuilder::createInstantInductLoop(), OutputDevice::getDeviceByOption(), MsgHandler::initOutputOptions(), MSCalibrator::MSCalibrator(), MsgHandler::MsgHandler(), GUIDialog_ViewSettings::onCmdExportSetting(), GUIDialog_Breakpoints::onCmdSave(), GUIDialog_EditViewport::onCmdSave(), GUIParameterTracker::onCmdSave(), RONet::openOutput(), GUILoadThread::run(), PCPolyContainer::save(), RODFDetectorCon::save(), GUISelectedStorage::save(), RODFDetectorCon::saveAsPOIs(), GUIDialog_ViewSettings::saveDecals(), RODFDetectorCon::saveRoutes(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), NWWriter_XML::writeJoinedJunctions(), NWWriter_DlrNavteq::writeLinksUnsplitted(), NWWriter_OpenDrive::writeNetwork(), NWFrame::writeNetwork(), NWWriter_MATSim::writeNetwork(), NWWriter_SUMO::writeNetwork(), NWWriter_XML::writeNodes(), NWWriter_DlrNavteq::writeNodesUnsplitted(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), NWWriter_XML::writeStreetSigns(), NWWriter_XML::writeTrafficLights(), and RODFDetectorCon::writeValidationDetectors().

OutputDevice & OutputDevice::getDeviceByOption ( const std::string &  name) throw (IOError, InvalidArgument)
staticinherited

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 116 of file OutputDevice.cpp.

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

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

std::ostream & OutputDevice_File::getOStream ( )
protectedvirtual

Returns the associated ostream.

Returns
The used stream

Implements OutputDevice.

Definition at line 70 of file OutputDevice_File.cpp.

References myFileStream.

void OutputDevice::inform ( const std::string &  msg,
const char  progress = 0 
)
inherited

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 231 of file OutputDevice.cpp.

References OutputDevice::getOStream(), and OutputDevice::postWriteHook().

bool OutputDevice::isBinary ( ) const
inlineinherited

Returns whether we have a binary output.

Returns
whether we have a binary output

Definition at line 249 of file OutputDevice.h.

References OutputDevice::myAmBinary.

Referenced by MSDevice_Vehroutes::generateOutput().

void OutputDevice::lf ( )
inlineinherited
bool OutputDevice::ok ( )
virtualinherited

returns the information whether one can write into the device

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

Definition at line 171 of file OutputDevice.cpp.

References OutputDevice::getOStream().

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

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 203 of file OutputDevice.cpp.

References OutputDevice::getOStream(), OutputDevice::myFormatter, and OutputFormatter::openTag().

Referenced by RORouteHandler::addStop(), MSPerson::MSPersonStage_Walking::beginEventOutput(), MSPerson::MSPersonStage_Driving::beginEventOutput(), MSPerson::MSPersonStage_Waiting::beginEventOutput(), MSPerson::MSPersonStage_Walking::endEventOutput(), MSPerson::MSPersonStage_Driving::endEventOutput(), MSPerson::MSPersonStage_Waiting::endEventOutput(), MSPersonControl::erase(), MSVTypeProbe::execute(), MSDevice_HBEFA::generateOutput(), MSDevice_Vehroutes::generateOutput(), MSDevice_Tripinfo::generateOutput(), RORouteHandler::myStartElement(), RODFRouteCont::save(), PCPolyContainer::save(), RODFDetectorCon::save(), RODFDetectorCon::saveAsPOIs(), MSPerson::MSPersonStage_Walking::tripInfoOutput(), MSPerson::MSPersonStage_Driving::tripInfoOutput(), MSPerson::MSPersonStage_Waiting::tripInfoOutput(), MSVTKExport::write(), MSEmissionExport::write(), MSFCDExport::write(), MSQueueExport::write(), MSFullExport::write(), MSXMLRawOut::write(), SUMOVTypeParameter::write(), ODMatrix::write(), MSInstantInductLoop::write(), SUMOVehicleParameter::write(), NBSign::writeAsPOI(), NWWriter_SUMO::writeConnection(), NWWriter_SUMO::writeDistrict(), MSQueueExport::writeEdge(), MSFullExport::writeEdge(), MSXMLRawOut::writeEdge(), NWWriter_SUMO::writeEdge(), MSMeanData::writeEdge(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), ODMatrix::writeFlows(), NWWriter_SUMO::writeInternalConnection(), NWWriter_SUMO::writeInternalEdge(), NWWriter_SUMO::writeInternalNodes(), NWWriter_XML::writeJoinedJunctions(), NWWriter_SUMO::writeJunction(), MSQueueExport::writeLane(), MSFullExport::writeLane(), MSXMLRawOut::writeLane(), NWWriter_SUMO::writeLane(), NBRequest::writeLaneResponse(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), MSMeanData::writePrefix(), NWWriter_SUMO::writeProhibitions(), NWWriter_SUMO::writeRoundabout(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), SUMOVehicleParameter::writeStops(), MSFullExport::writeTLS(), NWWriter_SUMO::writeTrafficLights(), RODFDetectorCon::writeValidationDetectors(), MSXMLRawOut::writeVehicle(), MSFullExport::writeVehicles(), RORouteDef::writeXMLDefinition(), RORoute::writeXMLDefinition(), MSRouteProbe::writeXMLOutput(), MSMeanData::writeXMLOutput(), and MSDevice_Vehroutes::writeXMLRoute().

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

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 210 of file OutputDevice.cpp.

References OutputDevice::getOStream(), OutputDevice::myFormatter, and OutputFormatter::openTag().

template<class T >
OutputDevice& OutputDevice::operator<< ( const T &  t)
inlineinherited

Abstract output operator.

Returns
The OutputDevice for further processing

Definition at line 284 of file OutputDevice.h.

References OutputDevice::getOStream(), and OutputDevice::postWriteHook().

void OutputDevice::postWriteHook ( )
protectedvirtualinherited

Called after every write access.

Default implementation does nothing.

Reimplemented in GUIMessageWindow::MsgOutputDevice, OutputDevice_Network, MsgRetrievingFunction< T >, OutputDevice_CERR, and OutputDevice_COUT.

Definition at line 227 of file OutputDevice.cpp.

Referenced by OutputDevice::closeTag(), OutputDevice::inform(), and OutputDevice::operator<<().

std::string OutputDevice::realString ( const SUMOReal  v,
const int  precision = OUTPUT_ACCURACY 
)
staticinherited

Helper method for string formatting.

Parameters
[in]vThe floating point value to be formatted
[in]precisionthe precision to achieve
Returns
The formatted string

Definition at line 135 of file OutputDevice.cpp.

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

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

Sets the precison or resets it to default.

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

Definition at line 190 of file OutputDevice.cpp.

References OutputDevice::getOStream().

Referenced by MSVTypeProbe::execute(), OutputDevice::getDevice(), MSFCDExport::write(), NWWriter_XML::writeEdgesAndConnections(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), NWWriter_DlrNavteq::writeNodesUnsplitted(), and RORoute::writeXMLDefinition().

OutputDevice & OutputDevice::writeAttr ( std::string  attr,
std::string  val 
)
inherited

writes an arbitrary attribute

Parameters
[in]attrThe attribute (name)
[in]valThe attribute value
Returns
The OutputDevice for further processing

Definition at line 242 of file OutputDevice.cpp.

References OutputDevice::getOStream(), OutputDevice::myFormatter, and OutputFormatter::writeAttr().

Referenced by MSDevice_Vehroutes::generateOutput(), RONet::openOutput(), RODFRouteCont::save(), PCPolyContainer::save(), RODFDetectorCon::save(), RODFDetectorCon::saveAsPOIs(), MSFCDExport::write(), SUMOVTypeParameter::write(), ODMatrix::write(), MSInstantInductLoop::write(), SUMOVehicleParameter::write(), NBSign::writeAsPOI(), NWWriter_SUMO::writeConnection(), ODMatrix::writeDefaultAttrs(), NWWriter_SUMO::writeDistrict(), NWWriter_SUMO::writeEdge(), MSMeanData::writeEdge(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), ODMatrix::writeFlows(), NWWriter_SUMO::writeInternalConnection(), NWWriter_SUMO::writeInternalEdge(), NWWriter_SUMO::writeInternalNodes(), NWWriter_XML::writeJoinedJunctions(), NWWriter_SUMO::writeJunction(), NWWriter_SUMO::writeLane(), NBRequest::writeLaneResponse(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), NWWriter_SUMO::writePermissions(), NWFrame::writePositionLong(), NWWriter_SUMO::writePreferences(), MSMeanData::writePrefix(), NWWriter_SUMO::writeProhibitions(), NWWriter_SUMO::writeRoundabout(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), SUMOVehicleParameter::writeStops(), NWWriter_SUMO::writeTrafficLights(), RODFDetectorCon::writeValidationDetectors(), RORouteDef::writeXMLDefinition(), RORoute::writeXMLDefinition(), and MSMeanData::writeXMLOutput().

template<typename T >
OutputDevice& OutputDevice::writeAttr ( const SumoXMLAttr  attr,
const T &  val 
)
inlineinherited

writes a named attribute

Parameters
[in]attrThe attribute (name)
[in]valThe attribute value
Returns
The OutputDevice for further processing

Definition at line 261 of file OutputDevice.h.

References OutputDevice::getOStream(), OutputDevice::myAmBinary, PlainXMLFormatter::writeAttr(), and BinaryFormatter::writeAttr().

template<typename E >
bool OutputDevice::writeHeader ( const SumoXMLTag rootElement)
inlineinherited
bool OutputDevice::writeXMLHeader ( const std::string &  rootElement,
const std::string &  attrs = "",
const std::string &  comment = "" 
)
inherited

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]attrsAdditional attributes to save within the rootElement
[in]commentAdditional comment (saved in front the rootElement)
Returns
Whether the header could be written (stack was empty)
Todo:

Check which parameter is used herein

Describe what is saved

Definition at line 196 of file OutputDevice.cpp.

References OutputDevice::getOStream(), OutputDevice::myFormatter, and OutputFormatter::writeXMLHeader().

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

Field Documentation

std::ofstream* OutputDevice_File::myFileStream
private

The wrapped ofstream.

Definition at line 74 of file OutputDevice_File.h.

Referenced by getOStream(), OutputDevice_File(), and ~OutputDevice_File().


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