Eclipse SUMO - Simulation of Urban MObility
libsumo/MultiEntryExit.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2020 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 /****************************************************************************/
21 // C++ TraCI client API implementation
22 /****************************************************************************/
23 #include <config.h>
24 
27 #include <microsim/MSNet.h>
28 #include <libsumo/TraCIConstants.h>
29 #include "MultiEntryExit.h"
30 
31 
32 namespace libsumo {
33 // ===========================================================================
34 // static member initializations
35 // ===========================================================================
36 SubscriptionResults MultiEntryExit::mySubscriptionResults;
37 ContextSubscriptionResults MultiEntryExit::myContextSubscriptionResults;
38 
39 
40 // ===========================================================================
41 // static member definitions
42 // ===========================================================================
43 std::vector<std::string>
44 MultiEntryExit::getIDList() {
45  std::vector<std::string> ids;
47  return ids;
48 }
49 
50 
51 int
52 MultiEntryExit::getIDCount() {
53  std::vector<std::string> ids;
55 }
56 
57 
58 int
59 MultiEntryExit::getLastStepVehicleNumber(const std::string& detID) {
60  return getDetector(detID)->getVehiclesWithin();
61 }
62 
63 
64 double
65 MultiEntryExit::getLastStepMeanSpeed(const std::string& detID) {
66  return getDetector(detID)->getCurrentMeanSpeed();
67 }
68 
69 
70 std::vector<std::string>
71 MultiEntryExit::getLastStepVehicleIDs(const std::string& detID) {
72  return getDetector(detID)->getCurrentVehicleIDs();
73 }
74 
75 
76 int
77 MultiEntryExit::getLastStepHaltingNumber(const std::string& detID) {
78  return getDetector(detID)->getCurrentHaltingNumber();
79 }
80 
81 
82 std::string
83 MultiEntryExit::getParameter(const std::string& detID, const std::string& param) {
84  return getDetector(detID)->getParameter(param, "");
85 }
86 
87 
89 
90 
91 void
92 MultiEntryExit::setParameter(const std::string& detID, const std::string& name, const std::string& value) {
93  getDetector(detID)->setParameter(name, value);
94 }
95 
96 
98 
99 
101 MultiEntryExit::getDetector(const std::string& id) {
103  if (e3 == nullptr) {
104  throw TraCIException("Multi entry exit detector '" + id + "' is not known");
105  }
106  return e3;
107 }
108 
109 
110 std::shared_ptr<VariableWrapper>
111 MultiEntryExit::makeWrapper() {
112  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
113 }
114 
115 
116 bool
117 MultiEntryExit::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
118  switch (variable) {
119  case TRACI_ID_LIST:
120  return wrapper->wrapStringList(objID, variable, getIDList());
121  case ID_COUNT:
122  return wrapper->wrapInt(objID, variable, getIDCount());
124  return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
126  return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
128  return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
130  return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
131  default:
132  return false;
133  }
134 }
135 
136 
137 }
138 
139 
140 /****************************************************************************/
@ SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:57
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:104
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
A detector of vehicles passing an area between entry/exit points.
Definition: MSE3Collector.h:58
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:434
C++ TraCI client API implementation.
T get(const std::string &id) const
Retrieves an item.
void insertIDs(std::vector< std::string > &into) const
int size() const
Returns the number of stored items within the container.
TRACI_CONST int LAST_STEP_VEHICLE_ID_LIST
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int LAST_STEP_MEAN_SPEED
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:250
TRACI_CONST int ID_COUNT
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:251