Eclipse SUMO - Simulation of Urban MObility
PlainXMLFormatter.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2020 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 // Output formatter for plain XML output
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include "OutputFormatter.h"
25 
26 
27 // ===========================================================================
28 // class definitions
29 // ===========================================================================
37 public:
39  PlainXMLFormatter(const int defaultIndentation = 0);
40 
41 
43  virtual ~PlainXMLFormatter() { }
44 
45 
56  bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
57  const std::map<SumoXMLAttr, std::string>& attrs);
58 
59 
68  bool writeHeader(std::ostream& into, const SumoXMLTag& rootElement);
69 
70 
81  void openTag(std::ostream& into, const std::string& xmlElement);
82 
83 
91  void openTag(std::ostream& into, const SumoXMLTag& xmlElement);
92 
93 
100  bool closeTag(std::ostream& into, const std::string& comment = "");
101 
102 
108  void writePreformattedTag(std::ostream& into, const std::string& val);
109 
112  void writePadding(std::ostream& into, const std::string& val);
113 
114 
121  template <class T>
122  static void writeAttr(std::ostream& into, const std::string& attr, const T& val) {
123  into << " " << attr << "=\"" << toString(val, into.precision()) << "\"";
124  }
125 
126 
133  template <class T>
134  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val) {
135  into << " " << toString(attr) << "=\"" << toString(val, into.precision()) << "\"";
136  }
137 
138 
139 private:
141  std::vector<std::string> myXMLStack;
142 
145 
148 };
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Abstract base class for output formatters.
Output formatter for plain XML output.
bool closeTag(std::ostream &into, const std::string &comment="")
Closes the most recently opened tag.
bool myHavePendingOpener
whether a closing ">" might be missing
bool writeXMLHeader(std::ostream &into, const std::string &rootElement, const std::map< SumoXMLAttr, std::string > &attrs)
Writes an XML header with optional configuration.
PlainXMLFormatter(const int defaultIndentation=0)
Constructor.
static void writeAttr(std::ostream &into, const SumoXMLAttr attr, const T &val)
writes a named attribute
int myDefaultIndentation
The initial indentation level.
static void writeAttr(std::ostream &into, const std::string &attr, const T &val)
writes an arbitrary attribute
bool writeHeader(std::ostream &into, const SumoXMLTag &rootElement)
Writes an XML header with optional configuration.
std::vector< std::string > myXMLStack
The stack of begun xml elements.
void writePadding(std::ostream &into, const std::string &val)
writes arbitrary padding
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 ~PlainXMLFormatter()
Destructor.
void openTag(std::ostream &into, const std::string &xmlElement)
Opens an XML tag.