SUMO - Simulation of Urban MObility
PlainXMLFormatter.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Output formatter for plain XML output
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef PlainXMLFormatter_h
22 #define PlainXMLFormatter_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "OutputFormatter.h"
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
47 public:
49  PlainXMLFormatter(const int defaultIndentation = 0);
50 
51 
53  virtual ~PlainXMLFormatter() { }
54 
55 
66  bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
67  const std::map<SumoXMLAttr, std::string>& attrs);
68 
69 
78  bool writeHeader(std::ostream& into, const SumoXMLTag& rootElement);
79 
80 
91  void openTag(std::ostream& into, const std::string& xmlElement);
92 
93 
101  void openTag(std::ostream& into, const SumoXMLTag& xmlElement);
102 
103 
110  bool closeTag(std::ostream& into);
111 
112 
118  void writePreformattedTag(std::ostream& into, const std::string& val);
119 
120 
127  template <class T>
128  static void writeAttr(std::ostream& into, const std::string& attr, const T& val) {
129  into << " " << attr << "=\"" << toString(val, into.precision()) << "\"";
130  }
131 
132 
139  template <class T>
140  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val) {
141  into << " " << toString(attr) << "=\"" << toString(val, into.precision()) << "\"";
142  }
143 
144 
145 private:
147  std::vector<std::string> myXMLStack;
148 
151 
154 };
155 
156 
157 #endif
158 
159 /****************************************************************************/
160 
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:56
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 ...