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