SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryFormatter Class Reference

Output formatter for plain XML output. More...

#include <BinaryFormatter.h>

Inheritance diagram for BinaryFormatter:
OutputFormatter

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
}
 data types in binary output More...
 

Public Member Functions

 BinaryFormatter ()
 Constructor. More...
 
void closeOpener (std::ostream &into)
 Ends the most recently opened element start. More...
 
bool closeTag (std::ostream &into, bool abbreviated=false)
 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...
 
void writeAttr (std::ostream &into, const std::string &attr, const std::string &val)
 writes an arbitrary attribute More...
 
template<typename T , typename S >
void writeAttr (S &into, const SumoXMLAttr attr, const T &val)
 
template<typename S >
void writeAttr (S &into, const SumoXMLAttr attr, const std::vector< const ROEdge * > &val)
 
template<typename E >
bool writeHeader (std::ostream &into, const SumoXMLTag &rootElement)
 Writes a header with optional edge list and connections. More...
 
bool writeXMLHeader (std::ostream &into, const std::string &rootElement, const std::string xmlParams="", const std::string &attrs="", const std::string &comment="")
 Writes an XML header with optional configuration. More...
 
virtual ~BinaryFormatter ()
 Destructor. More...
 

Static Public Member Functions

template<typename T , typename S >
static void writeAttr (S &into, const SumoXMLAttr attr, const T &val)
 writes a named attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const bool &val)
 writes a named boolean attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const SUMOReal &val)
 writes a named float attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const int &val)
 writes a named integer attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const unsigned int &val)
 writes a named unsigned integer attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const SumoXMLNodeType &val)
 writes a node type attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const SumoXMLEdgeFunc &val)
 writes an edge function attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const Position &val)
 writes a position attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const PositionVector &val)
 writes a position vector attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const Boundary &val)
 writes a boundary attribute More...
 
static void writeAttr (std::ostream &into, const SumoXMLAttr attr, const RGBColor &val)
 writes a color attribute More...
 
template<typename S >
static void writeAttr (S &into, const SumoXMLAttr attr, const std::vector< const ROEdge * > &val)
 writes an edge vector attribute More...
 

Static Private Member Functions

static void writeAttrHeader (std::ostream &into, const SumoXMLAttr attr, const DataType type)
 writes the header for an arbitrary attribute More...
 
static void writePosition (std::ostream &into, const Position &val)
 writes a position 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 62 of file BinaryFormatter.h.

Member Enumeration Documentation

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 

Definition at line 65 of file BinaryFormatter.h.

Constructor & Destructor Documentation

BinaryFormatter::BinaryFormatter ( )

Constructor.

Definition at line 51 of file BinaryFormatter.cpp.

virtual BinaryFormatter::~BinaryFormatter ( )
inlinevirtual

Destructor.

Definition at line 113 of file BinaryFormatter.h.

Member Function Documentation

void BinaryFormatter::closeOpener ( std::ostream &  into)
virtual

Ends the most recently opened element start.

Does nothing.

Parameters
[in]intoThe output stream to use

Implements OutputFormatter.

Definition at line 109 of file BinaryFormatter.cpp.

bool BinaryFormatter::closeTag ( std::ostream &  into,
bool  abbreviated = false 
)
virtual

Closes the most recently opened tag.

Parameters
[in]intoThe output stream to use
[in]namewhether abbreviated closing is performed
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 114 of file BinaryFormatter.cpp.

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

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 93 of file BinaryFormatter.cpp.

References SUMOXMLDefinitions::Tags.

Referenced by writeHeader(), and writeXMLHeader().

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 101 of file BinaryFormatter.cpp.

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

void BinaryFormatter::writeAttr ( std::ostream &  into,
const std::string &  attr,
const std::string &  val 
)
virtual

writes an arbitrary attribute

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

Implements OutputFormatter.

Definition at line 126 of file BinaryFormatter.cpp.

References SUMOXMLDefinitions::Attrs.

Referenced by OutputDevice::writeAttr().

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

writes a named attribute

