Line data Source code
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 : /****************************************************************************/
12 : /// @file TraCI_Route.cpp
13 : /// @author Daniel Krajzewicz
14 : /// @author Mario Krumnow
15 : /// @author Jakob Erdmann
16 : /// @author Michael Behrisch
17 : /// @author Robert Hilbrich
18 : /// @date 30.05.2012
19 : /// @version $Id$
20 : ///
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>
44 43 : TraCI_Route::getIDList() {
45 43 : std::vector<std::string> ids;
46 43 : MSRoute::insertIDs(ids);
47 43 : return ids;
48 : }
49 :
50 : std::vector<std::string>
51 25 : TraCI_Route::getEdges(const std::string& routeID) {
52 25 : const MSRoute* r = getRoute(routeID);
53 23 : std::vector<std::string> ids;
54 145 : for (ConstMSEdgeVector::const_iterator i = r->getEdges().begin(); i != r->getEdges().end(); ++i) {
55 122 : ids.push_back((*i)->getID());
56 : }
57 23 : return ids;
58 : }
59 :
60 :
61 : int
62 11 : TraCI_Route::getIDCount() {
63 11 : return (int)getIDList().size();
64 : }
65 :
66 :
67 : std::string
68 8 : TraCI_Route::getParameter(const std::string& routeID, const std::string& param) {
69 8 : const MSRoute* r = getRoute(routeID);
70 8 : return r->getParameter(param, "");
71 : }
72 :
73 : void
74 4 : TraCI_Route::setParameter(const std::string& routeID, const std::string& key, const std::string& value) {
75 4 : MSRoute* r = const_cast<MSRoute*>(getRoute(routeID));
76 4 : r->setParameter(key, value);
77 4 : }
78 :
79 :
80 : void
81 26 : TraCI_Route::add(const std::string& routeID, const std::vector<std::string>& edgeIDs) {
82 26 : ConstMSEdgeVector edges;
83 64 : for (std::vector<std::string>::const_iterator ei = edgeIDs.begin(); ei != edgeIDs.end(); ++ei) {
84 38 : MSEdge* edge = MSEdge::dictionary(*ei);
85 38 : if (edge == 0) {
86 0 : throw TraCIException("Unknown edge '" + *ei + "' in route.");
87 : }
88 38 : edges.push_back(edge);
89 : }
90 52 : const std::vector<SUMOVehicleParameter::Stop> stops;
91 26 : if (!MSRoute::dictionary(routeID, new MSRoute(routeID, edges, true, 0, stops))) {
92 0 : throw TraCIException("Could not add route.");
93 26 : }
94 26 : }
95 :
96 :
97 : const MSRoute*
98 37 : TraCI_Route::getRoute(const std::string& id) {
99 37 : const MSRoute* r = MSRoute::dictionary(id);
100 37 : if (r == 0) {
101 2 : throw TraCIException("Route '" + id + "' is not known");
102 : }
103 35 : return r;
104 43554 : }
105 :
106 :
107 : /****************************************************************************/
|