Eclipse SUMO - Simulation of Urban MObility
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. More...
 
void openTag (std::ostream &into, const std::string &xmlElement)
 Opens an XML tag. More...
 
void openTag (std::ostream &into, const SumoXMLTag &xmlElement)
 Opens an XML tag. More...
 
 PlainXMLFormatter (const int defaultIndentation=0)
 Constructor. More...
 
bool writeHeader (std::ostream &into, const SumoXMLTag &rootElement)
 Writes an XML header with optional configuration. More...
 
void writePadding (std::ostream &into, const std::string &val)
 writes arbitrary padding More...
 
void writePreformattedTag (std::ostream &into, const std::string &val)
 writes a preformatted tag to the device but ensures that any pending tags are closed More...
 
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. More...
 
bool wroteHeader () const
 
virtual ~PlainXMLFormatter ()
 Destructor. More...
 

Static Public Member Functions

template<class T >
static void writeAttr (std::ostream &into, const std::string &attr, const T &val)
 writes an arbitrary attribute More...
 
template<class T >
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const T &val)
 writes a named attribute More...
 

Private Attributes

int myDefaultIndentation
 The initial indentation level. More...
 
bool myHavePendingOpener
 whether a closing ">" might be missing More...
 
std::vector< std::string > myXMLStack
 The stack of begun xml elements. More...
 

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 31 of file PlainXMLFormatter.cpp.

◆ ~PlainXMLFormatter()

virtual PlainXMLFormatter::~PlainXMLFormatter ( )
inlinevirtual

Destructor.

Definition at line 43 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
Todo:
it is not verified that the topmost element was closed

Implements OutputFormatter.

Definition at line 82 of file PlainXMLFormatter.cpp.

References myDefaultIndentation, myHavePendingOpener, and myXMLStack.

◆ 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
Returns
The OutputDevice for further processing

Implements OutputFormatter.

Definition at line 65 of file PlainXMLFormatter.cpp.

References myDefaultIndentation, myHavePendingOpener, and myXMLStack.

Referenced by openTag(), writeHeader(), 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 76 of file PlainXMLFormatter.cpp.

References openTag(), and toString().

◆ writeAttr() [1/2]

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

writes an arbitrary attribute

Parameters
[in]intoThe output stream to use
[in]attrThe attribute (name)
[in]valThe attribute value

Definition at line 123 of file PlainXMLFormatter.h.

References toString().

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

Here is the caller graph for this function:

◆ writeAttr() [2/2]

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

writes a named attribute

Parameters
[in]intoThe output stream to use
[in]attrThe attribute (name)
[in]valThe attribute value

Definition at line 135 of file PlainXMLFormatter.h.

References toString().

◆ writeHeader()

bool PlainXMLFormatter::writeHeader ( std::ostream &  into,
const SumoXMLTag rootElement 
)

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

Definition at line 37 of file PlainXMLFormatter.cpp.

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

◆ writePadding()

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

writes arbitrary padding

Implements OutputFormatter.

Definition at line 108 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

Implements OutputFormatter.

Definition at line 99 of file PlainXMLFormatter.cpp.

References myHavePendingOpener.

◆ writeXMLHeader()

bool PlainXMLFormatter::writeXMLHeader ( std::ostream &  into,
const std::string &  rootElement,
const std::map< SumoXMLAttr, std::string > &  attrs,
bool  includeConfig = true 
)
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
Todo:
Describe what is saved

Implements OutputFormatter.

Definition at line 48 of file PlainXMLFormatter.cpp.

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

◆ wroteHeader()

bool PlainXMLFormatter::wroteHeader ( ) const
inlinevirtual

Implements OutputFormatter.

Definition at line 139 of file PlainXMLFormatter.h.

References myXMLStack.

Field Documentation

◆ myDefaultIndentation

int PlainXMLFormatter::myDefaultIndentation
private

The initial indentation level.

Definition at line 148 of file PlainXMLFormatter.h.

Referenced by closeTag(), and openTag().

◆ myHavePendingOpener

bool PlainXMLFormatter::myHavePendingOpener
private

whether a closing ">" might be missing

Definition at line 151 of file PlainXMLFormatter.h.

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

◆ myXMLStack

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

The stack of begun xml elements.

Definition at line 145 of file PlainXMLFormatter.h.

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


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