Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
OutputFormatter Class Referenceabstract

Abstract base class for output formatters. More...

#include <OutputFormatter.h>

Inheritance diagram for OutputFormatter:
[legend]

Public Member Functions

virtual bool closeTag (std::ostream &into, const std::string &comment="")=0
 Closes the most recently opened tag and optinally add a comment.
 
OutputFormatterType getType ()
 Returns the type of formatter being used.
 
virtual void openTag (std::ostream &into, const std::string &xmlElement)=0
 Opens an XML tag.
 
virtual void openTag (std::ostream &into, const SumoXMLTag &xmlElement)=0
 Opens an XML tag.
 
 OutputFormatter (OutputFormatterType t)
 Constructor.
 
virtual void setExpectedAttributes (const SumoXMLAttrMask &expected, const int depth=2)
 Set the expected attributes to write. This is used for tracking which attributes are expected in table like outputs. This should be not necessary but at least in the initial phase of implementing CSV and Parquet it helps a lot to track errors.
 
virtual void writePadding (std::ostream &into, const std::string &val)
 Writes some whitespace to format the output. This method is only implemented for XML output.
 
virtual void writePreformattedTag (std::ostream &into, const std::string &val)
 Writes a preformatted tag to the device but ensures that any pending tags are closed. This method is only implemented for XML output.
 
virtual void writeTime (std::ostream &into, const SumoXMLAttr attr, const SUMOTime val)=0
 
virtual bool writeXMLHeader (std::ostream &into, const std::string &rootElement, const std::map< SumoXMLAttr, std::string > &attrs, bool includeConfig=true)
 Writes an XML header with optional configuration.
 
virtual bool wroteHeader () const =0
 Returns whether a header has been written. Useful to detect whether a file is being used by multiple sources.
 
virtual ~OutputFormatter ()
 Destructor.
 

Private Attributes

const OutputFormatterType myType
 the type of formatter being used (XML, CSV, Parquet, etc.)
 

Detailed Description

Abstract base class for output formatters.

OutputFormatter format XML like output into the output stream. There are only two implementation at the moment, "normal" XML and binary XML.

Definition at line 57 of file OutputFormatter.h.

Constructor & Destructor Documentation

◆ OutputFormatter()

OutputFormatter::OutputFormatter ( OutputFormatterType  t)
inline

Constructor.

Definition at line 60 of file OutputFormatter.h.

◆ ~OutputFormatter()

virtual OutputFormatter::~OutputFormatter ( )
inlinevirtual

Destructor.

Definition at line 63 of file OutputFormatter.h.

Member Function Documentation

◆ closeTag()

virtual bool OutputFormatter::closeTag ( std::ostream &  into,
const std::string &  comment = "" 
)
pure virtual

Closes the most recently opened tag and optinally add a comment.

Parameters
[in]intoThe output stream to use
Returns
Whether a further element existed in the stack and could be closed
Todo:
it is not verified that the topmost element was closed

Implemented in CSVFormatter, ParquetFormatter, and PlainXMLFormatter.

Referenced by OutputDevice::closeTag().

Here is the caller graph for this function:

◆ getType()

OutputFormatterType OutputFormatter::getType ( )
inline

Returns the type of formatter being used.

Returns
the formatter type

Definition at line 149 of file OutputFormatter.h.

References myType.

Referenced by OutputDevice::writeAttr(), OutputDevice::writeAttr(), OutputDevice::writeFuncAttr(), and OutputDevice::writeOptionalAttr().

Here is the caller graph for this function:

◆ openTag() [1/2]

virtual void OutputFormatter::openTag ( std::ostream &  into,
const std::string &  xmlElement 
)
pure virtual

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]intoThe output stream to use
[in]xmlElementName of element to open
Returns
The OutputDevice for further processing

Implemented in CSVFormatter, ParquetFormatter, and PlainXMLFormatter.

Referenced by OutputDevice::openTag(), and OutputDevice::openTag().

Here is the caller graph for this function:

◆ openTag() [2/2]

