SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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 unsigned int defaultIndentation = 0);
50 
51 
53  virtual ~PlainXMLFormatter() { }
54 
55 
68  bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
69  const std::string& attrs = "",
70  const std::string& comment = "");
71 
72 
81  bool writeHeader(std::ostream& into, const SumoXMLTag& rootElement);
82 
83 
94  void openTag(std::ostream& into, const std::string& xmlElement);
95 
96 
104  void openTag(std::ostream& into, const SumoXMLTag& xmlElement);
105 
106 
113  bool closeTag(std::ostream& into);
114 
115 
121  void writePreformattedTag(std::ostream& into, const std::string& val);
122 
123 
130  template <class T>
131  static void writeAttr(std::ostream& into, const std::string& attr, const T& val) {
132  into << " " << attr << "=\"" << toString(val, into.precision()) << "\"";
133  }
134 
135 
142  template <class T>
143  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val) {
144  into << " " << toString(attr) << "=\"" << toString(val, into.precision()) << "\"";
145  }
146 
147 
148 private:
150  std::vector<std::string> myXMLStack;
151 
153  unsigned int myDefaultIndentation;
154 
157 };
158 
159 
160 #endif
161 
162 /****************************************************************************/
163 
SumoXMLTag
Numbers representing SUMO-XML - element names.
Abstract base class for output formatters.
unsigned int myDefaultIndentation
The initial indentation level.
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
Output formatter for plain XML output.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
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.
bool writeXMLHeader(std::ostream &into, const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
PlainXMLFormatter(const unsigned int defaultIndentation=0)
Constructor.
void writePreformattedTag(std::ostream &into, const std::string &val)
writes a preformatted tag to the device but ensures that any pending tags are closed ...