LCOV - code coverage report
Current view: top level - src/libsumo - MeanData.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 45.7 % 35 16
Test Date: 2024-12-21 15:45:41 Functions: 23.5 % 17 4

            Line data    Source code
       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              : /****************************************************************************/
      14              : /// @file    MeanData.cpp
      15              : /// @author  Jakob Erdmann
      16              : /// @date    16.03.2020
      17              : ///
      18              : // C++ TraCI client API implementation
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include <microsim/MSNet.h>
      23              : #include <microsim/MSEdge.h>
      24              : #include <microsim/output/MSDetectorControl.h>
      25              : #include <microsim/output/MSMeanData.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          209 : MeanData::getIDList() {
      44              :     std::vector<std::string> ids;
      45          219 :     for (const auto& item : MSNet::getInstance()->getDetectorControl().getMeanData()) {
      46           10 :         ids.push_back(item.first);
      47              :     }
      48          207 :     std::sort(ids.begin(), ids.end());
      49          207 :     return ids;
      50            2 : }
      51              : 
      52              : int
      53            5 : MeanData::getIDCount() {
      54            5 :     return (int)getIDList().size();
      55              : }
      56              : 
      57              : 
      58              : std::string
      59            0 : MeanData::getParameter(const std::string& /* dataID */, const std::string& /* param */) {
      60            0 :     return "";
      61              : }
      62              : 
      63            0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(MeanData)
      64              : 
      65              : void
      66            0 : 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            0 : }
      70              : 
      71              : 
      72            0 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(MeanData, MEANDATA)
      73              : 
      74              : 
      75              : MSMeanData*
      76            0 : MeanData::getMeanData(const std::string& id) {
      77            0 :     auto mdMap = MSNet::getInstance()->getDetectorControl().getMeanData();
      78              :     auto it = mdMap.find(id);
      79            0 :     if (it == mdMap.end() || it->second.size() == 0) {
      80            0 :         throw TraCIException("MeanData '" + id + "' is not known");
      81              :     }
      82            0 :     if (it->second.size() > 1) {
      83            0 :         WRITE_WARNINGF(TL("Found % meanData definitions with id '%'."), toString(it->second.size()), id);
      84              :     }
      85            0 :     return it->second.front();
      86              : }
      87              : 
      88              : 
      89              : std::shared_ptr<VariableWrapper>
      90          264 : MeanData::makeWrapper() {
      91          264 :     return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
      92              : }
      93              : 
      94              : 
      95              : bool
      96          105 : MeanData::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
      97          105 :     switch (variable) {
      98          102 :         case TRACI_ID_LIST:
      99          102 :             return wrapper->wrapStringList(objID, variable, getIDList());
     100            3 :         case ID_COUNT:
     101            3 :             return wrapper->wrapInt(objID, variable, getIDCount());
     102            0 :         case libsumo::VAR_PARAMETER:
     103            0 :             paramData->readUnsignedByte();
     104            0 :             return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
     105            0 :         case libsumo::VAR_PARAMETER_WITH_KEY:
     106            0 :             paramData->readUnsignedByte();
     107            0 :             return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
     108              :         default:
     109              :             return false;
     110              :     }
     111              : }
     112              : 
     113              : }
     114              : 
     115              : 
     116              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1