SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlainXMLFormatter.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Static storage of an output device and its base (abstract) implementation
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
10 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <utils/common/ToString.h>
33 #include "PlainXMLFormatter.h"
34 
35 #ifdef CHECK_MEMORY_LEAKS
36 #include <foreign/nvwa/debug_new.h>
37 #endif // CHECK_MEMORY_LEAKS
38 
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
43 PlainXMLFormatter::PlainXMLFormatter(const unsigned int defaultIndentation)
44  : myDefaultIndentation(defaultIndentation) {
45 }
46 
47 
48 bool
49 PlainXMLFormatter::writeXMLHeader(std::ostream& into, const std::string& rootElement, const std::string xmlParams,
50  const std::string& attrs, const std::string& comment) {
51  if (myXMLStack.empty()) {
52  OptionsCont::getOptions().writeXMLHeader(into, xmlParams);
53  if (comment != "") {
54  into << comment << "\n";
55  }
56  openTag(into, rootElement);
57  if (attrs != "") {
58  into << " " << attrs;
59  }
60  into << ">\n";
61  return true;
62  }
63  return false;
64 }
65 
66 
67 void
68 PlainXMLFormatter::openTag(std::ostream& into, const std::string& xmlElement) {
69  into << std::string(4 * (myXMLStack.size() + myDefaultIndentation), ' ') << "<" << xmlElement;
70  myXMLStack.push_back(xmlElement);
71 }
72 
73 
74 void
75 PlainXMLFormatter::openTag(std::ostream& into, const SumoXMLTag& xmlElement) {
76  openTag(into, toString(xmlElement));
77 }
78 
79 
80 void
81 PlainXMLFormatter::closeOpener(std::ostream& into) {
82  into << ">\n";
83 }
84 
85 
86 bool
87 PlainXMLFormatter::closeTag(std::ostream& into, bool abbreviated) {
88  if (!myXMLStack.empty()) {
89  if (abbreviated) {
90  into << "/>\n";
91  } else {
92  const std::string indent(4 * (myXMLStack.size() + myDefaultIndentation - 1), ' ');
93  into << indent << "</" << myXMLStack.back() << ">\n";
94  }
95  myXMLStack.pop_back();
96  return true;
97  }
98  return false;
99 }
100 
101 
102 void
103 PlainXMLFormatter::writeAttr(std::ostream& into, const std::string& attr, const std::string& val) {
104  into << " " << attr << "=\"" << val << "\"";
105 }
106 
107 /****************************************************************************/
108