SUMO - Simulation of Urban MObility

ToString.h

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