SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // ------------------- 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef ToString_h 00023 #define ToString_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <sstream> 00036 #include <string> 00037 #include <iomanip> 00038 #include <utils/xml/SUMOXMLDefinitions.h> 00039 #include <utils/common/SUMOVehicleClass.h> 00040 #include "StdDefs.h" 00041 00042 // =========================================================================== 00043 // class definitions 00044 // =========================================================================== 00049 template <class T> 00050 inline std::string toString(const T& t, std::streamsize accuracy = OUTPUT_ACCURACY) { 00051 std::ostringstream oss; 00052 oss.setf(std::ios::fixed , std::ios::floatfield); 00053 oss << std::setprecision(accuracy); 00054 oss << t; 00055 return oss.str(); 00056 } 00057 00058 00059 template <> 00060 inline std::string toString<SumoXMLTag>(const SumoXMLTag& tag, std::streamsize accuracy) { 00061 UNUSED_PARAMETER(accuracy); 00062 return SUMOXMLDefinitions::Tags.getString(tag); 00063 } 00064 00065 00066 template <> 00067 inline std::string toString<SumoXMLAttr>(const SumoXMLAttr& attr, std::streamsize accuracy) { 00068 UNUSED_PARAMETER(accuracy); 00069 return SUMOXMLDefinitions::Attrs.getString(attr); 00070 } 00071 00072 00073 template <> 00074 inline std::string toString<SumoXMLNodeType>(const SumoXMLNodeType& nodeType, std::streamsize accuracy) { 00075 UNUSED_PARAMETER(accuracy); 00076 return SUMOXMLDefinitions::NodeTypes.getString(nodeType); 00077 } 00078 00079 00080 template <> 00081 inline std::string toString<SumoXMLEdgeFunc>(const SumoXMLEdgeFunc& edgeFunc, std::streamsize accuracy) { 00082 UNUSED_PARAMETER(accuracy); 00083 return SUMOXMLDefinitions::EdgeFunctions.getString(edgeFunc); 00084 } 00085 00086 00087 template <> 00088 inline std::string toString<SUMOVehicleClass>(const SUMOVehicleClass& vClass, std::streamsize accuracy) { 00089 UNUSED_PARAMETER(accuracy); 00090 return SumoVehicleClassStrings.getString(vClass); 00091 } 00092 00093 00094 template <> 00095 inline std::string toString<LaneSpreadFunction>(const LaneSpreadFunction& lsf, std::streamsize accuracy) { 00096 UNUSED_PARAMETER(accuracy); 00097 return SUMOXMLDefinitions::LaneSpreadFunctions.getString(lsf); 00098 } 00099 00100 00101 template <> 00102 inline std::string toString<LinkState>(const LinkState& linkState, std::streamsize accuracy) { 00103 UNUSED_PARAMETER(accuracy); 00104 return SUMOXMLDefinitions::LinkStates.getString(linkState); 00105 } 00106 00107 template <> 00108 inline std::string toString<LinkDirection>(const LinkDirection& linkDir, std::streamsize accuracy) { 00109 UNUSED_PARAMETER(accuracy); 00110 return SUMOXMLDefinitions::LinkDirections.getString(linkDir); 00111 } 00112 00113 template <> 00114 inline std::string toString<TrafficLightType>(const TrafficLightType& type, std::streamsize accuracy) { 00115 UNUSED_PARAMETER(accuracy); 00116 return SUMOXMLDefinitions::TrafficLightTypes.getString(type); 00117 } 00118 00119 #endif 00120 00121 /****************************************************************************/ 00122