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-2025 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>
27
28
29// ===========================================================================
30// class declarations
31// ===========================================================================
32class Boundary;
33class Position;
34class PositionVector;
35class RGBColor;
36
37
38// ===========================================================================
39// class definitions
40// ===========================================================================
42 XML,
43#ifdef HAVE_PARQUET
44 PARQUET,
45#endif
46 CSV
47};
48
58public:
61
63 virtual ~OutputFormatter() { }
64
77 virtual bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
78 const std::map<SumoXMLAttr, std::string>& attrs,
79 bool includeConfig = true) {
80 UNUSED_PARAMETER(into);
81 UNUSED_PARAMETER(rootElement);
82 UNUSED_PARAMETER(attrs);
83 UNUSED_PARAMETER(includeConfig);
84 return false;
85 }
86
97 virtual void openTag(std::ostream& into, const std::string& xmlElement) = 0;
98
106 virtual void openTag(std::ostream& into, const SumoXMLTag& xmlElement) = 0;
107
108 virtual void writeTime(std::ostream& into, const SumoXMLAttr attr, const SUMOTime val) = 0;
109
116 virtual bool closeTag(std::ostream& into, const std::string& comment = "") = 0;
117
124 virtual void writePreformattedTag(std::ostream& into, const std::string& val) {
125 UNUSED_PARAMETER(into);
126 UNUSED_PARAMETER(val);
127 throw ProcessError("The selected file format does not support preformatted tags.");
128 }
129
135 virtual void writePadding(std::ostream& into, const std::string& val) {
136 UNUSED_PARAMETER(into);
137 UNUSED_PARAMETER(val);
138 }
139
144 virtual bool wroteHeader() const = 0;
145
150 return myType;
151 }
152
160 virtual void setExpectedAttributes(const SumoXMLAttrMask& expected, const int depth = 2) {
161 UNUSED_PARAMETER(expected);
162 UNUSED_PARAMETER(depth);
163 }
164
165private:
168};
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.
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 writeXMLHeader(std::ostream &into, const std::string &rootElement, const std::map< SumoXMLAttr, std::string > &attrs, bool includeConfig=true)
Writes an XML header with optional configuration.
OutputFormatterType getType()
Returns the type of formatter being used.
virtual 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 tabl...
virtual bool closeTag(std::ostream &into, const std::string &comment="")=0
Closes the most recently opened tag and optinally add a comment.
virtual void openTag(std::ostream &into, const std::string &xmlElement)=0
Opens an XML tag.
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)