SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Variables, methods, and tools for internal time representation 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 // =========================================================================== 00023 // included modules 00024 // =========================================================================== 00025 #ifdef _MSC_VER 00026 #include <windows_config.h> 00027 #else 00028 #include <config.h> 00029 #endif 00030 00031 #include <sstream> 00032 #include "SUMOTime.h" 00033 #include "TplConvert.h" 00034 00035 00036 // =========================================================================== 00037 // type definitions 00038 // =========================================================================== 00039 #ifdef HAVE_SUBSECOND_TIMESTEPS 00040 SUMOTime DELTA_T = 1000; 00041 #endif 00042 00043 00044 // =========================================================================== 00045 // method definitions 00046 // =========================================================================== 00047 SUMOTime 00048 string2time(const std::string& r) throw(EmptyData, NumberFormatException, ProcessError) { 00049 double time; 00050 std::istringstream buf(r); 00051 buf >> time; 00052 if (buf.fail()) { 00053 throw ProcessError("Input string '" + r + "' cannot be parsed as a time"); 00054 } else { 00055 return TIME2STEPS(time); 00056 } 00057 } 00058 00059 00060 std::string 00061 time2string(SUMOTime t) { 00062 // 123456 -> "12.34" 00063 std::ostringstream oss; 00064 oss.setf(oss.fixed); 00065 oss.precision(OUTPUT_ACCURACY); 00066 oss << STEPS2TIME(t); 00067 return oss.str(); 00068 } 00069 00070 00071 /****************************************************************************/ 00072