Eclipse SUMO - Simulation of Urban MObility
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 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <microsim/MSNet.h>
23 #include <microsim/MSLane.h>
25 #include <libsumo/TraCIConstants.h>
26 #include "Helper.h"
27 #include "ParkingArea.h"
28 
29 
30 namespace libsumo {
31 // ===========================================================================
32 // static member initializations
33 // ===========================================================================
34 SubscriptionResults ParkingArea::mySubscriptionResults;
35 ContextSubscriptionResults ParkingArea::myContextSubscriptionResults;
36 
37 
38 // ===========================================================================
39 // static member definitions
40 // ===========================================================================
41 std::vector<std::string>
42 ParkingArea::getIDList() {
43  std::vector<std::string> ids;
44  for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_PARKING_AREA)) {
45  ids.push_back(item.first);
46  }
47  std::sort(ids.begin(), ids.end());
48  return ids;
49 }
50 
51 int
52 ParkingArea::getIDCount() {
53  return (int)getIDList().size();
54 }
55 
56 
57 std::string
58 ParkingArea::getLaneID(const std::string& stopID) {
59  return getParkingArea(stopID)->getLane().getID();
60 }
61 
62 double
63 ParkingArea::getStartPos(const std::string& stopID) {
64  return getParkingArea(stopID)->getBeginLanePosition();
65 }
66 
67 double
68 ParkingArea::getEndPos(const std::string& stopID) {
69  return getParkingArea(stopID)->getEndLanePosition();
70 }
71 
72 std::string
73 ParkingArea::getName(const std::string& stopID) {
74  return getParkingArea(stopID)->getMyName();
75 }
76 
77 int
78 ParkingArea::getVehicleCount(const std::string& stopID) {
79  return (int)getParkingArea(stopID)->getStoppedVehicles().size();
80 }
81 
82 std::vector<std::string>
83 ParkingArea::getVehicleIDs(const std::string& stopID) {
84  std::vector<std::string> result;
85  for (const SUMOVehicle* veh : getParkingArea(stopID)->getStoppedVehicles()) {
86  result.push_back(veh->getID());
87  }
88  return result;
89 }
90 
91 
92 std::string
93 ParkingArea::getParameter(const std::string& stopID, const std::string& param) {
94  return getParkingArea(stopID)->getParameter(param, "");
95 }
96 
97 
99 
100 
101 void
102 ParkingArea::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
103  getParkingArea(stopID)->setParameter(key, value);
104 }
105 
106 
108 
109 
111 ParkingArea::getParkingArea(const std::string& id) {
113 }
114 
115 
116 std::shared_ptr<VariableWrapper>
117 ParkingArea::makeWrapper() {
118  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
119 }
120 
121 
122 bool
123 ParkingArea::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
124  switch (variable) {
125  case TRACI_ID_LIST:
126  return wrapper->wrapStringList(objID, variable, getIDList());
127  case ID_COUNT:
128  return wrapper->wrapInt(objID, variable, getIDCount());
129  case VAR_LANE_ID:
130  return wrapper->wrapString(objID, variable, getLaneID(objID));
131  case VAR_POSITION:
132  return wrapper->wrapDouble(objID, variable, getStartPos(objID));
133  case VAR_LANEPOSITION:
134  return wrapper->wrapDouble(objID, variable, getEndPos(objID));
135  case VAR_NAME:
136  return wrapper->wrapString(objID, variable, getName(objID));
138  return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
140  return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
142  paramData->readUnsignedByte();
143  return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
145  paramData->readUnsignedByte();
146  return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
147  default:
148  return false;
149  }
150 }
151 
152 }
153 
154 
155 /****************************************************************************/
@ 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
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
A lane area vehicles can halt at.
C++ TraCI client API implementation.
Definition: ParkingArea.h:29
Representation of a vehicle.
Definition: SUMOVehicle.h:60
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_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