Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
OutputFormatter.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// Abstract base class for output formatters
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24#include <string>
25#include <vector>
29
30
31// ===========================================================================
32// class declarations
33// ===========================================================================
34class Boundary;
35class Position;
36class PositionVector;
37class RGBColor;
38
39
40// ===========================================================================
41// class definitions
42// ===========================================================================
44 XML,
45#ifdef HAVE_PARQUET
46 PARQUET,
47#endif
48 CSV
49};
50
60public:
63
65 virtual ~OutputFormatter() { }
66
79 virtual bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
80 const std::map<SumoXMLAttr, std::string>& attrs, bool writeMetadata,
81 bool includeConfig) {
82 UNUSED_PARAMETER(into);
83 UNUSED_PARAMETER(rootElement);
84 UNUSED_PARAMETER(attrs);
85 UNUSED_PARAMETER(writeMetadata);
86 UNUSED_PARAMETER(includeConfig);
87 return false;
88 }
89
100 virtual void openTag(std::ostream& into, const std::string& xmlElement) = 0;
101
109 virtual void openTag(std::ostream& into, const SumoXMLTag& xmlElement) = 0;
110
111 virtual void writeTime(std::ostream& into, const SumoXMLAttr attr, const SUMOTime val) = 0;
112
119 virtual bool closeTag(std::ostream& into, const std::string& comment = "") = 0;
120
127 virtual void writePreformattedTag(std::ostream& into, const std::string& val) {
128 UNUSED_PARAMETER(into);
129 UNUSED_PARAMETER(val);
130 throw ProcessError("The selected file format does not support preformatted tags.");
131 }
132
138 virtual void writePadding(std::ostream& into, const std::string& val) {
139 UNUSED_PARAMETER(into);
140 UNUSED_PARAMETER(val);
141 }
142
147 virtual bool wroteHeader() const = 0;
148
153 return myType;
154 }
155
163 virtual void setExpectedAttributes(const SumoXMLAttrMask& expected, const int depth) {
164 UNUSED_PARAMETER(expected);
165 UNUSED_PARAMETER(depth);
166 }
167
168private:
171};
long long int SUMOTime
Definition GUI.h:36
OutputFormatterType
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::bitset< 96 > SumoXMLAttrMask
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
Abstract base class for output formatters.
OutputFormatterType getType() const
Returns the type of formatter being used.
OutputFormatter(OutputFormatterType t)
Constructor.
virtual ~OutputFormatter()
Destructor.
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....
virtual void writeTime(std::ostream &into, const SumoXMLAttr attr, const SUMOTime val)=0
virtual bool closeTag(std::ostream &into, const std::string &comment="")=0
Closes the most recently opened tag and optinally add a comment.
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.
virtual void openTag(std::ostream &into, const std::string &xmlElement)=0
Opens an XML tag.
virtual void setExpectedAttributes(const SumoXMLAttrMask &expected, const int depth)
Set the expected attributes to write. This is used for tracking which attributes are expected in tabl...
const OutputFormatterType myType
the type of formatter being used (XML, CSV, Parquet, etc.)
virtual bool wroteHeader() const =0
Returns whether a header has been written. Useful to detect whether a file is being used by multiple ...
virtual void openTag(std::ostream &into, const SumoXMLTag &xmlElement)=0
Opens an XML tag.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
#define UNUSED_PARAMETER(x)