virtual void OutputFormatter::openTag ( std::ostream &  into,
const SumoXMLTag xmlElement 
)
pure virtual

Opens an XML tag.

Helper method which finds the correct string before calling openTag.

Parameters
[in]intoThe output stream to use
[in]xmlElementId of the element to open

Implemented in CSVFormatter, ParquetFormatter, and PlainXMLFormatter.

◆ setExpectedAttributes()

virtual void OutputFormatter::setExpectedAttributes ( const SumoXMLAttrMask expected,
const int  depth = 2 
)
inlinevirtual

Set the expected attributes to write. This is used for tracking which attributes are expected in table like outputs. This should be not necessary but at least in the initial phase of implementing CSV and Parquet it helps a lot to track errors.

Parameters
[in]expectedwhich attributes are to be written (at the deepest XML level)
[in]depththe maximum XML hierarchy depth (excluding the root)

Reimplemented in CSVFormatter, and ParquetFormatter.

Definition at line 160 of file OutputFormatter.h.

References UNUSED_PARAMETER.

Referenced by OutputDevice::setExpectedAttributes().

Here is the caller graph for this function:

◆ writePadding()

virtual void OutputFormatter::writePadding ( std::ostream &  into,
const std::string &  val 
)
inlinevirtual

Writes some whitespace to format the output. This method is only implemented for XML output.

Parameters
[in]intoThe output stream to use
[in]valThe whitespace

Reimplemented in PlainXMLFormatter.

Definition at line 135 of file OutputFormatter.h.

References UNUSED_PARAMETER.

Referenced by OutputDevice::writePadding().

Here is the caller graph for this function:

◆ writePreformattedTag()

virtual void OutputFormatter::writePreformattedTag ( std::ostream &  into,
const std::string &  val 
)
inlinevirtual

Writes a preformatted tag to the device but ensures that any pending tags are closed. This method is only implemented for XML output.

Parameters
[in]intoThe output stream to use
[in]valThe preformatted data

Reimplemented in PlainXMLFormatter.

Definition at line 124 of file OutputFormatter.h.

References UNUSED_PARAMETER.

Referenced by OutputDevice::writePreformattedTag().

Here is the caller graph for this function:

◆ writeTime()

virtual void OutputFormatter::writeTime ( std::ostream &  into,
const SumoXMLAttr  attr,
const SUMOTime  val 
)
pure virtual

Implemented in CSVFormatter, ParquetFormatter, and PlainXMLFormatter.

Referenced by OutputDevice::writeTime().

Here is the caller graph for this function:

◆ writeXMLHeader()

virtual bool OutputFormatter::writeXMLHeader ( std::ostream &  into,
const std::string &  rootElement,
const std::map< SumoXMLAttr, std::string > &  attrs,
bool  includeConfig = true 
)
inlinevirtual

Writes an XML header with optional configuration.

If something has been written (myXMLStack is not empty), nothing is written and false returned. The default implementation does nothing and returns false.

Parameters
[in]intoThe output stream to use
[in]rootElementThe root element to use
[in]attrsAdditional attributes to save within the rootElement
[in]includeConfigwhether the current config should be included as XML comment
Returns
whether something has been written

Reimplemented in PlainXMLFormatter.

Definition at line 77 of file OutputFormatter.h.

References UNUSED_PARAMETER.

Referenced by OutputDevice::writeXMLHeader().

Here is the caller graph for this function:

◆ wroteHeader()

virtual bool OutputFormatter::wroteHeader ( ) const
pure virtual

Returns whether a header has been written. Useful to detect whether a file is being used by multiple sources.

Returns
Whether a header has been written

Implemented in CSVFormatter, ParquetFormatter, and PlainXMLFormatter.

Referenced by OutputDevice::wroteHeader().

Here is the caller graph for this function:

Field Documentation

◆ myType

const OutputFormatterType OutputFormatter::myType
private

the type of formatter being used (XML, CSV, Parquet, etc.)

Definition at line 167 of file OutputFormatter.h.

Referenced by getType().


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