SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
PlainXMLFormatter.cpp
Go to the documentation of this file.
1
/****************************************************************************/
8
// Static storage of an output device and its base (abstract) implementation
9
/****************************************************************************/
10
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11
// Copyright (C) 2012-2014 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
22
23
// ===========================================================================
24
// included modules
25
// ===========================================================================
26
#ifdef _MSC_VER
27
#include <
windows_config.h
>
28
#else
29
#include <
config.h
>
30
#endif
31
32
#include <
utils/common/ToString.h
>
33
#include <
utils/options/OptionsCont.h
>
34
#include "
PlainXMLFormatter.h
"
35
36
#ifdef CHECK_MEMORY_LEAKS
37
#include <
foreign/nvwa/debug_new.h
>
38
#endif // CHECK_MEMORY_LEAKS
39
40
41
// ===========================================================================
42
// member method definitions
43
// ===========================================================================
44
PlainXMLFormatter::PlainXMLFormatter
(
const
unsigned
int
defaultIndentation)
45
: myDefaultIndentation(defaultIndentation), myHavePendingOpener(false) {
46
}
47
48
49
bool
50
PlainXMLFormatter::writeHeader
(std::ostream& into,
const
SumoXMLTag
& rootElement) {
51
if
(
myXMLStack
.empty()) {
52
OptionsCont::getOptions
().
writeXMLHeader
(into);
53
openTag
(into, rootElement);
54
return
true
;
55
}
56
return
false
;
57
}
58
59
60
bool
61
PlainXMLFormatter::writeXMLHeader
(std::ostream& into,
const
std::string& rootElement,
62
const
std::string& attrs,
const
std::string& comment) {
63
if
(
myXMLStack
.empty()) {
64
OptionsCont::getOptions
().
writeXMLHeader
(into);
65
if
(comment !=
""
) {
66
into << comment <<
"\n"
;
67
}
68
openTag
(into, rootElement);
69
if
(attrs !=
""
) {
70
into <<
" "
<< attrs;
71
}
72
into <<
">\n"
;
73
myHavePendingOpener
=
false
;
74
return
true
;
75
}
76
return
false
;
77
}
78
79
80
void
81
PlainXMLFormatter::openTag
(std::ostream& into,
const
std::string& xmlElement) {
82
if
(
myHavePendingOpener
) {
83
into <<
">\n"
;
84
}
85
myHavePendingOpener
=
true
;
86
into << std::string(4 * (
myXMLStack
.size() +
myDefaultIndentation
),
' '
) <<
"<"
<< xmlElement;
87
myXMLStack
.push_back(xmlElement);
88
}
89
90
91
void
92
PlainXMLFormatter::openTag
(std::ostream& into,
const
SumoXMLTag
& xmlElement) {
93
openTag
(into,
toString
(xmlElement));
94
}
95
96
97
bool
98
PlainXMLFormatter::closeTag
(std::ostream& into) {
99
if
(!
myXMLStack
.empty()) {
100
if
(
myHavePendingOpener
) {
101
into <<
"/>\n"
;
102
myHavePendingOpener
=
false
;
103
}
else
{
104
const
std::string indent(4 * (
myXMLStack
.size() +
myDefaultIndentation
- 1),
' '
);
105
into << indent <<
"</"
<<
myXMLStack
.back() <<
">\n"
;
106
}
107
myXMLStack
.pop_back();
108
return
true
;
109
}
110
return
false
;
111
}
112
113
114
void
115
PlainXMLFormatter::writePreformattedTag
(std::ostream& into,
const
std::string& val) {
116
if
(
myHavePendingOpener
) {
117
into <<
">\n"
;
118
myHavePendingOpener
=
false
;
119
}
120
into << val;
121
}
122
123
/****************************************************************************/
124
tmp
buildd
sumo-0.21.0+dfsg
src
utils
iodevices
PlainXMLFormatter.cpp
Generated on Thu Nov 20 2014 19:49:58 for SUMO - Simulation of Urban MObility by
1.8.1.2