SUMO - Simulation of Urban MObility
Route.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-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 /****************************************************************************/
21 // C++ TraCI client API implementation
22 /****************************************************************************/
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 <microsim/MSNet.h>
35 #include <microsim/MSEdge.h>
36 #include <microsim/MSRoute.h>
37 #include "Route.h"
38 
39 
40 // ===========================================================================
41 // member definitions
42 // ===========================================================================
43 namespace libsumo {
44 std::vector<std::string>
46  std::vector<std::string> ids;
47  MSRoute::insertIDs(ids);
48  return ids;
49 }
50 
51 std::vector<std::string>
52 Route::getEdges(const std::string& routeID) {
53  const MSRoute* r = getRoute(routeID);
54  std::vector<std::string> ids;
55  for (ConstMSEdgeVector::const_iterator i = r->getEdges().begin(); i != r->getEdges().end(); ++i) {
56  ids.push_back((*i)->getID());
57  }
58  return ids;
59 }
60 
61 
62 int
64  return (int)getIDList().size();
65 }
66 
67 
68 std::string
69 Route::getParameter(const std::string& routeID, const std::string& param) {
70  const MSRoute* r = getRoute(routeID);
71  return r->getParameter(param, "");
72 }
73 
74 void
75 Route::setParameter(const std::string& routeID, const std::string& key, const std::string& value) {
76  MSRoute* r = const_cast<MSRoute*>(getRoute(routeID));
77  r->setParameter(key, value);
78 }
79 
80 
81 void
82 Route::add(const std::string& routeID, const std::vector<std::string>& edgeIDs) {
83  ConstMSEdgeVector edges;
84  for (std::vector<std::string>::const_iterator ei = edgeIDs.begin(); ei != edgeIDs.end(); ++ei) {
85  MSEdge* edge = MSEdge::dictionary(*ei);
86  if (edge == 0) {
87  throw TraCIException("Unknown edge '" + *ei + "' in route.");
88  }
89  edges.push_back(edge);
90  }
91  const std::vector<SUMOVehicleParameter::Stop> stops;
92  if (!MSRoute::dictionary(routeID, new MSRoute(routeID, edges, true, 0, stops))) {
93  throw TraCIException("Could not add route.");
94  }
95 }
96 
97 
98 const MSRoute*
99 Route::getRoute(const std::string& id) {
100  const MSRoute* r = MSRoute::dictionary(id);
101  if (r == 0) {
102  throw TraCIException("Route '" + id + "' is not known");
103  }
104  return r;
105 }
106 }
107 
108 
109 /****************************************************************************/
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:127
static const MSRoute * getRoute(const std::string &id)
Definition: Route.cpp:99
static void add(const std::string &routeID, const std::vector< std::string > &edgeIDs)
Definition: Route.cpp:82
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:744
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:206
A road/street connecting two junctions.
Definition: MSEdge.h:80
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
static std::string getParameter(const std::string &routeID, const std::string &param)
Definition: Route.cpp:69
Definition: Edge.cpp:31
static void setParameter(const std::string &routeID, const std::string &key, const std::string &value)
Definition: Route.cpp:75
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
static std::vector< std::string > getEdges(const std::string &routeID)
Definition: Route.cpp:52
static int getIDCount()
Definition: Route.cpp:63
static std::vector< std::string > getIDList()
Definition: Route.cpp:45
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:117