Eclipse SUMO - Simulation of Urban MObility
BinaryFormatter Class Reference

Output formatter for plain XML output. More...

#include <BinaryFormatter.h>

Inheritance diagram for BinaryFormatter:
Collaboration diagram for BinaryFormatter:

Public Types

enum  DataType {
  BF_BYTE, BF_INTEGER, BF_FLOAT, BF_STRING,
  BF_LIST, BF_XML_TAG_START, BF_XML_TAG_END, BF_XML_ATTRIBUTE,
  BF_EDGE, BF_LANE, BF_POSITION_2D, BF_POSITION_3D,
  BF_BOUNDARY, BF_COLOR, BF_NODE_TYPE, BF_EDGE_FUNCTION,
  BF_ROUTE, BF_SCALED2INT, BF_SCALED2INT_POSITION_2D, BF_SCALED2INT_POSITION_3D,
  BF_INVALID
}
 data types in binary output More...
 

Public Member Functions

 BinaryFormatter ()
 Constructor. More...
 
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...
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const bool &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const Boundary &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const double &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const int &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const Position &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const PositionVector &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const RGBColor &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const SumoXMLEdgeFunc &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr attr, const SumoXMLNodeType &val)
 
template<>
void writeAttr (std::ostream &into, const SumoXMLAttr, const std::vector< int > &val)
 
template<typename E >
bool writeHeader (std::ostream &into, const SumoXMLTag &rootElement)
 Writes a header with optional edge list and connections. More...
 
void writePadding (std::ostream &, const std::string &)
 padding is ignored for binary output 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)
 Writes an XML header with optional configuration. More...
 
virtual ~BinaryFormatter ()
 Destructor. More...
 

Static Public Member Functions

template<typename dummy , typename T >
static void writeAttr (dummy &into, const std::string &attr, const T &val)
 writes a named attribute More...
 
template<typename dummy >
static void writeAttr (dummy &into, const SumoXMLAttr attr, const std::vector< const MSEdge * > &val)
 
template<typename dummy >
static void writeAttr (dummy &into, const SumoXMLAttr attr, const std::vector< const ROEdge * > &val)
 
template<typename dummy , typename T >
static void writeAttr (dummy &into, const SumoXMLAttr attr, const T &val)
 writes an arbitrary attribute More...
 

Static Private Member Functions

static void writeAttrHeader (std::ostream &into, const SumoXMLAttr attr, const DataType type=BF_INVALID)
 writes the header for an arbitrary attribute More...
 
static void writePosition (std::ostream &into, const Position &val)
 writes a position More...
 
static void writeStaticHeader (std::ostream &into)
 writes the part of the header which is always unchanged. More...
 
static void writeStringList (std::ostream &into, const std::vector< std::string > &list)
 writes a list of strings More...
 

Private Attributes

std::vector< SumoXMLTagmyXMLStack
 The stack of begun xml elements. More...
 

Detailed Description

Output formatter for plain XML output.

BinaryFormatter format XML like output into the output stream.

Definition at line 54 of file BinaryFormatter.h.

Member Enumeration Documentation

◆ DataType

data types in binary output

Enumerator
BF_BYTE 
BF_INTEGER 
BF_FLOAT 
BF_STRING 
BF_LIST 
BF_XML_TAG_START 
BF_XML_TAG_END 
BF_XML_ATTRIBUTE 
BF_EDGE 
BF_LANE 
BF_POSITION_2D 
BF_POSITION_3D 
BF_BOUNDARY 
BF_COLOR 
BF_NODE_TYPE 
BF_EDGE_FUNCTION 
BF_ROUTE 
BF_SCALED2INT 
BF_SCALED2INT_POSITION_2D 
BF_SCALED2INT_POSITION_3D 
BF_INVALID 

Definition at line 57 of file BinaryFormatter.h.

Constructor & Destructor Documentation

◆ BinaryFormatter()

