Eclipse SUMO - Simulation of Urban MObility
libsumo/Rerouter.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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <microsim/MSNet.h>
23 #include <microsim/MSEdge.h>
25 #include <libsumo/TraCIConstants.h>
26 #include "Helper.h"
27 #include "Rerouter.h"
28 
29 
30 namespace libsumo {
31 // ===========================================================================
32 // static member initializations
33 // ===========================================================================
34 SubscriptionResults Rerouter::mySubscriptionResults;
35 ContextSubscriptionResults Rerouter::myContextSubscriptionResults;
36 
37 
38 // ===========================================================================
39 // static member definitions
40 // ===========================================================================
41 std::vector<std::string>
42 Rerouter::getIDList() {
43  std::vector<std::string> ids;
44  for (const auto& item : MSTriggeredRerouter::getInstances()) {
45  ids.push_back(item.first);
46  }
47  return ids;
48 }
49 
50 int
51 Rerouter::getIDCount() {
52  return (int)MSTriggeredRerouter::getInstances().size();
53 }
54 
55 
56 std::string
57 Rerouter::getParameter(const std::string& /* rerouterID */, const std::string& /* param */) {
58  return "";
59 }
60 
61 
63 
64 
65 void
66 Rerouter::setParameter(const std::string& /* rerouterID */, const std::string& /* key */, const std::string& /* value */) {
67  //MSRerouter* r = const_cast<MSRerouter*>(getRerouter(rerouterID));
68  //r->setParameter(key, value);
69 }
70 
71 
73 
74 
76 Rerouter::getRerouter(const std::string& id) {
77  MSTriggeredRerouter* s = nullptr;
78  if (s == nullptr) {
79  throw TraCIException("Rerouter '" + id + "' is not known");
80  }
81  return s;
82 }
83 
84 
85 std::shared_ptr<VariableWrapper>
86 Rerouter::makeWrapper() {
87  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
88 }
89 
90 
91 bool
92 Rerouter::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
93  switch (variable) {
94  case TRACI_ID_LIST:
95  return wrapper->wrapStringList(objID, variable, getIDList());
96  case ID_COUNT:
97  return wrapper->wrapInt(objID, variable, getIDCount());
98  default:
99  return false;
100  }
101 }
102 
103 }
104 
105 
106 /****************************************************************************/
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:57
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:104
Reroutes vehicles passing an edge.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
C++ TraCI client API implementation.
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:250
TRACI_CONST int ID_COUNT
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:251