Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/ParkingArea.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/****************************************************************************/
19// C++ TraCI client API implementation
20/****************************************************************************/
21#include <config.h>
22
23#include <microsim/MSNet.h>
24#include <microsim/MSLane.h>
28#include "Helper.h"
29#include "ParkingArea.h"
30
31
32namespace libsumo {
33// ===========================================================================
34// static member initializations
35// ===========================================================================
36SubscriptionResults ParkingArea::mySubscriptionResults;
37ContextSubscriptionResults ParkingArea::myContextSubscriptionResults;
38
39
40// ===========================================================================
41// static member definitions
42// ===========================================================================
43std::vector<std::string>
44ParkingArea::getIDList() {
45 std::vector<std::string> ids;
46 for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_PARKING_AREA)) {
47 ids.push_back(item.first);
48 }
49 std::sort(ids.begin(), ids.end());
50 return ids;
51}
52
53int
54ParkingArea::getIDCount() {
55 return (int)getIDList().size();
56}
57
58
59std::string
60ParkingArea::getLaneID(const std::string& stopID) {
61 return getParkingArea(stopID)->getLane().getID();
62}
63
64double
65ParkingArea::getStartPos(const std::string& stopID) {
66 return getParkingArea(stopID)->getBeginLanePosition();
67}
68
69double
70ParkingArea::getEndPos(const std::string& stopID) {
71 return getParkingArea(stopID)->getEndLanePosition();
72}
73
74std::string
75ParkingArea::getName(const std::string& stopID) {
76 return getParkingArea(stopID)->getMyName();
77}
78
79int
80ParkingArea::getVehicleCount(const std::string& stopID) {
81 return (int)getParkingArea(stopID)->getStoppedVehicles().size();
82}
83
84std::vector<std::string>
85ParkingArea::getVehicleIDs(const std::string& stopID) {
86 std::vector<std::string> result;
87 for (const SUMOVehicle* veh : getParkingArea(stopID)->getStoppedVehicles()) {
88 result.push_back(veh->getID());
89 }
90 return result;
91}
92
93std::vector<std::string>
94ParkingArea::getAcceptedBadges(const std::string& stopID) {
95 return dynamic_cast<MSParkingArea*>(getParkingArea(stopID))->getAcceptedBadges();
96}
97
98
99void
100ParkingArea::setAcceptedBadges(const std::string& stopID, const std::vector<std::string>& badges) {
101 dynamic_cast<MSParkingArea*>(getParkingArea(stopID))->setAcceptedBadges(badges);
102}
103
104
105std::string
106ParkingArea::getParameter(const std::string& stopID, const std::string& param) {
107 return getParkingArea(stopID)->getParameter(param, "");
108}
109
110
112
113
114void
115ParkingArea::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
116 getParkingArea(stopID)->setParameter(key, value);
117}
118
119
121
122
124ParkingArea::getParkingArea(const std::string& id) {
126}
127
128
129std::shared_ptr<VariableWrapper>
130ParkingArea::makeWrapper() {
131 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
132}
133
134
135bool
136ParkingArea::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
137 switch (variable) {
138 case TRACI_ID_LIST:
139 return wrapper->wrapStringList(objID, variable, getIDList());
140 case ID_COUNT:
141 return wrapper->wrapInt(objID, variable, getIDCount());
142 case VAR_LANE_ID:
143 return wrapper->wrapString(objID, variable, getLaneID(objID));
144 case VAR_POSITION:
145 return wrapper->wrapDouble(objID, variable, getStartPos(objID));
146 case VAR_LANEPOSITION:
147 return wrapper->wrapDouble(objID, variable, getEndPos(objID));
148 case VAR_NAME:
149 return wrapper->wrapString(objID, variable, getName(objID));
150 case VAR_ACCESS_BADGE:
151 return wrapper->wrapStringList(objID, variable, getAcceptedBadges(objID));
153 return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
155 return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
157 paramData->readUnsignedByte();
158 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
160 paramData->readUnsignedByte();
161 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
162 default:
163 return false;
164 }
165}
166
167}
168
169
170/****************************************************************************/
@ SUMO_TAG_PARKING_AREA
A parking area.
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
The simulated network and simulation perfomer.
Definition MSNet.h:89
A lane area vehicles can halt at.
A lane area vehicles can halt at.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
C++ TraCI client API implementation.
Representation of a vehicle.
Definition SUMOVehicle.h:62
static MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag type)
Definition Helper.cpp:527
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int VAR_ACCESS_BADGE
TRACI_CONST int VAR_NAME
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:338
TRACI_CONST int VAR_POSITION
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_LANEPOSITION
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS