SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryFormatter.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // Output formatter for plain XML output
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 #ifndef BinaryFormatter_h
21 #define BinaryFormatter_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
34 #include "OutputFormatter.h"
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class Position;
41 class PositionVector;
42 class Boundary;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
55 public:
57  enum DataType {
88  };
89 
92 
93 
95  virtual ~BinaryFormatter() { }
96 
97 
111  bool writeXMLHeader(std::ostream& into, const std::string& rootElement,
112  const std::string xmlParams = "",
113  const std::string& attrs = "",
114  const std::string& comment = "");
115 
116 
127  void openTag(std::ostream& into, const std::string& xmlElement);
128 
129 
137  void openTag(std::ostream& into, const SumoXMLTag& xmlElement);
138 
139 
146  void closeOpener(std::ostream& into);
147 
148 
156  bool closeTag(std::ostream& into, bool abbreviated=false);
157 
158 
165  void writeAttr(std::ostream& into, const std::string& attr, const std::string& val);
166 
167 
174  template <typename T>
175  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val);
176 
177 
184  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const SUMOReal& val);
185 
186 
193  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const int& val);
194 
195 
202  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const SumoXMLNodeType& val);
203 
204 
211  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const SumoXMLEdgeFunc& val);
212 
213 
220  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const Position& val);
221 
222 
229  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const PositionVector& val);
230 
231 
238  static void writeAttr(std::ostream& into, const SumoXMLAttr attr, const Boundary& val);
239 
240 
241 private:
248  static inline void writeAttrHeader(std::ostream& into, const SumoXMLAttr attr, const DataType type) {
249  FileHelpers::writeByte(into, static_cast<unsigned char>(BF_XML_ATTRIBUTE));
250  FileHelpers::writeInt(into, attr);
251  FileHelpers::writeByte(into, static_cast<unsigned char>(type));
252  }
253 
254 
260  void writeStringList(std::ostream& into, const std::vector<std::string>& list);
261 
262 
263 private:
265  std::vector<SumoXMLTag> myXMLStack;
266 
267 
268 };
269 
270 
271 template <typename T>
272 void BinaryFormatter::writeAttr(std::ostream& into, const SumoXMLAttr attr, const T& val) {
274  FileHelpers::writeString(into, toString(val, into.precision()));
275 }
276 
277 
278 #endif
279 
280 /****************************************************************************/
281