Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Variables, methods, and tools for internal time representation
17 /****************************************************************************/
18 #ifndef SUMOTime_h
19 #define SUMOTime_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 
26 #include <limits>
27 #include <string>
28 #include "UtilExceptions.h"
29 
30 
31 // ===========================================================================
32 // type definitions
33 // ===========================================================================
34 typedef long long int SUMOTime;
35 #define SUMOTime_MAX std::numeric_limits<SUMOTime>::max()
36 #define SUMOTime_MIN std::numeric_limits<SUMOTime>::min()
37 #define SUMOTIME_MAXSTRING "9223372036854774" // SUMOTime_MAX / 1000 - 1 (because of rounding errors)
38 
39 // the step length in ms
40 extern SUMOTime DELTA_T;
41 
42 // the step length in seconds as double
43 #define TS (static_cast<double>(DELTA_T/1000.))
44 
45 // x*deltaT
46 #define SPEED2DIST(x) ((x)*TS)
47 // x/deltaT
48 #define DIST2SPEED(x) ((x)/TS)
49 // x*deltaT*deltaT
50 #define ACCEL2DIST(x) ((x)*TS*TS)
51 // x*deltaT
52 #define ACCEL2SPEED(x) ((x)*TS)
53 // x*deltaT
54 #define SPEED2ACCEL(x) ((x)/TS)
55 
56 #define STEPS2TIME(x) (static_cast<double>((x)/1000.))
57 // static cast to long long int truncates so we must pad away from 0 for correct rounding
58 #define TIME2STEPS(x) (static_cast<SUMOTime>((x) * 1000. + ((x) >= 0 ? 0.5 : -0.5)))
59 #define STEPFLOOR(x) (int(x/DELTA_T)*DELTA_T)
60 #define STEPS2MS(x) (x)
61 
62 #define SIMSTEP MSNet::getInstance()->getCurrentTimeStep()
63 #define SIMTIME STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())
64 
65 // ===========================================================================
66 // method declarations
67 // ===========================================================================
68 SUMOTime string2time(const std::string& r);
69 std::string time2string(SUMOTime t);
70 bool checkStepLengthMultiple(const SUMOTime t, const std::string& error = "");
71 
72 #endif
73 
74 
75 /****************************************************************************/
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
checkStepLengthMultiple
bool checkStepLengthMultiple(const SUMOTime t, const std::string &error="")
Definition: SUMOTime.cpp:108
string2time
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:44
UtilExceptions.h
DELTA_T
SUMOTime DELTA_T
Definition: SUMOTime.cpp:36