![]() |
Eclipse SUMO - Simulation of Urban MObility
|
Output formatter for plain XML output. More...
#include <PlainXMLFormatter.h>
Public Member Functions | |
| bool | closeTag (std::ostream &into, const std::string &comment="") |
| Closes the most recently opened tag. | |
| OutputFormatterType | getType () const |
| Returns the type of formatter being used. | |
| void | openTag (std::ostream &into, const std::string &xmlElement) |
| Opens an XML tag. | |
| void | openTag (std::ostream &into, const SumoXMLTag &xmlElement) |
| Opens an XML tag. | |
| PlainXMLFormatter (const int defaultIndentation=0) | |
| Constructor. | |
| virtual void | setExpectedAttributes (const SumoXMLAttrMask &expected, const int depth) |
| 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. | |
| void | writePadding (std::ostream &into, const std::string &val) |
| writes arbitrary padding | |
| void | writePreformattedTag (std::ostream &into, const std::string &val) |
| writes a preformatted tag to the device but ensures that any pending tags are closed | |
| void | writeTime (std::ostream &into, const SumoXMLAttr attr, const SUMOTime val) |
| bool | writeXMLHeader (std::ostream &into, const std::string &rootElement, const std::map< SumoXMLAttr, std::string > &attrs, bool includeConfig) |
| Writes an XML header with optional configuration. | |
| bool | wroteHeader () const |
| Returns whether a header has been written. Useful to detect whether a file is being used by multiple sources. | |
| virtual | ~PlainXMLFormatter () |
| Destructor. | |
Static Public Member Functions | |
| static void | setHeaderWriters (std::function< void(std::ostream &, bool)> headerWriter, std::function< void(std::ostream &)> metadataWriter) |
| Sets the functions which write the file header and the metadata block. | |
| static void | writeAttr (std::ostream &into, const std::string &attr, const std::string &val, const bool escape) |
| typed overloads (non-template) – picked by overload resolution over the template | |
| template<class T > | |
| static void | writeAttr (std::ostream &into, const std::string &attr, const T &val, const bool escape) |
| writes an arbitrary attribute | |
| static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const std::string &val, const bool escape) |
| template<class T > | |
| static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const T &val, const bool escape) |
| writes a named attribute | |
Private Attributes | |
| int | myDefaultIndentation |
| The initial indentation level. | |
| bool | myHavePendingOpener |
| whether a closing ">" might be missing | |
| const OutputFormatterType | myType |
| the type of formatter being used (XML, CSV, Parquet, etc.) | |
| std::vector< std::string > | myXMLStack |
| The stack of begun xml elements. | |
Static Private Attributes | |
| static std::function< void(std::ostream &, bool)> | myHeaderWriter |
| writes the XML declaration and optionally the configuration comment | |
| static std::function< void(std::ostream &)> | myMetadataWriter |
| writes the metadata block | |
Output formatter for plain XML output.
PlainXMLFormatter format XML like output into the output stream.
Definition at line 37 of file PlainXMLFormatter.h.
| PlainXMLFormatter::PlainXMLFormatter | ( | const int | defaultIndentation = 0 | ) |
Constructor.
Definition at line 38 of file PlainXMLFormatter.cpp.
|
inlinevirtual |
Destructor.
Definition at line 43 of file PlainXMLFormatter.h.
|
virtual |
Closes the most recently opened tag.
| [in] | into | The output stream to use |
Implements OutputFormatter.
Definition at line 84 of file PlainXMLFormatter.cpp.
References myDefaultIndentation, myHavePendingOpener, and myXMLStack.
|
inlineinherited |
Returns the type of formatter being used.
Definition at line 150 of file OutputFormatter.h.
References OutputFormatter::myType.
Referenced by OutputDevice::isXML(), OutputDevice::lf(), OutputDevice::writeAttr(), OutputDevice::writeFuncAttr(), and OutputDevice::writeOptionalAttr().
|
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.
| [in] | into | The output stream to use |
| [in] | xmlElement | Name of element to open |
Implements OutputFormatter.
Definition at line 67 of file PlainXMLFormatter.cpp.
References myDefaultIndentation, myHavePendingOpener, and myXMLStack.
Referenced by openTag(), and writeXMLHeader().
|
virtual |
Opens an XML tag.
Helper method which finds the correct string before calling openTag.
| [in] | into | The output stream to use |
| [in] | xmlElement | Id of the element to open |
Implements OutputFormatter.
Definition at line 78 of file PlainXMLFormatter.cpp.
References openTag(), and toString().
|
inlinevirtualinherited |
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.
| [in] | expected | which attributes are to be written (at the deepest XML level) |
| [in] | depth | the maximum XML hierarchy depth (includes the root only if it has relevant attributes) |
Reimplemented in CSVFormatter, and ParquetFormatter.
Definition at line 161 of file OutputFormatter.h.
References UNUSED_PARAMETER.
Referenced by OutputDevice::setExpectedAttributes().
|
inlinestatic |
Sets the functions which write the file header and the metadata block.
They are provided by the options subsystem (see SystemFrame) so that this class does not depend on it.
| [in] | headerWriter | writes the XML declaration and optionally the configuration comment |
| [in] | metadataWriter | writes the metadata block including the configuration |
Definition at line 52 of file PlainXMLFormatter.h.
References myHeaderWriter, and myMetadataWriter.
Referenced by SystemFrame::updateOutputSettings().
|
static |
typed overloads (non-template) – picked by overload resolution over the template
Definition at line 117 of file PlainXMLFormatter.cpp.
References StringUtils::escapeXML().
|
inlinestatic |
writes an arbitrary attribute
| [in] | into | The output stream to use |
| [in] | attr | The attribute (name) |
| [in] | val | The attribute value |
| [in] | escape | Whether the value should be processed by StringUtils::escapeXML (only used in the string variant below) |
Definition at line 119 of file PlainXMLFormatter.h.
References toString(), and UNUSED_PARAMETER.
Referenced by OutputDevice::writeAttr(), OutputDevice::writeFuncAttr(), and writeXMLHeader().
|
static |
Definition at line 123 of file PlainXMLFormatter.cpp.
References StringUtils::escapeXML(), and toString().
|
inlinestatic |
writes a named attribute
| [in] | into | The output stream to use |
| [in] | attr | The attribute (name) |
| [in] | val | The attribute value |
| [in] | escape | Whether the value should be processed by StringUtils::escapeXML (only used in the string variant below) |
Definition at line 132 of file PlainXMLFormatter.h.
References toString(), and UNUSED_PARAMETER.
|
virtual |
writes arbitrary padding
Reimplemented from OutputFormatter.
Definition at line 111 of file PlainXMLFormatter.cpp.
|
virtual |
writes a preformatted tag to the device but ensures that any pending tags are closed
| [in] | into | The output stream to use |
| [in] | val | The preformatted data |
Reimplemented from OutputFormatter.
Definition at line 101 of file PlainXMLFormatter.cpp.
References myHavePendingOpener.
|
inlinevirtual |
Implements OutputFormatter.
Definition at line 141 of file PlainXMLFormatter.h.
References time2string(), and toString().
|
virtual |
Writes an XML header with optional configuration.
If something has been written (myXMLStack is not empty), nothing is written and false returned.
| [in] | into | The output stream to use |
| [in] | rootElement | The root element to use |
| [in] | attrs | Additional attributes to save within the rootElement |
| [in] | includeConfig | whether the current config should be included as XML comment |
Reimplemented from OutputFormatter.
Definition at line 44 of file PlainXMLFormatter.cpp.
References myHavePendingOpener, myHeaderWriter, myMetadataWriter, myXMLStack, openTag(), and writeAttr().
|
inlinevirtual |
Returns whether a header has been written. Useful to detect whether a file is being used by multiple sources.
Implements OutputFormatter.
Definition at line 145 of file PlainXMLFormatter.h.
References myXMLStack.
|
private |
The initial indentation level.
Definition at line 160 of file PlainXMLFormatter.h.
Referenced by closeTag(), and openTag().
|
private |
whether a closing ">" might be missing
Definition at line 163 of file PlainXMLFormatter.h.
Referenced by closeTag(), openTag(), writePreformattedTag(), and writeXMLHeader().
|
staticprivate |
writes the XML declaration and optionally the configuration comment
Definition at line 151 of file PlainXMLFormatter.h.
Referenced by setHeaderWriters(), and writeXMLHeader().
|
staticprivate |
writes the metadata block
Definition at line 154 of file PlainXMLFormatter.h.
Referenced by setHeaderWriters(), and writeXMLHeader().
|
privateinherited |
the type of formatter being used (XML, CSV, Parquet, etc.)
Definition at line 168 of file OutputFormatter.h.
Referenced by OutputFormatter::getType().
|
private |
The stack of begun xml elements.
Definition at line 157 of file PlainXMLFormatter.h.
Referenced by closeTag(), openTag(), writeXMLHeader(), and wroteHeader().