SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SUMOTime.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Variables, methods, and tools for internal time representation
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <sstream>
32 #include "SUMOTime.h"
33 #include "TplConvert.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(OUTPUT_ACCURACY);
64  oss << STEPS2TIME(t);
65  return oss.str();
66 }
67 
68 
69 /****************************************************************************/
70 
long long int SUMOTime
Definition: SUMOTime.h:43
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
#define OUTPUT_ACCURACY
Definition: config.h:164
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
#define SUMOTime_MAX
Definition: SUMOTime.h:44