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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Output formatter for plain XML output
19 /****************************************************************************/
20 #ifndef PlainXMLFormatter_h
21 #define PlainXMLFormatter_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "OutputFormatter.h"
34 
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
46 public:
48  PlainXMLFormatter(const int defaultIndentation = 0);
49 
50 
52  virtual ~PlainXMLFormatter() { }
53 
54 
65  bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
66  const std::map<SumoXMLAttr, std::string>& attrs);
67 
68 
77  bool writeHeader(std::ostream& into, const SumoXMLTag& rootElement);
78 
79 
90  void openTag(std::ostream& into, const std::string& xmlElement);
91 
92 
100  void openTag(std::ostream& into, const SumoXMLTag& xmlElement);
101 
102 
109  bool closeTag(std::ostream& into);
110 
111 
117  void writePreformattedTag(std::ostream& into, const std::string& val);
118 
119 
126  template <class T>
127  static void writeAttr(std::ostream& into, const std::string& attr, const T& val) {
128  into << " " << attr << "=\"" << toString(val, into.precision()) << "\"";
129  }
130 
131 
138  template <class T>
139  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val) {
140  into << " " << toString(attr) << "=\"" << toString(val, into.precision()) << "\"";
141  }
142 
143 
144 private:
146  std::vector<std::string> myXMLStack;
147 
150 
153 };
154 
155 
156 #endif
157 
158 /****************************************************************************/
159 
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.
bool closeTag(std::ostream &into)
Closes the most recently opened tag.
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:55
Output formatter for plain XML output.
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 writePreformattedTag(std::ostream &into, const std::string &val)
writes a preformatted tag to the device but ensures that any pending tags are closed ...