SUMO - Simulation of Urban MObility
SUMOTime.h
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 #ifndef SUMOTime_h
22 #define SUMOTime_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <limits>
35 #include <string>
36 #include "UtilExceptions.h"
37 
38 
39 // ===========================================================================
40 // type definitions
41 // ===========================================================================
42 typedef long long int SUMOTime;
43 #define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
44 #define SUMOTime_MIN std::numeric_limits<SUMOTime>::min()
45 #define SUMOTIME_MAXSTRING "9223372036854774" // SUMOTime_MAX / 1000 - 1 (because of rounding errors)
46 
47 // the step length in ms
48 extern SUMOTime DELTA_T;
49 
50 // the step length in seconds as double
51 #define TS (static_cast<double>(DELTA_T/1000.))
52 
53 // x*deltaT
54 #define SPEED2DIST(x) ((x)*TS)
55 // x/deltaT
56 #define DIST2SPEED(x) ((x)/TS)
57 // x*deltaT*deltaT
58 #define ACCEL2DIST(x) ((x)*TS*TS)
59 // x*deltaT
60 #define ACCEL2SPEED(x) ((x)*TS)
61 // x*deltaT
62 #define SPEED2ACCEL(x) ((x)/TS)
63 
64 #define STEPS2TIME(x) (static_cast<double>((x)/1000.))
65 // static cast to long long int truncates so we must pad away from 0 for correct rounding
66 #define TIME2STEPS(x) (static_cast<SUMOTime>((x)*1000 + (x >= 0 ? 0.5 : -0.5)))
67 #define STEPFLOOR(x) (int(x/DELTA_T)*DELTA_T)
68 #define STEPS2MS(x) (x)
69 
70 #define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()
71 #define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())
72 
73 // ===========================================================================
74 // method declarations
75 // ===========================================================================
76 SUMOTime string2time(const std::string& r);
77 std::string time2string(SUMOTime t);
78 
79 
80 #endif
81 
82 /****************************************************************************/
83 
long long int SUMOTime
Definition: SUMOTime.h:42
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
long long int SUMOTime
Definition: TraCIDefs.h:51