SUMO - Simulation of Urban MObility
SUMOTime.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Variables, methods, and tools for internal time representation
20 /****************************************************************************/
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <sstream>
31 #include "SUMOTime.h"
32 #include "TplConvert.h"
33 #include "StdDefs.h"
34 
35 
36 // ===========================================================================
37 // type definitions
38 // ===========================================================================
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
46 string2time(const std::string& r) {
47  double time;
48  std::istringstream buf(r);
49  buf >> time;
50  if (buf.fail() || time > STEPS2TIME(SUMOTime_MAX)) {
51  throw ProcessError("Input string '" + r + "' is not a valid number or exceeds the time value range.");
52  } else {
53  return TIME2STEPS(time);
54  }
55 }
56 
57 
58 std::string
60  // 123456 -> "12.34"
61  std::ostringstream oss;
62  oss.setf(oss.fixed);
63  oss.precision(gPrecision);
64  oss << STEPS2TIME(t);
65  return oss.str();
66 }
67 
68 
69 /****************************************************************************/
70 
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:29
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
#define SUMOTime_MAX
Definition: TraCIDefs.h:52
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
long long int SUMOTime
Definition: TraCIDefs.h:51