Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/BusStop.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>
27#include "Helper.h"
28#include "BusStop.h"
29
30
31namespace libsumo {
32// ===========================================================================
33// static member initializations
34// ===========================================================================
35SubscriptionResults BusStop::mySubscriptionResults;
36ContextSubscriptionResults BusStop::myContextSubscriptionResults;
37
38
39// ===========================================================================
40// static member definitions
41// ===========================================================================
42std::vector<std::string>
43BusStop::getIDList() {
44 std::vector<std::string> ids;
46 ids.push_back(item.first);
47 }
48 std::sort(ids.begin(), ids.end());
49 return ids;
50}
51
52int
53BusStop::getIDCount() {
54 return (int)getIDList().size();
55}
56
57
58std::string
59BusStop::getLaneID(const std::string& stopID) {
60 return getBusStop(stopID)->getLane().getID();
61}
62
63double
64BusStop::getStartPos(const std::string& stopID) {
65 return getBusStop(stopID)->getBeginLanePosition();
66}
67
68double
69BusStop::getEndPos(const std::string& stopID) {
70 return getBusStop(stopID)->getEndLanePosition();
71}
72
73std::string
74BusStop::getName(const std::string& stopID) {
75 return getBusStop(stopID)->getMyName();
76}
77
78int
79BusStop::getVehicleCount(const std::string& stopID) {
80 return (int)getBusStop(stopID)->getStoppedVehicles().size();
81}
82
83std::vector<std::string>
84BusStop::getVehicleIDs(const std::string& stopID) {
85 std::vector<std::string> result;
86 for (const SUMOVehicle* veh : getBusStop(stopID)->getStoppedVehicles()) {
87 result.push_back(veh->getID());
88 }
89 return result;
90}
91
92int
93BusStop::getPersonCount(const std::string& stopID) {
94 return (int)getBusStop(stopID)->getNumWaitingPersons();
95}
96
97std::vector<std::string>
98BusStop::getPersonIDs(const std::string& stopID) {
99 std::vector<std::string> result;
100 getBusStop(stopID)->getWaitingPersonIDs(result);
101 return result;
102}
103
104
105std::string
106BusStop::getParameter(const std::string& stopID, const std::string& param) {
107 return getBusStop(stopID)->getParameter(param, "");
108}
109
111
112void
113BusStop::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
114 getBusStop(stopID)->setParameter(key, value);
115}
116
117
119
120
122BusStop::getBusStop(const std::string& id) {
124}
125
126
127std::shared_ptr<VariableWrapper>
128BusStop::makeWrapper() {
129 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
130}
131
132
133bool
134BusStop::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
135 switch (variable) {
136 case TRACI_ID_LIST:
137 return wrapper->wrapStringList(objID, variable, getIDList());
138 case ID_COUNT:
139 return wrapper->wrapInt(objID, variable, getIDCount());
140 case VAR_LANE_ID:
141 return wrapper->wrapString(objID, variable, getLaneID(objID));
142 case VAR_POSITION:
143 return wrapper->wrapDouble(objID, variable, getStartPos(objID));
144 case VAR_LANEPOSITION:
145 return wrapper->wrapDouble(objID, variable, getEndPos(objID));
146 case VAR_NAME:
147 return wrapper->wrapString(objID, variable, getName(objID));
149 return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
151 return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
153 return wrapper->wrapInt(objID, variable, getPersonCount(objID));
155 return wrapper->wrapStringList(objID, variable, getPersonIDs(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
171/****************************************************************************/
@ SUMO_TAG_BUS_STOP
A bus stop.
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
C++ TraCI client API implementation.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:185
const NamedObjectCont< MSStoppingPlace * > & getStoppingPlaces(SumoXMLTag category) const
Definition MSNet.cpp:1414
A lane area vehicles can halt at.
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_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 VAR_BUS_STOP_WAITING_IDS
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
TRACI_CONST int VAR_BUS_STOP_WAITING