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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Output formatter for plain XML output
17 /****************************************************************************/
18 #ifndef PlainXMLFormatter_h
19 #define PlainXMLFormatter_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include "OutputFormatter.h"
28 
29 
30 // ===========================================================================
31 // class definitions
32 // ===========================================================================
40 public:
42  PlainXMLFormatter(const int defaultIndentation = 0);
43 
44 
46  virtual ~PlainXMLFormatter() { }
47 
48 
59  bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
60  const std::map<SumoXMLAttr, std::string>& attrs);
61 
62 
71  bool writeHeader(std::ostream& into, const SumoXMLTag& rootElement);
72 
73 
84  void openTag(std::ostream& into, const std::string& xmlElement);
85 
86 
94  void openTag(std::ostream& into, const SumoXMLTag& xmlElement);
95 
96 
103  bool closeTag(std::ostream& into, const std::string& comment = "");
104 
105 
111  void writePreformattedTag(std::ostream& into, const std::string& val);
112 
115  void writePadding(std::ostream& into, const std::string& val);
116 
117 
124  template <class T>
125  static void writeAttr(std::ostream& into, const std::string& attr, const T& val) {
126  into << " " << attr << "=\"" << toString(val, into.precision()) << "\"";
127  }
128 
129 
136  template <class T>
137  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val) {
138  into << " " << toString(attr) << "=\"" << toString(val, into.precision()) << "\"";
139  }
140 
141 
142 private:
144  std::vector<std::string> myXMLStack;
145 
148 
151 };
152 
153 
154 #endif
155 
156 /****************************************************************************/
157 
SumoXMLTag
Numbers representing SUMO-XML - element names.
Abstract base class for output formatters.
bool writeXMLHeader(std::ostream &into, const std::string &rootElement, const std::map< SumoXMLAttr, std::string > &attrs)
Writes an XML header with optional configuration.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void openTag(std::ostream &into, const std::string &xmlElement)
Opens an XML tag.
bool myHavePendingOpener
whether a closing ">" might be missing
virtual ~PlainXMLFormatter()
Destructor.
static void writeAttr(std::ostream &into, const SumoXMLAttr attr, const T &val)
writes a named attribute
static void writeAttr(std::ostream &into, const std::string &attr, const T &val)
writes an arbitrary attribute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
Output formatter for plain XML output.
bool closeTag(std::ostream &into, const std::string &comment="")
Closes the most recently opened tag.
PlainXMLFormatter(const int defaultIndentation=0)
Constructor.
int myDefaultIndentation
The initial indentation level.
std::vector< std::string > myXMLStack
The stack of begun xml elements.
bool writeHeader(std::ostream &into, const SumoXMLTag &rootElement)
Writes an XML header with optional configuration.
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 ...