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