Eclipse SUMO - Simulation of Urban MObility
libsumo/MeanData.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-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 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <microsim/MSNet.h>
23 #include <microsim/MSEdge.h>
26 #include <libsumo/TraCIConstants.h>
27 #include "Helper.h"
28 #include "MeanData.h"
29 
30 
31 namespace libsumo {
32 // ===========================================================================
33 // static member initializations
34 // ===========================================================================
35 SubscriptionResults MeanData::mySubscriptionResults;
36 ContextSubscriptionResults MeanData::myContextSubscriptionResults;
37 
38 
39 // ===========================================================================
40 // static member definitions
41 // ===========================================================================
42 std::vector<std::string>
43 MeanData::getIDList() {
44  std::vector<std::string> ids;
45  for (auto item : MSNet::getInstance()->getDetectorControl().getMeanData()) {
46  ids.push_back(item.first);
47  }
48  std::sort(ids.begin(), ids.end());
49  return ids;
50 }
51 
52 int
53 MeanData::getIDCount() {
54  return (int)getIDList().size();
55 }
56 
57 
58 std::string
59 MeanData::getParameter(const std::string& /* dataID */, const std::string& /* param */) {
60  return "";
61 }
62 
64 
65 void
66 MeanData::setParameter(const std::string& /* dataID */, const std::string& /* key */, const std::string& /* value */) {
67  //MSMeanData* r = const_cast<MSMeanData*>(getMeanData(dataID));
68  //r->setParameter(key, value);
69 }
70 
71 
73 
74 
76 MeanData::getMeanData(const std::string& id) {
78  auto it = mdMap.find(id);
79  if (it == mdMap.end() || it->second.size() == 0) {
80  throw TraCIException("MeanData '" + id + "' is not known");
81  }
82  if (it->second.size() > 1) {
83  WRITE_WARNING("Found " + toString(it->second.size()) + " meanData definitions with id '" + id + "'.");
84  }
85  return it->second.front();
86 }
87 
88 
89 std::shared_ptr<VariableWrapper>
90 MeanData::makeWrapper() {
91  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
92 }
93 
94 
95 bool
96 MeanData::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
97  switch (variable) {
98  case TRACI_ID_LIST:
99  return wrapper->wrapStringList(objID, variable, getIDList());
100  case ID_COUNT:
101  return wrapper->wrapInt(objID, variable, getIDCount());
102  default:
103  return false;
104  }
105 }
106 
107 }
108 
109 
110 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:57
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition: TraCIDefs.h:104
const std::map< std::string, std::vector< MSMeanData * > > & getMeanData() const
Data collector for edges/lanes.
Definition: MSMeanData.h:57
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.
TRACI_CONST int TRACI_ID_LIST
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