BinaryFormatter::BinaryFormatter ( )

Constructor.

Definition at line 41 of file BinaryFormatter.cpp.

◆ ~BinaryFormatter()

virtual BinaryFormatter::~BinaryFormatter ( )
inlinevirtual

Destructor.

Definition at line 107 of file BinaryFormatter.h.

Member Function Documentation

◆ closeTag()

bool BinaryFormatter::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 108 of file BinaryFormatter.cpp.

References BF_XML_TAG_END, myXMLStack, and FileHelpers::writeByte().

◆ openTag() [1/2]

void BinaryFormatter::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 90 of file BinaryFormatter.cpp.

References SUMOXMLDefinitions::Tags.

Referenced by writeHeader(), and writeXMLHeader().

◆ openTag() [2/2]

void BinaryFormatter::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 98 of file BinaryFormatter.cpp.

References BF_XML_TAG_START, myXMLStack, and FileHelpers::writeByte().

◆ writeAttr() [1/14]

template<typename dummy , typename T >
void BinaryFormatter::writeAttr ( dummy &  into,
const std::string &  attr,
const T &  val 
)
static

writes a named attribute

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

Definition at line 297 of file BinaryFormatter.h.

References SUMOXMLDefinitions::Attrs, and writeAttr().

◆ writeAttr() [2/14]

template<typename dummy >
void BinaryFormatter::writeAttr ( dummy &  into,
const SumoXMLAttr  attr,
const std::vector< const MSEdge * > &  val 
)
static

Definition at line 324 of file BinaryFormatter.h.

References BF_ROUTE, writeAttrHeader(), and FileHelpers::writeEdgeVector().

◆ writeAttr() [3/14]

template<typename dummy >
void BinaryFormatter::writeAttr ( dummy &  into,
const SumoXMLAttr  attr,
const std::vector< const ROEdge * > &  val 
)
static

Definition at line 317 of file BinaryFormatter.h.

References BF_ROUTE, writeAttrHeader(), and FileHelpers::writeEdgeVector().

◆ writeAttr() [4/14]

template<typename dummy , typename T >
void BinaryFormatter::writeAttr ( dummy &  into,
const SumoXMLAttr  attr,
const T &  val 
)
static

writes an arbitrary attribute

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

Definition at line 290 of file BinaryFormatter.h.

References BF_STRING, toString(), writeAttrHeader(), and FileHelpers::writeString().

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

◆ writeAttr() [5/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const bool &  val 
)

Definition at line 119 of file BinaryFormatter.cpp.

References BF_BYTE, writeAttrHeader(), and FileHelpers::writeByte().

◆ writeAttr() [6/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const Boundary val 
)

◆ writeAttr() [7/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const double &  val 
)

◆ writeAttr() [8/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const int &  val 
)

Definition at line 138 of file BinaryFormatter.cpp.

References BF_INTEGER, writeAttrHeader(), and FileHelpers::writeInt().

◆ writeAttr() [9/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const Position val 
)

Definition at line 188 of file BinaryFormatter.cpp.

References writeAttrHeader(), and writePosition().

◆ writeAttr() [10/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const PositionVector val 
)

◆ writeAttr() [11/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const RGBColor val 
)

◆ writeAttr() [12/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const SumoXMLEdgeFunc val 
)

◆ writeAttr() [13/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const SumoXMLNodeType val 
)

Definition at line 145 of file BinaryFormatter.cpp.

References BF_NODE_TYPE, writeAttrHeader(), and FileHelpers::writeByte().

◆ writeAttr() [14/14]

template<>
void BinaryFormatter::writeAttr ( std::ostream &  into,
const  SumoXMLAttr,
const std::vector< int > &  val 
)

◆ writeAttrHeader()

static void BinaryFormatter::writeAttrHeader ( std::ostream &  into,
const SumoXMLAttr  attr,
const DataType  type = BF_INVALID 
)
inlinestaticprivate

