SUMO - Simulation of Urban MObility
|
Output formatter for plain XML output. More...
#include <BinaryFormatter.h>
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_COLOR, BF_NODE_TYPE, BF_EDGE_FUNCTION } |
data types in binary output More... |
Public Member Functions | |
BinaryFormatter () | |
Constructor. | |
void | closeOpener (std::ostream &into) |
Ends the most recently opened element start. | |
bool | closeTag (std::ostream &into, bool abbreviated=false) |
Closes the most recently opened tag. | |
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. | |
void | writeAttr (std::ostream &into, const std::string &attr, const std::string &val) |
writes an arbitrary attribute | |
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. | |
virtual | ~BinaryFormatter () |
Destructor. |
Static Public Member Functions | |
template<typename T > | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const T &val) |
writes a named attribute | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const SUMOReal &val) |
writes a named float attribute | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const int &val) |
writes a named integer attribute | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const SumoXMLNodeType &val) |
writes a node type attribute | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const SumoXMLEdgeFunc &val) |
writes an edge function attribute | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const Position &val) |
writes a position attribute | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const PositionVector &val) |
writes a position vector attribute | |
static void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const Boundary &val) |
writes a boundary attribute |
Private Member Functions | |
void | writeStringList (std::ostream &into, const std::vector< std::string > &list) |
writes a list of strings |
Static Private Member Functions | |
static void | writeAttrHeader (std::ostream &into, const SumoXMLAttr attr, const DataType type) |
writes the header for an arbitrary attribute |
Private Attributes | |
std::vector< SumoXMLTag > | myXMLStack |
The stack of begun xml elements. |
Output formatter for plain XML output.
BinaryFormatter format XML like output into the output stream.
Definition at line 54 of file BinaryFormatter.h.
data types in binary output
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_COLOR | |
BF_NODE_TYPE | |
BF_EDGE_FUNCTION |
Definition at line 57 of file BinaryFormatter.h.
BinaryFormatter::BinaryFormatter | ( | ) |
Constructor.
Definition at line 50 of file BinaryFormatter.cpp.
|
inlinevirtual |
Destructor.
Definition at line 95 of file BinaryFormatter.h.
|
virtual |
Ends the most recently opened element start.
Does nothing.
[in] | into | The output stream to use |
Implements OutputFormatter.
Definition at line 105 of file BinaryFormatter.cpp.
Closes the most recently opened tag.
[in] | into | The output stream to use |
[in] | name | whether abbreviated closing is performed |
Implements OutputFormatter.
Definition at line 110 of file BinaryFormatter.cpp.
References BF_XML_TAG_END, myXMLStack, FileHelpers::writeByte(), and FileHelpers::writeInt().
|
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 89 of file BinaryFormatter.cpp.
References SUMOXMLDefinitions::Tags.
Referenced by 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 97 of file BinaryFormatter.cpp.
References BF_XML_TAG_START, myXMLStack, FileHelpers::writeByte(), and FileHelpers::writeInt().
|
virtual |
writes an arbitrary attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Implements OutputFormatter.
Definition at line 122 of file BinaryFormatter.cpp.
References SUMOXMLDefinitions::Attrs.
|
static |
writes a named attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 272 of file BinaryFormatter.h.
References BF_STRING, toString(), writeAttrHeader(), and FileHelpers::writeString().
|
static |
writes a named float attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 129 of file BinaryFormatter.cpp.
References BF_FLOAT, writeAttrHeader(), and FileHelpers::writeFloat().
|
static |
writes a named integer attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 135 of file BinaryFormatter.cpp.
References BF_INTEGER, writeAttrHeader(), and FileHelpers::writeInt().
|
static |
writes a node type attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 141 of file BinaryFormatter.cpp.
References BF_NODE_TYPE, writeAttrHeader(), and FileHelpers::writeByte().
|
static |
writes an edge function attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 147 of file BinaryFormatter.cpp.
References BF_EDGE_FUNCTION, writeAttrHeader(), and FileHelpers::writeByte().
|
static |
writes a position attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 153 of file BinaryFormatter.cpp.
References BF_POSITION_2D, BF_POSITION_3D, writeAttrHeader(), FileHelpers::writeFloat(), Position::x(), Position::y(), and Position::z().
|
static |
writes a position vector attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 167 of file BinaryFormatter.cpp.
References PositionVector::begin(), BF_LIST, BF_POSITION_2D, BF_POSITION_3D, PositionVector::end(), PositionVector::size(), writeAttrHeader(), FileHelpers::writeByte(), FileHelpers::writeFloat(), and FileHelpers::writeInt().
|
static |
writes a boundary attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | val | The attribute value |
Definition at line 185 of file BinaryFormatter.cpp.
References BF_LIST, BF_POSITION_2D, writeAttrHeader(), FileHelpers::writeByte(), FileHelpers::writeFloat(), FileHelpers::writeInt(), Boundary::xmax(), Boundary::xmin(), Boundary::ymax(), and Boundary::ymin().
|
inlinestaticprivate |
writes the header for an arbitrary attribute
[in] | into | The output stream to use |
[in] | attr | The attribute (name) |
[in] | type | The attribute type |
Definition at line 248 of file BinaryFormatter.h.
References BF_XML_ATTRIBUTE, FileHelpers::writeByte(), and FileHelpers::writeInt().
Referenced by writeAttr().
|
private |
writes a list of strings
[in] | into | The output stream to use |
[in] | list | the list to write |
Definition at line 55 of file BinaryFormatter.cpp.
References BF_LIST, BF_STRING, FileHelpers::writeByte(), FileHelpers::writeInt(), and FileHelpers::writeString().
Referenced by writeXMLHeader().
|
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] | xmlParams | Additional parameters (such as encoding) to include in the <?xml> declaration |
[in] | attrs | Additional attributes to save within the rootElement |
[in] | comment | Additional comment (saved in front the rootElement) |
Check which parameter is used herein
Describe what is saved
Implements OutputFormatter.
Definition at line 65 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().
|
private |
The stack of begun xml elements.
Definition at line 265 of file BinaryFormatter.h.
Referenced by closeTag(), openTag(), and writeXMLHeader().