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 /****************************************************************************/
15 // Output formatter for plain XML output
16 /****************************************************************************/
17 #ifndef PlainXMLFormatter_h
18 #define PlainXMLFormatter_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include "OutputFormatter.h"
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
39 public:
41  PlainXMLFormatter(const int defaultIndentation = 0);
42 
43 
45  virtual ~PlainXMLFormatter() { }
46 
47 
58  bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
59  const std::map<SumoXMLAttr, std::string>& attrs);
60 
61 
70  bool writeHeader(std::ostream& into, const SumoXMLTag& rootElement);
71 
72 
83  void openTag(std::ostream& into, const std::string& xmlElement);
84 
85 
93  void openTag(std::ostream& into, const SumoXMLTag& xmlElement);
94 
95 
102  bool closeTag(std::ostream& into, const std::string& comment = "");
103 
104 
110  void writePreformattedTag(std::ostream& into, const std::string& val);
111 
114  void writePadding(std::ostream& into, const std::string& val);
115 
116 
123  template <class T>
124  static void writeAttr(std::ostream& into, const std::string& attr, const T& val) {
125  into << " " << attr << "=\"" << toString(val, into.precision()) << "\"";
126  }
127 
128 
135  template <class T>
136  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val) {
137  into << " " << toString(attr) << "=\"" << toString(val, into.precision()) << "\"";
138  }
139 
140 
141 private:
143  std::vector<std::string> myXMLStack;
144 
147 
150 };
151 
152 
153 #endif
154 
155 /****************************************************************************/
156 
PlainXMLFormatter::writePadding
void writePadding(std::ostream &into, const std::string &val)
writes arbitrary padding
Definition: PlainXMLFormatter.cpp:109
PlainXMLFormatter::myDefaultIndentation
int myDefaultIndentation
The initial indentation level.
Definition: PlainXMLFormatter.h:146
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
PlainXMLFormatter::PlainXMLFormatter
PlainXMLFormatter(const int defaultIndentation=0)
Constructor.
Definition: PlainXMLFormatter.cpp:32
OutputFormatter
Abstract base class for output formatters.
Definition: OutputFormatter.h:51
PlainXMLFormatter::myXMLStack
std::vector< std::string > myXMLStack
The stack of begun xml elements.
Definition: PlainXMLFormatter.h:143
PlainXMLFormatter::writeHeader
bool writeHeader(std::ostream &into, const SumoXMLTag &rootElement)
Writes an XML header with optional configuration.
Definition: PlainXMLFormatter.cpp:38
OutputFormatter.h
PlainXMLFormatter
Output formatter for plain XML output.
Definition: PlainXMLFormatter.h:38
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
PlainXMLFormatter::writePreformattedTag
void writePreformattedTag(std::ostream &into, const std::string &val)
writes a preformatted tag to the device but ensures that any pending tags are closed
Definition: PlainXMLFormatter.cpp:100
PlainXMLFormatter::myHavePendingOpener
bool myHavePendingOpener
whether a closing ">" might be missing
Definition: PlainXMLFormatter.h:149
config.h
PlainXMLFormatter::writeXMLHeader
bool writeXMLHeader(std::ostream &into, const std::string &rootElement, const std::map< SumoXMLAttr, std::string > &attrs)
Writes an XML header with optional configuration.
Definition: PlainXMLFormatter.cpp:49
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
PlainXMLFormatter::openTag
void openTag(std::ostream &into, const std::string &xmlElement)
Opens an XML tag.
Definition: PlainXMLFormatter.cpp:66
PlainXMLFormatter::closeTag
bool closeTag(std::ostream &into, const std::string &comment="")
Closes the most recently opened tag.
Definition: PlainXMLFormatter.cpp:83
PlainXMLFormatter::~PlainXMLFormatter
virtual ~PlainXMLFormatter()
Destructor.
Definition: PlainXMLFormatter.h:45
PlainXMLFormatter::writeAttr
static void writeAttr(std::ostream &into, const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: PlainXMLFormatter.h:136
PlainXMLFormatter::writeAttr
static void writeAttr(std::ostream &into, const std::string &attr, const T &val)
writes an arbitrary attribute
Definition: PlainXMLFormatter.h:124