Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/VariableSpeedSign.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-2024 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/MSLane.h>
26#include "Helper.h"
27#include "VariableSpeedSign.h"
28
29
30namespace libsumo {
31// ===========================================================================
32// static member initializations
33// ===========================================================================
34SubscriptionResults VariableSpeedSign::mySubscriptionResults;
35ContextSubscriptionResults VariableSpeedSign::myContextSubscriptionResults;
36
37
38// ===========================================================================
39// static member definitions
40// ===========================================================================
41std::vector<std::string>
42VariableSpeedSign::getIDList() {
43 MSNet::getInstance(); // just to check that we actually have a network
44 std::vector<std::string> ids;
45 for (auto& item : MSLaneSpeedTrigger::getInstances()) {
46 ids.push_back(item.first);
47 }
48 return ids;
49}
50
51int
52VariableSpeedSign::getIDCount() {
53 return (int)getIDList().size();
54}
55
56std::vector<std::string>
57VariableSpeedSign::getLanes(const std::string& vssID) {
58 std::vector<std::string> result;
59 MSLaneSpeedTrigger* vss = getVariableSpeedSign(vssID);
60 for (MSLane* lane : vss->getLanes()) {
61 result.push_back(lane->getID());
62 }
63 return result;
64}
65
66std::string
67VariableSpeedSign::getParameter(const std::string& /* vssID */, const std::string& /* param */) {
68 return "";
69}
70
72
73void
74VariableSpeedSign::setParameter(const std::string& /* vssID */, const std::string& /* key */, const std::string& /* value */) {
75 //MSVariableSpeedSign* r = const_cast<MSVariableSpeedSign*>(getVariableSpeedSign(vssID));
76 //r->setParameter(key, value);
77}
78
79
81
82
84VariableSpeedSign::getVariableSpeedSign(const std::string& id) {
85 const auto& dict = MSLaneSpeedTrigger::getInstances();
86 auto it = dict.find(id);
87 if (it == dict.end()) {
88 throw TraCIException("VariableSpeedSign '" + id + "' is not known");
89 }
90 return it->second;
91}
92
93
94std::shared_ptr<VariableWrapper>
95VariableSpeedSign::makeWrapper() {
96 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
97}
98
99
100bool
101VariableSpeedSign::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
102 switch (variable) {
103 case TRACI_ID_LIST:
104 return wrapper->wrapStringList(objID, variable, getIDList());
105 case ID_COUNT:
106 return wrapper->wrapInt(objID, variable, getIDCount());
107 case VAR_LANES:
108 return wrapper->wrapStringList(objID, variable, getLanes(objID));
110 paramData->readUnsignedByte();
111 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
113 paramData->readUnsignedByte();
114 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
115 default:
116 return false;
117 }
118}
119}
120
121
122/****************************************************************************/
@ VARIABLESPEEDSIGN
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Changes the speed allowed on a set of lanes.
const std::vector< MSLane * > & getLanes()
static const std::map< std::string, MSLaneSpeedTrigger * > & getInstances()
return all MSLaneSpeedTrigger instances
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
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
TRACI_CONST int VAR_LANES
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