SUMO - Simulation of Urban MObility
TraCI_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 "TraCI_Route.h"
38 
39 
40 // ===========================================================================
41 // member definitions
42 // ===========================================================================
43 std::vector<std::string>
45  std::vector<std::string> ids;
46  MSRoute::insertIDs(ids);
47  return ids;
48 }
49 
50 std::vector<std::string>
51 TraCI_Route::getEdges(const std::string& routeID) {
52  const MSRoute* r = getRoute(routeID);
53  std::vector<std::string> ids;
54  for (ConstMSEdgeVector::const_iterator i = r->getEdges().begin(); i != r->getEdges().end(); ++i) {
55  ids.push_back((*i)->getID());
56  }
57  return ids;
58 }
59 
60 
61 int
63  return (int)getIDList().size();
64 }
65 
66 
67 std::string
68 TraCI_Route::getParameter(const std::string& routeID, const std::string& param) {
69  const MSRoute* r = getRoute(routeID);
70  return r->getParameter(param, "");
71 }
72 
73 void
74 TraCI_Route::setParameter(const std::string& routeID, const std::string& key, const std::string& value) {
75  MSRoute* r = const_cast<MSRoute*>(getRoute(routeID));
76  r->setParameter(key, value);
77 }
78 
79 
80 void
81 TraCI_Route::add(const std::string& routeID, const std::vector<std::string>& edgeIDs) {
82  ConstMSEdgeVector edges;
83  for (std::vector<std::string>::const_iterator ei = edgeIDs.begin(); ei != edgeIDs.end(); ++ei) {
84  MSEdge* edge = MSEdge::dictionary(*ei);
85  if (edge == 0) {
86  throw TraCIException("Unknown edge '" + *ei + "' in route.");
87  }
88  edges.push_back(edge);
89  }
90  const std::vector<SUMOVehicleParameter::Stop> stops;
91  if (!MSRoute::dictionary(routeID, new MSRoute(routeID, edges, true, 0, stops))) {
92  throw TraCIException("Could not add route.");
93  }
94 }
95 
96 
97 const MSRoute*
98 TraCI_Route::getRoute(const std::string& id) {
99  const MSRoute* r = MSRoute::dictionary(id);
100  if (r == 0) {
101  throw TraCIException("Route '" + id + "' is not known");
102  }
103  return r;
104 }
105 
106 
107 /****************************************************************************/
static void setParameter(const std::string &routeID, const std::string &key, const std::string &value)
Definition: TraCI_Route.cpp:74
static const MSRoute * getRoute(const std::string &id)
Definition: TraCI_Route.cpp:98
static std::vector< std::string > getIDList()
Definition: TraCI_Route.cpp:44
static int getIDCount()
Definition: TraCI_Route.cpp:62
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
static void add(const std::string &routeID, const std::vector< std::string > &edgeIDs)
Definition: TraCI_Route.cpp:81
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:127
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
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: TraCI_Route.cpp:51
static std::string getParameter(const std::string &routeID, const std::string &param)
Definition: TraCI_Route.cpp:68
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:117