Parameters
[in]intoThe output stream to use
[in]attrThe attribute (name)
[in]valThe attribute value
void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const bool val 
)
static

writes a named boolean attribute

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

Definition at line 133 of file BinaryFormatter.cpp.

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

void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const SUMOReal val 
)
static

writes a named float attribute

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

Definition at line 139 of file BinaryFormatter.cpp.

References BF_FLOAT, BF_SCALED2INT, writeAttrHeader(), FileHelpers::writeFloat(), and FileHelpers::writeInt().

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

writes a named integer attribute

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

Definition at line 150 of file BinaryFormatter.cpp.

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

void BinaryFormatter::writeAttr ( std::ostream &  into,
const SumoXMLAttr  attr,
const unsigned int val 
)
static

writes a named unsigned integer attribute

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

Definition at line 156 of file BinaryFormatter.cpp.

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

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

writes a node type attribute

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

Definition at line 162 of file BinaryFormatter.cpp.

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

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

writes an edge function attribute

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

Definition at line 168 of file BinaryFormatter.cpp.

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

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

writes a position attribute

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

Definition at line 203 of file BinaryFormatter.cpp.

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

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

writes a position vector attribute

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

Definition at line 210 of file BinaryFormatter.cpp.

References PositionVector::begin(), BF_LIST, PositionVector::end(), PositionVector::size(), writeAttrHeader(), FileHelpers::writeInt(), and writePosition().

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

writes a boundary attribute

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

Definition at line 219 of file BinaryFormatter.cpp.

References BF_BOUNDARY, writeAttrHeader(), FileHelpers::writeFloat(), Boundary::xmax(), Boundary::xmin(), Boundary::ymax(), and Boundary::ymin().

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

writes a color attribute

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

Definition at line 228 of file BinaryFormatter.cpp.

References BF_COLOR, RGBColor::blue(), RGBColor::green(), RGBColor::red(), writeAttrHeader(), and FileHelpers::writeByte().

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

writes an edge vector attribute

Parameters
[in]intoThe output stream to use
[in]attrThe attribute (name)
[in]valThe attribute value
template<typename T , typename S >
void BinaryFormatter::writeAttr ( S &  into,
const SumoXMLAttr  attr,
const T &  val 
)
template<typename S >
void BinaryFormatter::writeAttr ( S &  into,
const SumoXMLAttr  attr,
const std::vector< const ROEdge * > &  val 
)

Definition at line 391 of file BinaryFormatter.h.

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

static void BinaryFormatter::writeAttrHeader ( std::ostream &  into,
const SumoXMLAttr  attr,
const DataType  type 
)
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 315 of file BinaryFormatter.h.

References BF_XML_ATTRIBUTE, and FileHelpers::writeByte().

Referenced by writeAttr().

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

References SUMOXMLDefinitions::Attrs, BF_BYTE, BF_INTEGER, BF_LIST, BF_STRING, SUMOXMLDefinitions::EdgeFunctions, myXMLStack, SUMOXMLDefinitions::NodeTypes, openTag(), SUMOXMLDefinitions::Tags, VERSION_STRING, FileHelpers::writeByte(), FileHelpers::writeInt(), FileHelpers::writeString(), and writeStringList().

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 174 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().

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 56 of file BinaryFormatter.cpp.

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

Referenced by writeHeader(), and writeXMLHeader().

bool BinaryFormatter::writeXMLHeader ( std::ostream &  into,
const std::string &  rootElement,
const std::string  xmlParams = "",
const std::string &  attrs = "",
const std::string &  comment = "" 
)
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]xmlParamsAdditional parameters (such as encoding) to include in the <?xml> declaration
[in]attrsAdditional attributes to save within the rootElement
[in]commentAdditional comment (saved in front the rootElement)
Todo:

Check which parameter is used herein

Describe what is saved

Implements OutputFormatter.

Definition at line 66 of file BinaryFormatter.cpp.

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

Field Documentation

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

The stack of begun xml elements.

Definition at line 340 of file BinaryFormatter.h.

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


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