![]() |
Eclipse SUMO - Simulation of Urban MObility
|
Output formatter for CSV output. More...
#include <CSVFormatter.h>
Public Member Functions | |
| bool | closeTag (std::ostream &into, const std::string &comment="") |
| Closes the most recently opened tag. | |
| CSVFormatter (const std::string &columnNames, const char separator=';') | |
| Constructor. | |
| OutputFormatterType | getType () |
| Returns the type of formatter being used. | |
| void | openTag (std::ostream &into, const std::string &xmlElement) |
| Keeps track of an open XML tag by adding a new element to the stack. | |
| void | openTag (std::ostream &into, const SumoXMLTag &xmlElement) |
| Keeps track of an open XML tag by adding a new element to the stack. | |
| void | setExpectedAttributes (const SumoXMLAttrMask &expected, const int depth=2) |
| 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. | |
| template<class T > | |
| void | writeAttr (std::ostream &into, const std::string &attr, const T &val, const bool isNull) |
| template<class T > | |
| void | writeAttr (std::ostream &into, const SumoXMLAttr attr, const T &val, const bool isNull) |
| writes a named attribute | |
| virtual void | writePadding (std::ostream &into, const std::string &val) |
| Writes some whitespace to format the output. This method is only implemented for XML output. | |
| virtual void | writePreformattedTag (std::ostream &into, const std::string &val) |
| Writes a preformatted tag to the device but ensures that any pending tags are closed. This method is only implemented for XML output. | |
| void | writeTime (std::ostream &, const SumoXMLAttr attr, const SUMOTime val) |
| virtual 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 | ~CSVFormatter () |
| Destructor. | |
Private Member Functions | |
| void | checkAttr (const SumoXMLAttr attr) |
| Helper function to keep track of the written attributes and accumulate the header. It checks whether the written attribute is expected in the column based format. The check does only apply to the deepest level of the XML hierarchy and not to the order of the columns just to the presence. | |
| template<class ATTR_TYPE > | |
| void | checkHeader (const ATTR_TYPE &attr) |
Private Attributes | |
| std::vector< std::string > | myBufferedRows |
| partial rows buffered before the schema is known (depth < myMaxDepth) | |
| bool | myCheckColumns = false |
| whether the columns should be checked for completeness | |
| std::string | myCurrentTag |
| the currently read tag (only valid when generating the header) | |
| SumoXMLAttrMask | myExpectedAttrs |
| which CSV columns are expected (just for checking completeness) | |
| std::vector< std::string > | myHeader |
| the CSV header | |
| const std::string | myHeaderFormat |
| the format to use for the column names | |
| int | myMaxDepth = 2 |
| the maximum depth of the XML hierarchy (excluding the root element) | |
| bool | myNeedsWrite = false |
| whether any attribute has been written since the last row was emitted | |
| SumoXMLAttrMask | mySeenAttrs |
| which CSV columns have been set (just for checking completeness) | |
| const char | mySeparator |
| The value separator. | |
| const OutputFormatterType | myType |
| the type of formatter being used (XML, CSV, Parquet, etc.) | |
| std::vector< std::string > | myValues |
| the current attribute / column values | |
| bool | myWroteHeader = false |
| whether the CSV header line has been written | |
| std::vector< int > | myXMLStack |
| The number of attributes in the currently open XML elements. | |
Output formatter for CSV output.
Definition at line 34 of file CSVFormatter.h.
| CSVFormatter::CSVFormatter | ( | const std::string & | columnNames, |
| const char | separator = ';' |
||
| ) |
Constructor.
Definition at line 34 of file CSVFormatter.cpp.
References myHeaderFormat, and myWroteHeader.
|
inlinevirtual |
Destructor.
Definition at line 40 of file CSVFormatter.h.
|
inlineprivate |
Helper function to keep track of the written attributes and accumulate the header. It checks whether the written attribute is expected in the column based format. The check does only apply to the deepest level of the XML hierarchy and not to the order of the columns just to the presence.
| [in] | attr | The attribute (name) |
Definition at line 106 of file CSVFormatter.h.
References checkHeader(), myCheckColumns, myExpectedAttrs, myMaxDepth, mySeenAttrs, myXMLStack, TLF, and toString().
Referenced by writeAttr(), and writeTime().
|
inlineprivate |
Definition at line 117 of file CSVFormatter.h.
References myBufferedRows, myCurrentTag, myHeader, myHeaderFormat, myNeedsWrite, mySeparator, myValues, myWroteHeader, and toString().
Referenced by checkAttr(), and writeAttr().
|
virtual |
Closes the most recently opened tag.
| [in] | into | The output stream to use |
Implements OutputFormatter.
Definition at line 67 of file CSVFormatter.cpp.
References joinToString(), myBufferedRows, myCheckColumns, myHeader, myMaxDepth, myNeedsWrite, mySeenAttrs, mySeparator, myValues, myWroteHeader, myXMLStack, and WRITE_WARNING.
|
inlineinherited |
Returns the type of formatter being used.
Definition at line 150 of file OutputFormatter.h.
References OutputFormatter::myType.
Referenced by OutputDevice::isXML(), OutputDevice::writeAttr(), OutputDevice::writeFuncAttr(), and OutputDevice::writeOptionalAttr().
|
virtual |
Keeps track of an open XML tag by adding a new element to the stack.
| [in] | into | The output stream to use (unused) |
| [in] | xmlElement | Name of element to open (unused) |
Implements OutputFormatter.
Definition at line 43 of file CSVFormatter.cpp.
References myCurrentTag, myMaxDepth, myValues, myWroteHeader, myXMLStack, and WRITE_WARNINGF.
|
virtual |
Keeps track of an open XML tag by adding a new element to the stack.
| [in] | into | The output stream to use (unused) |
| [in] | xmlElement | Name of element to open (unused) |
Implements OutputFormatter.
Definition at line 55 of file CSVFormatter.cpp.
References myCurrentTag, myMaxDepth, myValues, myWroteHeader, myXMLStack, toString(), and WRITE_WARNINGF.
|
inlinevirtual |
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.
| [in] | expected | which attributes are to be written (at the deepest XML level) |
| [in] | depth | the maximum XML hierarchy depth (excluding the root) |
Reimplemented from OutputFormatter.
Definition at line 93 of file CSVFormatter.h.
References myCheckColumns, myExpectedAttrs, and myMaxDepth.
|
inline |
Definition at line 78 of file CSVFormatter.h.
References checkHeader(), myCheckColumns, myValues, and toString().
|
inline |
writes a named attribute
| [in] | into | The output stream to use |
| [in] | attr | The attribute (name) |
| [in] | val | The attribute value |
Definition at line 72 of file CSVFormatter.h.
References checkAttr(), myValues, and toString().
|
inlinevirtualinherited |
Writes some whitespace to format the output. This method is only implemented for XML output.
| [in] | into | The output stream to use |
| [in] | val | The whitespace |
Reimplemented in PlainXMLFormatter.
Definition at line 136 of file OutputFormatter.h.
References UNUSED_PARAMETER.
Referenced by OutputDevice::writePadding().
|
inlinevirtualinherited |
Writes a preformatted tag to the device but ensures that any pending tags are closed. This method is only implemented for XML output.
| [in] | into | The output stream to use |
| [in] | val | The preformatted data |
Reimplemented in PlainXMLFormatter.
Definition at line 125 of file OutputFormatter.h.
References UNUSED_PARAMETER.
Referenced by OutputDevice::writePreformattedTag().
|
inlinevirtual |
Implements OutputFormatter.
Definition at line 84 of file CSVFormatter.h.
References checkAttr(), myValues, and time2string().
|
inlinevirtualinherited |
Writes an XML header with optional configuration.
If something has been written (myXMLStack is not empty), nothing is written and false returned. The default implementation does nothing and returns false.
| [in] | into | The output stream to use |
| [in] | rootElement | The root element to use |
| [in] | attrs | Additional attributes to save within the rootElement |
| [in] | includeConfig | whether the current config should be included as XML comment |
Reimplemented in PlainXMLFormatter.
Definition at line 77 of file OutputFormatter.h.
References UNUSED_PARAMETER.
Referenced by OutputDevice::writeXMLHeader().
|
inlinevirtual |
Returns whether a header has been written. Useful to detect whether a file is being used by multiple sources.
Implements OutputFormatter.
Definition at line 89 of file CSVFormatter.h.
References myWroteHeader.
|
private |
partial rows buffered before the schema is known (depth < myMaxDepth)
Definition at line 164 of file CSVFormatter.h.
Referenced by checkHeader(), and closeTag().
|
private |
whether the columns should be checked for completeness
Definition at line 167 of file CSVFormatter.h.
Referenced by checkAttr(), closeTag(), setExpectedAttributes(), and writeAttr().
|
private |
the currently read tag (only valid when generating the header)
Definition at line 146 of file CSVFormatter.h.
Referenced by checkHeader(), openTag(), and openTag().
|
private |
which CSV columns are expected (just for checking completeness)
Definition at line 170 of file CSVFormatter.h.
Referenced by checkAttr(), and setExpectedAttributes().
|
private |
the CSV header
Definition at line 143 of file CSVFormatter.h.
Referenced by checkHeader(), and closeTag().
|
private |
the format to use for the column names
Definition at line 137 of file CSVFormatter.h.
Referenced by checkHeader(), and CSVFormatter().
|
private |
the maximum depth of the XML hierarchy (excluding the root element)
Definition at line 155 of file CSVFormatter.h.
Referenced by checkAttr(), closeTag(), openTag(), openTag(), and setExpectedAttributes().
|
private |
whether any attribute has been written since the last row was emitted
Definition at line 161 of file CSVFormatter.h.
Referenced by checkHeader(), and closeTag().
|
private |
which CSV columns have been set (just for checking completeness)
Definition at line 173 of file CSVFormatter.h.
Referenced by checkAttr(), and closeTag().
|
private |
The value separator.
Definition at line 140 of file CSVFormatter.h.
Referenced by checkHeader(), and closeTag().
|
privateinherited |
the type of formatter being used (XML, CSV, Parquet, etc.)
Definition at line 168 of file OutputFormatter.h.
Referenced by OutputFormatter::getType().
|
private |
the current attribute / column values
Definition at line 152 of file CSVFormatter.h.
Referenced by checkHeader(), closeTag(), openTag(), openTag(), writeAttr(), writeAttr(), and writeTime().
|
private |
whether the CSV header line has been written
Definition at line 158 of file CSVFormatter.h.
Referenced by checkHeader(), closeTag(), CSVFormatter(), openTag(), openTag(), and wroteHeader().
|
private |
The number of attributes in the currently open XML elements.
Definition at line 149 of file CSVFormatter.h.
Referenced by checkAttr(), closeTag(), openTag(), and openTag().