Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
PlainXMLFormatter Class Reference

Output formatter for plain XML output. More...

#include <PlainXMLFormatter.h>

Inheritance diagram for PlainXMLFormatter:
[legend]
Collaboration diagram for PlainXMLFormatter:
[legend]

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 writeMetadata, 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 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.
 

Detailed Description

Output formatter for plain XML output.

PlainXMLFormatter format XML like output into the output stream.

Definition at line 36 of file PlainXMLFormatter.h.

Constructor & Destructor Documentation

◆ PlainXMLFormatter()

PlainXMLFormatter::PlainXMLFormatter ( const int  defaultIndentation = 0)

Constructor.

Definition at line 32 of file PlainXMLFormatter.cpp.

◆ ~PlainXMLFormatter()

virtual PlainXMLFormatter::~PlainXMLFormatter ( )
inlinevirtual

Destructor.

Definition at line 42 of file PlainXMLFormatter.h.

Member Function Documentation

◆ closeTag()

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

Closes the most recently opened tag.

Parameters
[in]intoThe output stream to use
Returns
Whether a further element existed in the stack and could be closed

Implements OutputFormatter.

Definition at line 79 of file PlainXMLFormatter.cpp.

References myDefaultIndentation, myHavePendingOpener, and myXMLStack.

◆ getType()

OutputFormatterType OutputFormatter::getType ( ) const
inlineinherited

Returns the type of formatter being used.

Returns
the formatter type

Definition at line 152 of file OutputFormatter.h.

References OutputFormatter::myType.

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

Here is the caller graph for this function:

◆ openTag() [1/2]

void PlainXMLFormatter::openTag ( std::ostream &  into,
const std::string &  xmlElement 
)
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

Implements OutputFormatter.

Definition at line 62 of file PlainXMLFormatter.cpp.

References myDefaultIndentation, myHavePendingOpener, and myXMLStack.

Referenced by openTag(), and writeXMLHeader().

Here is the caller graph for this function:

◆ openTag() [2/2]

void PlainXMLFormatter::openTag ( std::ostream &  into,
const SumoXMLTag xmlElement 
)
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

Implements OutputFormatter.

Definition at line 73 of file PlainXMLFormatter.cpp.

References openTag(), and toString().

◆ setExpectedAttributes()

virtual void OutputFormatter::setExpectedAttributes ( const SumoXMLAttrMask expected,
const int  depth 
)
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.

Parameters
[in]expectedwhich attributes are to be written (at the deepest XML level)
[in]depththe maximum XML hierarchy depth (includes the root only if it has relevant attributes)

Reimplemented in CSVFormatter, and ParquetFormatter.

Definition at line 163 of file OutputFormatter.h.

References UNUSED_PARAMETER.

Referenced by OutputDevice::setExpectedAttributes().

Here is the caller graph for this function:

◆ writeAttr() [1/4]

void PlainXMLFormatter::writeAttr ( std::ostream &  into,
const std::string &  attr,
const std::string &  val,
const bool  escape 
)
static

typed overloads (non-template) – picked by overload resolution over the template

Definition at line 112 of file PlainXMLFormatter.cpp.

References StringUtils::escapeXML().

◆ writeAttr() [2/4]

template<class T >
static void PlainXMLFormatter::writeAttr ( std::ostream &  into,
const std::string &  attr,
const T &  val,
const bool  escape 
)
inlinestatic

writes an arbitrary attribute

Parameters
[in]intoThe output stream to use
[in]attrThe attribute (name)
[in]valThe attribute value
[in]escapeWhether the value should be processed by StringUtils::escapeXML (only used in the string variant below)

Definition at line 106 of file PlainXMLFormatter.h.

References toString(), and UNUSED_PARAMETER.

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

Here is the caller graph for this function:

◆ writeAttr() [3/4]

void PlainXMLFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const std::string &  val,
const bool  escape 
)
static

Definition at line 118 of file PlainXMLFormatter.cpp.

References StringUtils::escapeXML(), and toString().

◆ writeAttr() [4/4]

template<class T >
static void PlainXMLFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const T &  val,
const bool  escape 
)
inlinestatic

writes a named attribute

Parameters
[in]intoThe output stream to use
[in]attrThe attribute (name)
[in]valThe attribute value
[in]escapeWhether 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.

◆ writePadding()

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

writes arbitrary padding

Reimplemented from OutputFormatter.

Definition at line 106 of file PlainXMLFormatter.cpp.

◆ writePreformattedTag()

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

writes a preformatted tag to the device but ensures that any pending tags are closed

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

Reimplemented from OutputFormatter.

Definition at line 96 of file PlainXMLFormatter.cpp.

References myHavePendingOpener.

◆ writeTime()

void PlainXMLFormatter::writeTime ( std::ostream &  into,
const SumoXMLAttr  attr,
const SUMOTime  val 
)
inlinevirtual

Implements OutputFormatter.

Definition at line 128 of file PlainXMLFormatter.h.

References time2string(), and toString().

◆ writeXMLHeader()

bool PlainXMLFormatter::writeXMLHeader ( std::ostream &  into,
const std::string &  rootElement,
const std::map< SumoXMLAttr, std::string > &  attrs,
bool  writeMetadata,
bool  includeConfig 
)
virtual

Writes an XML header with optional configuration.

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

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
Todo:
Describe what is saved

Reimplemented from OutputFormatter.

Definition at line 38 of file PlainXMLFormatter.cpp.

References OptionsCont::getFullName(), OptionsCont::getOptions(), StringUtils::isoTimeString(), myHavePendingOpener, myXMLStack, openTag(), writeAttr(), OptionsCont::writeConfiguration(), and OptionsCont::writeXMLHeader().

◆ wroteHeader()

bool PlainXMLFormatter::wroteHeader ( ) const
inlinevirtual

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

Implements OutputFormatter.

Definition at line 132 of file PlainXMLFormatter.h.

References myXMLStack.

Field Documentation

◆ myDefaultIndentation

int PlainXMLFormatter::myDefaultIndentation
private

The initial indentation level.

Definition at line 141 of file PlainXMLFormatter.h.

Referenced by closeTag(), and openTag().

◆ myHavePendingOpener

bool PlainXMLFormatter::myHavePendingOpener
private

whether a closing ">" might be missing

Definition at line 144 of file PlainXMLFormatter.h.

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

◆ myType

const OutputFormatterType OutputFormatter::myType
privateinherited

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

Definition at line 170 of file OutputFormatter.h.

Referenced by OutputFormatter::getType().

◆ myXMLStack

std::vector<std::string> PlainXMLFormatter::myXMLStack
private

The stack of begun xml elements.

Definition at line 138 of file PlainXMLFormatter.h.

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


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