Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/MeanData.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/MSEdge.h>
27#include "Helper.h"
28#include "MeanData.h"
29
30
31namespace libsumo {
32// ===========================================================================
33// static member initializations
34// ===========================================================================
35SubscriptionResults MeanData::mySubscriptionResults;
36ContextSubscriptionResults MeanData::myContextSubscriptionResults;
37
38
39// ===========================================================================
40// static member definitions
41// ===========================================================================
42std::vector<std::string>
43MeanData::getIDList() {
44 std::vector<std::string> ids;
45 for (const 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
52int
53MeanData::getIDCount() {
54 return (int)getIDList().size();
55}
56
57
58std::string
59MeanData::getParameter(const std::string& /* dataID */, const std::string& /* param */) {
60 return "";
61}
62
64
65void
66MeanData::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
76MeanData::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_WARNINGF(TL("Found % meanData definitions with id '%'."), toString(it->second.size()), id);
84 }
85 return it->second.front();
86}
87
88
89std::shared_ptr<VariableWrapper>
90MeanData::makeWrapper() {
91 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
92}
93
94
95bool
96MeanData::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
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());
103 paramData->readUnsignedByte();
104 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
106 paramData->readUnsignedByte();
107 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
108 default:
109 return false;
110 }
111}
112
113}
114
115
116/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
const std::map< std::string, std::vector< MSMeanData * > > & getMeanData() const
Data collector for edges/lanes.
Definition MSMeanData.h:57
The simulated network and simulation perfomer.
Definition MSNet.h:89
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition MSNet.h:441
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:185
C++ TraCI client API implementation.
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:338
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_PARAMETER_WITH_KEY