SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ToString.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // -------------------
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef ToString_h
23 #define ToString_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <sstream>
36 #include <string>
37 #include <iomanip>
40 #include "StdDefs.h"
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
49 template <class T>
50 inline std::string toString(const T& t, std::streamsize accuracy = OUTPUT_ACCURACY) {
51  std::ostringstream oss;
52  oss.setf(std::ios::fixed , std::ios::floatfield);
53  oss << std::setprecision(accuracy);
54  oss << t;
55  return oss.str();
56 }
57 
58 
59 template <>
60 inline std::string toString<SumoXMLTag>(const SumoXMLTag& tag, std::streamsize accuracy) {
61  UNUSED_PARAMETER(accuracy);
63 }
64 
65 
66 template <>
67 inline std::string toString<SumoXMLAttr>(const SumoXMLAttr& attr, std::streamsize accuracy) {
68  UNUSED_PARAMETER(accuracy);
70 }
71 
72 
73 template <>
74 inline std::string toString<SumoXMLNodeType>(const SumoXMLNodeType& nodeType, std::streamsize accuracy) {
75  UNUSED_PARAMETER(accuracy);
77 }
78 
79 
80 template <>
81 inline std::string toString<SumoXMLEdgeFunc>(const SumoXMLEdgeFunc& edgeFunc, std::streamsize accuracy) {
82  UNUSED_PARAMETER(accuracy);
84 }
85 
86 
87 template <>
88 inline std::string toString<SUMOVehicleClass>(const SUMOVehicleClass& vClass, std::streamsize accuracy) {
89  UNUSED_PARAMETER(accuracy);
90  return SumoVehicleClassStrings.getString(vClass);
91 }
92 
93 
94 template <>
95 inline std::string toString<LaneSpreadFunction>(const LaneSpreadFunction& lsf, std::streamsize accuracy) {
96  UNUSED_PARAMETER(accuracy);
98 }
99 
100 
101 template <>
102 inline std::string toString<LinkState>(const LinkState& linkState, std::streamsize accuracy) {
103  UNUSED_PARAMETER(accuracy);
104  return SUMOXMLDefinitions::LinkStates.getString(linkState);
105 }
106 
107 template <>
108 inline std::string toString<LinkDirection>(const LinkDirection& linkDir, std::streamsize accuracy) {
109  UNUSED_PARAMETER(accuracy);
111 }
112 
113 template <>
114 inline std::string toString<TrafficLightType>(const TrafficLightType& type, std::streamsize accuracy) {
115  UNUSED_PARAMETER(accuracy);
117 }
118 
119 
120 template <typename T, typename T_BETWEEN>
121 inline std::string joinToString(const std::vector<T>& v, const T_BETWEEN& between, std::streamsize accuracy = OUTPUT_ACCURACY) {
122  std::ostringstream oss;
123  bool connect = false;
124  for (typename std::vector<T>::const_iterator it = v.begin(); it != v.end(); ++it) {
125  if (connect) {
126  oss << toString(between, accuracy);
127  } else {
128  connect = true;
129  }
130  oss << toString(*it, accuracy);
131  }
132  return oss.str();
133 }
134 
135 
136 template <typename T, typename T_BETWEEN>
137 inline std::string joinToString(const std::set<T>& s, const T_BETWEEN& between, std::streamsize accuracy = OUTPUT_ACCURACY) {
138  std::ostringstream oss;
139  bool connect = false;
140  for (typename std::set<T>::const_iterator it = s.begin(); it != s.end(); ++it) {
141  if (connect) {
142  oss << toString(between, accuracy);
143  } else {
144  connect = true;
145  }
146  oss << toString(*it, accuracy);
147  }
148  return oss.str();
149 }
150 
151 #endif
152 
153 /****************************************************************************/
154