Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/Rerouter.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2017-2023 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>
26#include "Helper.h"
27#include "Rerouter.h"
28
29
30namespace libsumo {
31// ===========================================================================
32// static member initializations
33// ===========================================================================
34SubscriptionResults Rerouter::mySubscriptionResults;
35ContextSubscriptionResults Rerouter::myContextSubscriptionResults;
36
37
38// ===========================================================================
39// static member definitions
40// ===========================================================================
41std::vector<std::string>
42Rerouter::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
50int
51Rerouter::getIDCount() {
52 return (int)MSTriggeredRerouter::getInstances().size();
53}
54
55
56std::string
57Rerouter::getParameter(const std::string& /* rerouterID */, const std::string& /* param */) {
58 return "";
59}
60
61
63
64
65void
66Rerouter::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
76Rerouter::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
85std::shared_ptr<VariableWrapper>
86Rerouter::makeWrapper() {
87 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
88}
89
90
91bool
92Rerouter::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
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());
99 paramData->readUnsignedByte();
100 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
102 paramData->readUnsignedByte();
103 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
104 default:
105 return false;
106 }
107}
108
109}
110
111
112/****************************************************************************/
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
Reroutes vehicles passing an edge.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
C++ TraCI client API implementation.
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:338
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:337
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_PARAMETER_WITH_KEY