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
BinaryFormatter.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
#ifdef HAVE_VERSION_H
32
#include <version.h>
33
#endif
34
35
#include <
utils/common/ToString.h
>
36
#include <
utils/common/FileHelpers.h
>
37
#include <
utils/xml/SUMOXMLDefinitions.h
>
38
#include <
utils/geom/PositionVector.h
>
39
#include <
utils/geom/Boundary.h
>
40
#include "
BinaryFormatter.h
"
41
42
#ifdef CHECK_MEMORY_LEAKS
43
#include <
foreign/nvwa/debug_new.h
>
44
#endif // CHECK_MEMORY_LEAKS
45
46
47
// ===========================================================================
48
// member method definitions
49
// ===========================================================================
50
BinaryFormatter::BinaryFormatter
() {
51
}
52
53
54
void
55
BinaryFormatter::writeStringList
(std::ostream& into,
const
std::vector<std::string>& list) {
56
FileHelpers::writeByte
(into,
BF_LIST
);
57
FileHelpers::writeInt
(into, list.size());
58
for
(std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it) {
59
FileHelpers::writeByte
(into,
BF_STRING
);
60
FileHelpers::writeString
(into, *it);
61
}
62
}
63
64
bool
65
BinaryFormatter::writeXMLHeader
(std::ostream& into,
66
const
std::string& rootElement,
67
const
std::string xmlParams,
68
const
std::string& attrs,
69
const
std::string& comment) {
70
if
(
myXMLStack
.empty()) {
71
FileHelpers::writeByte
(into,
BF_BYTE
);
72
FileHelpers::writeByte
(into, 1);
73
FileHelpers::writeByte
(into,
BF_STRING
);
74
FileHelpers::writeString
(into,
VERSION_STRING
);
75
writeStringList
(into,
SUMOXMLDefinitions::Tags
.getStrings());
76
writeStringList
(into,
SUMOXMLDefinitions::Attrs
.getStrings());
77
writeStringList
(into,
SUMOXMLDefinitions::NodeTypes
.getStrings());
78
writeStringList
(into,
SUMOXMLDefinitions::EdgeFunctions
.getStrings());
79
if
(
SUMOXMLDefinitions::Tags
.hasString(rootElement)) {
80
openTag
(into, (
const
SumoXMLTag
)(
SUMOXMLDefinitions::Tags
.
get
(rootElement)));
81
return
true
;
82
}
83
}
84
return
false
;
85
}
86
87
88
void
89
BinaryFormatter::openTag
(std::ostream& into,
const
std::string& xmlElement) {
90
if
(
SUMOXMLDefinitions::Tags
.hasString(xmlElement)) {
91
openTag
(into, (
const
SumoXMLTag
)(
SUMOXMLDefinitions::Tags
.
get
(xmlElement)));
92
}
93
}
94
95
96
void
97
BinaryFormatter::openTag
(std::ostream& into,
const
SumoXMLTag
& xmlElement) {
98
myXMLStack
.push_back(xmlElement);
99
FileHelpers::writeByte
(into,
BF_XML_TAG_START
);
100
FileHelpers::writeInt
(into, xmlElement);
101
}
102
103
104
void
105
BinaryFormatter::closeOpener
(std::ostream& into) {
106
}
107
108
109
bool
110
BinaryFormatter::closeTag
(std::ostream& into,
bool
abbreviated) {
111
if
(!
myXMLStack
.empty()) {
112
FileHelpers::writeByte
(into,
BF_XML_TAG_END
);
113
FileHelpers::writeInt
(into,
myXMLStack
.back());
114
myXMLStack
.pop_back();
115
return
true
;
116
}
117
return
false
;
118
}
119
120
121
void
122
BinaryFormatter::writeAttr
(std::ostream& into,
const
std::string& attr,
const
std::string& val) {
123
if
(
SUMOXMLDefinitions::Attrs
.hasString(attr)) {
124
writeAttr
(into, (
const
SumoXMLAttr
)(
SUMOXMLDefinitions::Attrs
.
get
(attr)), val);
125
}
126
}
127
128
129
void
BinaryFormatter::writeAttr
(std::ostream& into,
const
SumoXMLAttr
attr,
const
SUMOReal
& val) {
130
BinaryFormatter::writeAttrHeader
(into, attr,
BF_FLOAT
);
131
FileHelpers::writeFloat
(into, val);
132
}
133
134
135
void
BinaryFormatter::writeAttr
(std::ostream& into,
const
SumoXMLAttr
attr,
const
int
& val) {
136
BinaryFormatter::writeAttrHeader
(into, attr,
BF_INTEGER
);
137
FileHelpers::writeInt
(into, val);
138
}
139
140
141
void
BinaryFormatter::writeAttr
(std::ostream& into,
const
SumoXMLAttr
attr,
const
SumoXMLNodeType
& val) {
142
BinaryFormatter::writeAttrHeader
(into, attr,
BF_NODE_TYPE
);
143
FileHelpers::writeByte
(into, val);
144
}
145
146
147
void
BinaryFormatter::writeAttr
(std::ostream& into,
const
SumoXMLAttr
attr,
const
SumoXMLEdgeFunc
& val) {
148
BinaryFormatter::writeAttrHeader
(into, attr,
BF_EDGE_FUNCTION
);
149
FileHelpers::writeByte
(into, val);
150
}
151
152
153
void
BinaryFormatter::writeAttr
(std::ostream& into,
const
SumoXMLAttr
attr,
const
Position
& val) {
154
if
(val.
z
() != 0.) {
155
BinaryFormatter::writeAttrHeader
(into, attr,
BF_POSITION_3D
);
156
FileHelpers::writeFloat
(into, val.
x
());
157
FileHelpers::writeFloat
(into, val.
y
());
158
FileHelpers::writeFloat
(into, val.
z
());
159
}
else
{
160
BinaryFormatter::writeAttrHeader
(into, attr,
BF_POSITION_2D
);
161
FileHelpers::writeFloat
(into, val.
x
());
162
FileHelpers::writeFloat
(into, val.
y
());
163
}
164
}
165
166
167
void
BinaryFormatter::writeAttr
(std::ostream& into,
const
SumoXMLAttr
attr,
const
PositionVector
& val) {
168
BinaryFormatter::writeAttrHeader
(into, attr,
BF_LIST
);
169
FileHelpers::writeInt
(into, val.
size
());
170
for
(PositionVector::ContType::const_iterator pos = val.
begin
(); pos != val.
end
(); ++pos) {
171
if
(pos->z() != 0.) {
172
FileHelpers::writeByte
(into,
BF_POSITION_3D
);
173
FileHelpers::writeFloat
(into, pos->x());
174
FileHelpers::writeFloat
(into, pos->y());
175
FileHelpers::writeFloat
(into, pos->z());
176
}
else
{
177
FileHelpers::writeByte
(into,
BF_POSITION_2D
);
178
FileHelpers::writeFloat
(into, pos->x());
179
FileHelpers::writeFloat
(into, pos->y());
180
}
181
}
182
}
183
184
185
void
BinaryFormatter::writeAttr
(std::ostream& into,
const
SumoXMLAttr
attr,
const
Boundary
& val) {
186
BinaryFormatter::writeAttrHeader
(into, attr,
BF_LIST
);
187
FileHelpers::writeInt
(into, 2);
188
FileHelpers::writeByte
(into,
BF_POSITION_2D
);
189
FileHelpers::writeFloat
(into, val.
xmin
());
190
FileHelpers::writeFloat
(into, val.
ymin
());
191
FileHelpers::writeByte
(into,
BF_POSITION_2D
);
192
FileHelpers::writeFloat
(into, val.
xmax
());
193
FileHelpers::writeFloat
(into, val.
ymax
());
194
}
195
196
/****************************************************************************/
197
build
buildd
sumo-0.15.0~dfsg
src
utils
iodevices
BinaryFormatter.cpp
Generated on Wed Jul 18 2012 22:58:31 for SUMO - Simulation of Urban MObility by
1.8.1.1