SUMOTime.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef _MSC_VER
00023 #include <windows_config.h>
00024 #else
00025 #include <config.h>
00026 #endif
00027
00028 #include <sstream>
00029 #include "SUMOTime.h"
00030 #include "TplConvert.h"
00031
00032
00033
00034
00035
00036 #ifdef HAVE_SUBSECOND_TIMESTEPS
00037 SUMOTime DELTA_T = 1000;
00038 #endif
00039
00040
00041
00042
00043
00044 SUMOTime
00045 string2time(const std::string &r) throw(EmptyData, NumberFormatException) {
00046 size_t idx = r.find('.');
00047 if (idx==std::string::npos) {
00048
00049 return TplConvert<char>::_2int(r.c_str())*1000;
00050 }
00051 int secs = idx>0 ? TplConvert<char>::_2int(r.substr(0, idx).c_str()) : 0;
00052 int subsecs = TplConvert<char>::_2int((r.substr(idx+1)+"0000").substr(0,3).c_str()) * 10;
00053 do {
00054 subsecs = subsecs / 10;
00055 } while (idx<r.length()&&r[idx]=='0');
00056 return secs*1000 + subsecs;
00057 }
00058
00059
00060 std::string
00061 time2string(SUMOTime t) throw() {
00062 std::ostringstream oss;
00063 oss << ((SUMOReal) t / 1000.);
00064 std::string ret = oss.str();
00065 size_t idx = ret.find('.');
00066 if (idx==std::string::npos) {
00067 return ret + ".00";
00068 }
00069 return (ret+"00").substr(0, idx+3);
00070 }
00071
00072
00073
00074