writes the header for an arbitrary attribute

Parameters
[in]intoThe output stream to use
[in]attrThe attribute (name)
[in]typeThe attribute type

Definition at line 216 of file BinaryFormatter.h.

References BF_INVALID, BF_XML_ATTRIBUTE, and FileHelpers::writeByte().

Referenced by writeAttr().

◆ writeHeader()

template<typename E >
bool BinaryFormatter::writeHeader ( std::ostream &  into,
const SumoXMLTag rootElement 
)

Writes a header with optional edge list and connections.

If something has been written (myXMLStack is not empty), nothing is written and false returned. This header is only used by the binary formatter.

Parameters
[in]intoThe output stream to use
[in]rootElementThe root element to use

Definition at line 261 of file BinaryFormatter.h.

References BF_INTEGER, BF_LIST, BF_STRING, myXMLStack, openTag(), FileHelpers::writeByte(), FileHelpers::writeInt(), writeStaticHeader(), and FileHelpers::writeString().

◆ writePadding()

void BinaryFormatter::writePadding ( std::ostream &  ,
const std::string &   
)
inlinevirtual

padding is ignored for binary output

Implements OutputFormatter.

Definition at line 198 of file BinaryFormatter.h.

◆ writePosition()

void BinaryFormatter::writePosition ( std::ostream &  into,
const Position val 
)
staticprivate

writes a position

Parameters
[in]intoThe output stream to use
[in]valthe position to write

Definition at line 158 of file BinaryFormatter.cpp.

References BF_POSITION_2D, BF_POSITION_3D, BF_SCALED2INT_POSITION_2D, BF_SCALED2INT_POSITION_3D, FileHelpers::writeByte(), FileHelpers::writeFloat(), FileHelpers::writeInt(), Position::x(), Position::y(), and Position::z().

Referenced by writeAttr().

◆ writePreformattedTag()

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

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 193 of file BinaryFormatter.h.

References FileHelpers::writeString().

◆ writeStaticHeader()

void BinaryFormatter::writeStaticHeader ( std::ostream &  into)
staticprivate

writes the part of the header which is always unchanged.

This method exists only to reduce include dependencies of BinaryFormatter.h (which promote to OutputDevice.h, ...)

Parameters
[in]intoThe output stream to use

Definition at line 46 of file BinaryFormatter.cpp.

References SUMOXMLDefinitions::Attrs, BF_BYTE, BF_STRING, SUMOXMLDefinitions::EdgeFunctions, SUMOXMLDefinitions::NodeTypes, SUMOXMLDefinitions::Tags, VERSION_STRING, FileHelpers::writeByte(), FileHelpers::writeString(), and writeStringList().

Referenced by writeHeader(), and writeXMLHeader().

◆ writeStringList()

void BinaryFormatter::writeStringList ( std::ostream &  into,
const std::vector< std::string > &  list 
)
staticprivate

writes a list of strings

Parameters
[in]intoThe output stream to use
[in]listthe list to write

Definition at line 59 of file BinaryFormatter.cpp.

References BF_LIST, BF_STRING, FileHelpers::writeByte(), FileHelpers::writeInt(), and FileHelpers::writeString().

Referenced by writeStaticHeader(), and writeXMLHeader().

◆ writeXMLHeader()

bool BinaryFormatter::writeXMLHeader ( std::ostream &  into,
const std::string &  rootElement,
const std::map< SumoXMLAttr, std::string > &  attrs 
)
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 70 of file BinaryFormatter.cpp.

References myXMLStack, openTag(), SUMOXMLDefinitions::Tags, writeAttr(), writeStaticHeader(), and writeStringList().

Field Documentation

◆ myXMLStack

std::vector<SumoXMLTag> BinaryFormatter::myXMLStack
private

The stack of begun xml elements.

Definition at line 254 of file BinaryFormatter.h.

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


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