Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libsumo/VariableSpeedSign.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2025 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
/****************************************************************************/
14
/// @file VariableSpeedSign.cpp
15
/// @author Jakob Erdmann
16
/// @date 16.03.2020
17
///
18
// C++ TraCI client API implementation
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <microsim/MSNet.h>
23
#include <microsim/MSLane.h>
24
#include <microsim/trigger/MSLaneSpeedTrigger.h>
25
#include <libsumo/TraCIConstants.h>
26
#include "Helper.h"
27
#include "VariableSpeedSign.h"
28
29
30
namespace libsumo {
31
// ===========================================================================
32
// static member initializations
33
// ===========================================================================
34
SubscriptionResults VariableSpeedSign::mySubscriptionResults;
35
ContextSubscriptionResults VariableSpeedSign::myContextSubscriptionResults;
36
37
38
// ===========================================================================
39
// static member definitions
40
// ===========================================================================
41
std::vector<std::string>
42
VariableSpeedSign::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
51
int
52
VariableSpeedSign::getIDCount() {
53
return (int)getIDList().size();
54
}
55
56
std::vector<std::string>
57
VariableSpeedSign::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
66
std::string
67
VariableSpeedSign::getParameter(const std::string& /* vssID */, const std::string& /* param */) {
68
return "";
69
}
70
71
LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(VariableSpeedSign)
72
73
void
74
VariableSpeedSign::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
80
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(VariableSpeedSign, VARIABLESPEEDSIGN)
81
82
83
MSLaneSpeedTrigger*
84
VariableSpeedSign::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
94
std::shared_ptr<VariableWrapper>
95
VariableSpeedSign::makeWrapper() {
96
return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
97
}
98
99
100
bool
101
VariableSpeedSign::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));
109
case libsumo::VAR_PARAMETER:
110
paramData->readUnsignedByte();
111
return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
112
case libsumo::VAR_PARAMETER_WITH_KEY:
113
paramData->readUnsignedByte();
114
return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
115
default:
116
return false;
117
}
118
}
119
}
120
121
122
/****************************************************************************/
123
124