LCOV - code coverage report
Current view: top level - src/libsumo - VariableSpeedSign.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 65.0 % 40 26
Test Date: 2024-12-21 15:45:41 Functions: 50.0 % 18 9

            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    VariableSpeedSign.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/MSLane.h>
      24              : #include <microsim/trigger/MSLaneSpeedTrigger.h>
      25              : #include <libsumo/TraCIConstants.h>
      26              : #include "Helper.h"
      27              : #include "VariableSpeedSign.h"
      28              : 
      29              : 
      30              : namespace libsumo {
      31              : // ===========================================================================
      32              : // static member initializations
      33              : // ===========================================================================
      34              : SubscriptionResults VariableSpeedSign::mySubscriptionResults;
      35              : ContextSubscriptionResults VariableSpeedSign::myContextSubscriptionResults;
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // static member definitions
      40              : // ===========================================================================
      41              : std::vector<std::string>
      42          209 : VariableSpeedSign::getIDList() {
      43          209 :     MSNet::getInstance(); // just to check that we actually have a network
      44              :     std::vector<std::string> ids;
      45          793 :     for (auto& item : MSLaneSpeedTrigger::getInstances()) {
      46          586 :         ids.push_back(item.first);
      47              :     }
      48          207 :     return ids;
      49            0 : }
      50              : 
      51              : int
      52            5 : VariableSpeedSign::getIDCount() {
      53            5 :     return (int)getIDList().size();
      54              : }
      55              : 
      56              : std::vector<std::string>
      57            5 : VariableSpeedSign::getLanes(const std::string& vssID) {
      58              :     std::vector<std::string> result;
      59            5 :     MSLaneSpeedTrigger* vss = getVariableSpeedSign(vssID);
      60           15 :     for (MSLane* lane : vss->getLanes()) {
      61           10 :         result.push_back(lane->getID());
      62              :     }
      63            5 :     return result;
      64            0 : }
      65              : 
      66              : std::string
      67            0 : VariableSpeedSign::getParameter(const std::string& /* vssID */, const std::string& /* param */) {
      68            0 :     return "";
      69              : }
      70              : 
      71            0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(VariableSpeedSign)
      72              : 
      73              : void
      74            0 : VariableSpeedSign::setParameter(const std::string& /* vssID */, const std::string& /* key */, const std::string& /* value */) {
      75              :     //MSVariableSpeedSign* r = const_cast<MSVariableSpeedSign*>(getVariableSpeedSign(vssID));
      76              :     //r->setParameter(key, value);
      77            0 : }
      78              : 
      79              : 
      80          252 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(VariableSpeedSign, VARIABLESPEEDSIGN)
      81              : 
      82              : 
      83              : MSLaneSpeedTrigger*
      84            5 : VariableSpeedSign::getVariableSpeedSign(const std::string& id) {
      85              :     const auto& dict = MSLaneSpeedTrigger::getInstances();
      86              :     auto it = dict.find(id);
      87            5 :     if (it == dict.end()) {
      88            0 :         throw TraCIException("VariableSpeedSign '" + id + "' is not known");
      89              :     }
      90            5 :     return it->second;
      91              : }
      92              : 
      93              : 
      94              : std::shared_ptr<VariableWrapper>
      95          264 : VariableSpeedSign::makeWrapper() {
      96          264 :     return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
      97              : }
      98              : 
      99              : 
     100              : bool
     101          108 : VariableSpeedSign::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
     102          108 :     switch (variable) {
     103          102 :         case TRACI_ID_LIST:
     104          102 :             return wrapper->wrapStringList(objID, variable, getIDList());
     105            3 :         case ID_COUNT:
     106            3 :             return wrapper->wrapInt(objID, variable, getIDCount());
     107            3 :         case VAR_LANES:
     108            3 :             return wrapper->wrapStringList(objID, variable, getLanes(objID));
     109            0 :         case libsumo::VAR_PARAMETER:
     110            0 :             paramData->readUnsignedByte();
     111            0 :             return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
     112            0 :         case libsumo::VAR_PARAMETER_WITH_KEY:
     113            0 :             paramData->readUnsignedByte();
     114            0 :             return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
     115              :         default:
     116              :             return false;
     117              :     }
     118              : }
     119              : }
     120              : 
     121              : 
     122              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1